this repo has no description
13
fork

Configure Feed

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

at 4e5a065940825f147fa5ce0df54d1ef0d50ecee7 63 lines 1.9 kB view raw
1const std = @import("std"); 2const log = std.log.scoped(.main); 3const vaxis = @import("vaxis"); 4 5const TextView = vaxis.widgets.TextView; 6 7const Event = union(enum) { 8 key_press: vaxis.Key, 9 winsize: vaxis.Winsize, 10}; 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 defer tty.deinit(); 19 20 var vx = try vaxis.init(io, alloc, init.environ_map, .{}); 21 defer vx.deinit(alloc, tty.writer()); 22 23 var loop: vaxis.Loop(Event) = .init(io, &tty, &vx); 24 try loop.start(); 25 defer loop.stop(); 26 27 try vx.enterAltScreen(tty.writer()); 28 try vx.queryTerminal(tty.writer(), .fromSeconds(20)); 29 30 var text_view = TextView{}; 31 var text_view_buffer = TextView.Buffer{}; 32 defer text_view_buffer.deinit(alloc); 33 try text_view_buffer.append(alloc, .{ .bytes = "Press Enter to add a line, Up/Down to scroll, 'c' to close." }); 34 35 var counter: i32 = 0; 36 var lineBuf: [128]u8 = undefined; 37 38 while (true) { 39 const event = try loop.nextEvent(); 40 switch (event) { 41 .key_press => |key| { 42 // Close demo 43 if (key.matches('c', .{})) break; 44 if (key.matches(vaxis.Key.enter, .{})) { 45 counter += 1; 46 const new_content = try std.fmt.bufPrint(&lineBuf, "\nLine {d}", .{counter}); 47 try text_view_buffer.append(alloc, .{ .bytes = new_content }); 48 } 49 text_view.input(key); 50 }, 51 .winsize => |ws| try vx.resize(alloc, tty.writer(), ws), 52 } 53 const win = vx.window(); 54 win.clear(); 55 text_view.draw(win, text_view_buffer); 56 try vx.render(tty.writer()); 57 try tty.writer().flush(); 58 } 59} 60 61test { 62 std.testing.refAllDecls(@This()); 63}