this repo has no description
13
fork

Configure Feed

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

examples(table): updated the table example w/ latest vaxis changes

- Added `loop.init()` to regain dynamic resizing. (Thanks @rockorager!)
- Used the TTY's Buffered Writer where applicable.
- Updated `win.initChild()` to `win.child()` in all cases.
- Improved ArenaAllocator usage.

authored by

00JCIV00 and committed by
Tim Culverhouse
5972da8e 94879164

+36 -28
+36 -28
examples/table.zig
··· 29 29 30 30 var tty = try vaxis.Tty.init(); 31 31 defer tty.deinit(); 32 - 33 - var vx = try vaxis.init(alloc, .{}); 32 + var tty_buf_writer = tty.bufferedWriter(); 33 + defer tty_buf_writer.flush() catch {}; 34 + const tty_writer = tty_buf_writer.writer().any(); 35 + var vx = try vaxis.init(alloc, .{ 36 + .kitty_keyboard_flags = .{ .report_events = true }, 37 + }); 34 38 defer vx.deinit(alloc, tty.anyWriter()); 35 39 36 40 var loop: vaxis.Loop(union(enum) { ··· 38 42 winsize: vaxis.Winsize, 39 43 }) = .{ .tty = &tty, .vaxis = &vx }; 40 44 try loop.init(); 41 - 42 45 try loop.start(); 43 46 defer loop.stop(); 44 - try vx.enterAltScreen(tty.anyWriter()); 45 - try vx.queryTerminal(tty.anyWriter(), 1 * std.time.ns_per_s); 47 + try vx.enterAltScreen(tty_writer); 48 + try vx.queryTerminal(tty.anyWriter(), 250 * std.time.ns_per_ms); 46 49 47 50 const logo = 48 51 \\░█░█░█▀█░█░█░▀█▀░█▀▀░░░▀█▀░█▀█░█▀▄░█░░░█▀▀░ ··· 71 74 const other_bg: vaxis.Cell.Color = .{ .rgb = .{ 32, 32, 48 } }; 72 75 73 76 // Table Context 74 - var demo_tbl: vaxis.widgets.Table.TableContext = .{ .selected_bg = selected_bg }; 77 + var demo_tbl: vaxis.widgets.Table.TableContext = .{ 78 + .selected_bg = selected_bg, 79 + //.col_width = 10, 80 + }; 75 81 76 82 // TUI State 77 83 var active: ActiveSection = .mid; 78 84 var moving = false; 79 85 86 + // Create an Arena Allocator for easy allocations on each Event. 87 + var event_arena = heap.ArenaAllocator.init(alloc); 88 + defer event_arena.deinit(); 80 89 while (true) { 81 - // Create an Arena Allocator for easy allocations on each Event. 82 - var event_arena = heap.ArenaAllocator.init(alloc); 83 - defer event_arena.deinit(); 90 + defer _ = event_arena.reset(.retain_capacity); 91 + defer tty_buf_writer.flush() catch {}; 84 92 const event_alloc = event_arena.allocator(); 85 93 const event = loop.nextEvent(); 86 94 ··· 163 171 164 172 // - Top 165 173 const top_div = 6; 166 - const top_bar = win.initChild( 167 - 0, 168 - 0, 169 - .{ .limit = win.width }, 170 - .{ .limit = win.height / top_div }, 171 - ); 174 + const top_bar = win.child(.{ 175 + .x_off = 0, 176 + .y_off = 0, 177 + .width = .{ .limit = win.width }, 178 + .height = .{ .limit = win.height / top_div }, 179 + }); 172 180 for (title_segs[0..]) |*title_seg| 173 181 title_seg.*.style.bg = if (active == .top) selected_bg else other_bg; 174 182 top_bar.fill(.{ .style = .{ ··· 182 190 _ = try logo_bar.print(title_segs[0..], .{ .wrap = .word }); 183 191 184 192 // - Middle 185 - const middle_bar = win.initChild( 186 - 0, 187 - win.height / top_div, 188 - .{ .limit = win.width }, 189 - .{ .limit = win.height - (top_bar.height + 1) }, 190 - ); 193 + const middle_bar = win.child(.{ 194 + .x_off = 0, 195 + .y_off = win.height / top_div, 196 + .width = .{ .limit = win.width }, 197 + .height = .{ .limit = win.height - (top_bar.height + 1) }, 198 + }); 191 199 if (user_list.items.len > 0) { 192 200 demo_tbl.active = active == .mid; 193 201 try vaxis.widgets.Table.drawTable( ··· 202 210 } 203 211 204 212 // - Bottom 205 - const bottom_bar = win.initChild( 206 - 0, 207 - win.height - 1, 208 - .{ .limit = win.width }, 209 - .{ .limit = 1 }, 210 - ); 213 + const bottom_bar = win.child(.{ 214 + .x_off = 0, 215 + .y_off = win.height - 1, 216 + .width = .{ .limit = win.width }, 217 + .height = .{ .limit = 1 }, 218 + }); 211 219 if (active == .btm) bottom_bar.fill(.{ .style = .{ .bg = selected_bg } }); 212 220 cmd_input.draw(bottom_bar); 213 221 214 222 // Render the screen 215 - try vx.render(tty.anyWriter()); 223 + try vx.render(tty_writer); 216 224 } 217 225 } 218 226