this repo has no description
13
fork

Configure Feed

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

render: fix when we set current cursor to new style, update examples

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>

+19 -4
+8 -1
examples/text_input.zig
··· 28 28 // Optionally enter the alternate screen 29 29 try vx.enterAltScreen(); 30 30 31 + // We'll adjust the color index every keypress for the border 32 + var color_idx: u8 = 0; 33 + 31 34 var text_input: TextInput = .{}; 32 35 33 36 // The main event loop. Vaxis provides a thread safe, blocking, buffered ··· 40 43 // enum has the fields for those events (ie "key_press", "winsize") 41 44 switch (event) { 42 45 .key_press => |key| { 46 + color_idx += 1; 43 47 text_input.update(.{ .key_press = key }); 44 48 if (key.codepoint == 'c' and key.mods.ctrl) { 45 49 break :outer; ··· 61 65 win.clear(); 62 66 const child = win.initChild(win.width / 2 - 20, win.height / 2 - 3, .{ .limit = 40 }, .{ .limit = 3 }); 63 67 // draw the text_input using a bordered window 64 - text_input.draw(border.all(child, .{})); 68 + const style: vaxis.Style = .{ 69 + .fg = .{ .index = color_idx }, 70 + }; 71 + text_input.draw(border.all(child, style)); 65 72 66 73 // Render the screen 67 74 try vx.render();
+4 -1
src/ctlseqs.zig
··· 24 24 pub const smcup = "\x1b[?1049h"; 25 25 pub const rmcup = "\x1b[?1049l"; 26 26 27 + // sgr reset all 28 + pub const sgr_reset = "\x1b[m"; 29 + 27 30 // colors 28 31 pub const fg_base = "\x1b[3{d}m"; 29 32 pub const fg_bright = "\x1b[9{d}m"; ··· 33 36 pub const fg_reset = "\x1b[39m"; 34 37 pub const bg_reset = "\x1b[49m"; 35 38 pub const ul_reset = "\x1b[59m"; 36 - pub const fg_indexed = "\x1b[38;5;{d}m"; 39 + pub const fg_indexed = "\x1b[38:5:{d}m"; 37 40 pub const bg_indexed = "\x1b[48:5:{d}m"; 38 41 pub const ul_indexed = "\x1b[58:5:{d}m"; 39 42 pub const fg_rgb = "\x1b[38:2:{d}:{d}:{d}m";
+1
src/main.zig
··· 3 3 4 4 const cell = @import("cell.zig"); 5 5 pub const Cell = cell.Cell; 6 + pub const Style = cell.Style; 6 7 7 8 pub const Key = @import("Key.zig"); 8 9 pub const Winsize = @import("Tty.zig").Winsize;
+2 -1
src/vaxis.zig
··· 196 196 // and then reshow it if needed 197 197 _ = try tty.write(ctlseqs.hide_cursor); 198 198 _ = try tty.write(ctlseqs.home); 199 + _ = try tty.write(ctlseqs.sgr_reset); 199 200 200 201 // initialize some variables 201 202 var reposition: bool = false; ··· 207 208 while (i < self.screen.buf.len) : (i += 1) { 208 209 const cell = self.screen.buf[i]; 209 210 defer col += 1; 210 - defer cursor = cell.style; 211 211 if (col == self.screen.width) { 212 212 row += 1; 213 213 col = 0; ··· 223 223 } 224 224 continue; 225 225 } 226 + defer cursor = cell.style; 226 227 // Set this cell in the last frame 227 228 self.screen_last.buf[i] = cell; 228 229
+4 -1
src/widgets/TextInput.zig
··· 24 24 pub fn update(self: *TextInput, event: Event) void { 25 25 switch (event) { 26 26 .key_press => |key| { 27 - log.info("key : {}", .{key}); 28 27 if (key.text) |text| { 29 28 @memcpy(self.buffer[self.buffer_idx .. self.buffer_idx + text.len], text); 30 29 self.buffer_idx += text.len; 30 + self.cursor_idx += strWidth(text, .full) catch 1; 31 31 } 32 32 switch (key.codepoint) { 33 33 Key.backspace => { 34 34 // TODO: this only works at the end of the array. Then 35 35 // again, we don't have any means to move the cursor yet 36 + // This also doesn't work with graphemes yet 36 37 if (self.buffer_idx == 0) return; 37 38 self.buffer_idx -= 1; 39 + self.cursor_idx -= 1; 38 40 }, 39 41 else => {}, 40 42 } ··· 57 59 }); 58 60 col += w; 59 61 } 62 + win.showCursor(self.cursor_idx, 0); 60 63 }