this repo has no description
13
fork

Configure Feed

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

at 4e5a065940825f147fa5ce0df54d1ef0d50ecee7 110 lines 2.9 kB view raw
1const std = @import("std"); 2const vaxis = @import("vaxis"); 3const Cell = vaxis.Cell; 4 5const Event = union(enum) { 6 key_press: vaxis.Key, 7 winsize: vaxis.Winsize, 8}; 9 10pub const panic = vaxis.panic_handler; 11 12pub fn main(init: std.process.Init) !void { 13 const io = init.io; 14 const alloc = init.gpa; 15 16 var buffer: [1024]u8 = undefined; 17 var tty: vaxis.Tty = try .init(io, &buffer); 18 const writer = tty.writer(); 19 var vx = try vaxis.init(io, alloc, init.environ_map, .{}); 20 defer vx.deinit(alloc, writer); 21 22 var loop: vaxis.Loop(Event) = .init(io, &tty, &vx); 23 24 try loop.start(); 25 defer loop.stop(); 26 27 try vx.enterAltScreen(writer); 28 try vx.queryTerminal(writer, .fromSeconds(1)); 29 30 const vt_opts: vaxis.widgets.Terminal.Options = .{ 31 .winsize = .{ 32 .rows = 24, 33 .cols = 100, 34 .x_pixel = 0, 35 .y_pixel = 0, 36 }, 37 .scrollback_size = 0, 38 .initial_working_directory = init.environ_map.get("HOME") orelse @panic("no $HOME"), 39 }; 40 const shell = init.environ_map.get("SHELL") orelse "bash"; 41 const argv = [_][]const u8{shell}; 42 var write_buf: [4096]u8 = undefined; 43 var vt = try vaxis.widgets.Terminal.init( 44 io, 45 alloc, 46 &argv, 47 init.environ_map, 48 vt_opts, 49 &write_buf, 50 ); 51 defer vt.deinit(); 52 try vt.spawn(); 53 54 var redraw: bool = false; 55 while (true) { 56 try io.sleep(.fromMilliseconds(8), .real); 57 // try vt events first 58 while (try vt.tryEvent()) |event| { 59 redraw = true; 60 switch (event) { 61 .bell => {}, 62 .title_change => {}, 63 .exited => return, 64 .redraw => {}, 65 .pwd_change => {}, 66 } 67 } 68 while (try loop.tryEvent()) |event| { 69 redraw = true; 70 switch (event) { 71 .key_press => |key| { 72 if (key.matches('c', .{ .ctrl = true })) return; 73 try vt.update(.{ .key_press = key }); 74 }, 75 .winsize => |ws| try vx.resize(alloc, writer, ws), 76 } 77 } 78 if (!redraw) continue; 79 redraw = false; 80 81 const win = vx.window(); 82 win.hideCursor(); 83 win.clear(); 84 const child = win.child(.{ 85 .x_off = 4, 86 .y_off = 2, 87 .width = 120, 88 .height = 40, 89 .border = .{ 90 .where = .all, 91 }, 92 }); 93 94 try vt.resize(.{ 95 .rows = child.height, 96 .cols = child.width, 97 .x_pixel = 0, 98 .y_pixel = 0, 99 }); 100 try vt.draw(alloc, child); 101 102 try vx.render(writer); 103 } 104} 105 106test { 107 const builtin = @import("builtin"); 108 if (builtin.os.tag != .linux) return error.SkipZigTest; 109 std.testing.refAllDecls(@This()); 110}