this repo has no description
13
fork

Configure Feed

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

vaxis: add sync and refresh

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

+50 -17
+6 -1
examples/text_input.zig
··· 34 34 var text_input = TextInput.init(alloc); 35 35 defer text_input.deinit(); 36 36 37 + try vx.queryTerminal(); 38 + 37 39 // The main event loop. Vaxis provides a thread safe, blocking, buffered 38 40 // queue which can serve as the primary event queue for an application 39 41 outer: while (true) { ··· 49 51 else => color_idx + 1, 50 52 }; 51 53 try text_input.update(.{ .key_press = key }); 52 - if (key.codepoint == 'c' and key.mods.ctrl) { 54 + if (key.matches('c', .{ .ctrl = true })) { 53 55 break :outer; 56 + } 57 + if (key.matches('l', .{ .ctrl = true })) { 58 + vx.queueRefresh(); 54 59 } 55 60 }, 56 61 .winsize => |ws| {
+4
src/ctlseqs.zig
··· 10 10 pub const kitty_graphics_query = "\x1b_Gi=1,a=q\x1b\\"; 11 11 pub const sixel_geometry_query = "\x1b[?2;1;0S"; 12 12 13 + // sync 14 + pub const sync_set = "\x1b[?2026h"; 15 + pub const sync_reset = "\x1b[?2026l"; 16 + 13 17 // Key encoding 14 18 pub const csi_u_push = "\x1b[>{d}u"; 15 19 pub const csi_u_pop = "\x1b[<u";
+40 -16
src/vaxis.zig
··· 36 36 37 37 tty: ?Tty, 38 38 39 + /// the screen we write to 39 40 screen: Screen, 40 - // The last screen we drew. We keep this so we can efficiently update on 41 - // the next render 41 + /// The last screen we drew. We keep this so we can efficiently update on 42 + /// the next render 42 43 screen_last: InternalScreen = undefined, 43 44 45 + /// alt_screen state. We track so we can exit on deinit 44 46 alt_screen: bool, 47 + 48 + /// if we should redraw the entire screen on the next render 49 + refresh: bool = false, 45 50 46 51 // statistics 47 52 renders: usize = 0, ··· 161 166 var tty = self.tty orelse return; 162 167 163 168 const colorterm = std.os.getenv("COLORTERM") orelse ""; 164 - if (std.mem.eql(u8, colorterm, "truecolor" or 165 - std.mem.eql(u8, colorterm, "24bit"))) 169 + if (std.mem.eql(u8, colorterm, "truecolor") or 170 + std.mem.eql(u8, colorterm, "24bit")) 166 171 { 167 172 // TODO: Notify rgb support 168 173 } 169 174 170 - const writer = tty.buffered_writer.writer(); 171 - _ = try writer.write(ctlseqs.decrqm_focus); 172 - _ = try writer.write(ctlseqs.decrqm_sync); 173 - _ = try writer.write(ctlseqs.decrqm_unicode); 174 - _ = try writer.write(ctlseqs.decrqm_color_theme); 175 - _ = try writer.write(ctlseqs.xtversion); 176 - _ = try writer.write(ctlseqs.csi_u_query); 177 - _ = try writer.write(ctlseqs.kitty_graphics_query); 178 - _ = try writer.write(ctlseqs.sixel_geometry_query); 175 + // TODO: decide if we actually want to query for focus and sync. It 176 + // doesn't hurt to blindly use them 177 + // _ = try tty.write(ctlseqs.decrqm_focus); 178 + // _ = try tty.write(ctlseqs.decrqm_sync); 179 + _ = try tty.write(ctlseqs.decrqm_unicode); 180 + _ = try tty.write(ctlseqs.decrqm_color_theme); 181 + // TODO: XTVERSION has a DCS response. uncomment when we can parse 182 + // that 183 + // _ = try tty.write(ctlseqs.xtversion); 184 + _ = try tty.write(ctlseqs.csi_u_query); 185 + // TODO: KITTY_GRAPHICS has an APC response. uncomment when we can 186 + // parse that 187 + // that 188 + // _ = try tty.write(ctlseqs.kitty_graphics_query); 189 + _ = try tty.write(ctlseqs.sixel_geometry_query); 179 190 180 191 // TODO: XTGETTCAP queries ("RGB", "Smulx") 181 192 182 - _ = try writer.write(ctlseqs.primary_device_attrs); 183 - try writer.flush(); 193 + _ = try tty.write(ctlseqs.primary_device_attrs); 194 + try tty.flush(); 195 + } 196 + 197 + // the next render call will refresh the entire screen 198 + pub fn queueRefresh(self: *Self) void { 199 + self.refresh = true; 184 200 } 185 201 186 202 /// draws the screen to the terminal ··· 192 208 self.render_dur += std.time.microTimestamp() - timer_start; 193 209 } 194 210 211 + defer self.refresh = false; 195 212 defer tty.flush() catch {}; 213 + 214 + // Set up sync before we write anything 215 + // TODO: optimize sync so we only sync _when we have changes_. This 216 + // requires a smarter buffered writer, we'll probably have to write 217 + // our own 218 + _ = try tty.write(ctlseqs.sync_set); 219 + defer _ = tty.write(ctlseqs.sync_reset) catch {}; 196 220 197 221 // Send the cursor to 0,0 198 222 // TODO: this needs to move after we optimize writes. We only do ··· 218 242 } 219 243 // If cell is the same as our last frame, we don't need to do 220 244 // anything 221 - if (self.screen_last.buf[i].eql(cell)) { 245 + if (!self.refresh and self.screen_last.buf[i].eql(cell)) { 222 246 reposition = true; 223 247 // Close any osc8 sequence we might be in before 224 248 // repositioning