this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

readme: add gif

+43 -13
+3 -5
README.md
··· 4 4 It begins with them, but ends with me. Their son, Vaxis 5 5 ``` 6 6 7 - libvaxis is a zig port of the go TUI library 8 - [Vaxis](https://git.sr.ht/~rockorager/vaxis). The goal is to have the same 9 - feature set, only written in zig. 7 + ![vaxis demo gif](vaxis.gif) 10 8 11 - Like it's sibling library, libvaxis _does not use terminfo_. Support for vt 12 - features is detected through terminal queries. 9 + Libvaxis _does not use terminfo_. Support for vt features is detected through 10 + terminal queries. 13 11 14 12 Contributions are welcome. 15 13
+40 -8
examples/vaxis.zig
··· 7 7 winsize: vaxis.Winsize, 8 8 }; 9 9 10 + pub const panic = vaxis.panic_handler; 11 + 10 12 pub fn main() !void { 11 13 var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 12 14 defer { ··· 31 33 try vx.enterAltScreen(tty.anyWriter()); 32 34 try vx.queryTerminal(tty.anyWriter(), 1 * std.time.ns_per_s); 33 35 34 - const lower_limit = 30; 35 - var color_idx: u8 = lower_limit; 36 + try vx.queryColor(tty.anyWriter(), .fg); 37 + try vx.queryColor(tty.anyWriter(), .bg); 38 + var pct: u8 = 0; 36 39 var dir: enum { 37 40 up, 38 41 down, 39 42 } = .up; 43 + 44 + const fg = [_]u8{ 192, 202, 245 }; 45 + const bg = [_]u8{ 26, 27, 38 }; 40 46 41 47 // block until we get a resize 42 48 while (true) { ··· 61 67 const win = vx.window(); 62 68 win.clear(); 63 69 64 - const style: vaxis.Style = .{ .fg = .{ .rgb = [_]u8{ color_idx, color_idx, color_idx } } }; 70 + const color = try blendColors(bg, fg, pct); 71 + 72 + const style: vaxis.Style = .{ .fg = color }; 65 73 66 74 const segment: vaxis.Segment = .{ 67 75 .text = vaxis.logo, ··· 70 78 const center = vaxis.widgets.alignment.center(win, 28, 4); 71 79 _ = try center.printSegment(segment, .{ .wrap = .grapheme }); 72 80 try vx.render(tty.anyWriter()); 73 - std.time.sleep(8 * std.time.ns_per_ms); 81 + std.time.sleep(16 * std.time.ns_per_ms); 74 82 switch (dir) { 75 83 .up => { 76 - color_idx += 1; 77 - if (color_idx == 255) dir = .down; 84 + pct += 1; 85 + if (pct == 100) dir = .down; 78 86 }, 79 87 .down => { 80 - color_idx -= 1; 81 - if (color_idx == lower_limit) dir = .up; 88 + pct -= 1; 89 + if (pct == 0) dir = .up; 82 90 }, 83 91 } 84 92 } 85 93 } 94 + 95 + /// blend two rgb colors. pct is an integer percentage for te portion of 'b' in 96 + /// 'a' 97 + fn blendColors(a: [3]u8, b: [3]u8, pct: u8) !vaxis.Color { 98 + // const r_a = (a[0] * (100 -| pct)) / 100; 99 + 100 + const r_a = (@as(u16, a[0]) * @as(u16, (100 -| pct))) / 100; 101 + const r_b = (@as(u16, b[0]) * @as(u16, pct)) / 100; 102 + 103 + const g_a = (@as(u16, a[1]) * @as(u16, (100 -| pct))) / 100; 104 + const g_b = (@as(u16, b[1]) * @as(u16, pct)) / 100; 105 + // const g_a = try std.math.mul(u8, a[1], (100 -| pct) / 100); 106 + // const g_b = (b[1] * pct) / 100; 107 + 108 + const b_a = (@as(u16, a[2]) * @as(u16, (100 -| pct))) / 100; 109 + const b_b = (@as(u16, b[2]) * @as(u16, pct)) / 100; 110 + // const b_a = try std.math.mul(u8, a[2], (100 -| pct) / 100); 111 + // const b_b = (b[2] * pct) / 100; 112 + return .{ .rgb = [_]u8{ 113 + @min(r_a + r_b, 255), 114 + @min(g_a + g_b, 255), 115 + @min(b_a + b_b, 255), 116 + } }; 117 + }
vaxis.gif

This is a binary file and will not be displayed.