this repo has no description
13
fork

Configure Feed

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

vaxis: mode cleanup, initial mouse implementation

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

+50 -15
+3
examples/text_input.zig
··· 13 13 key_press: vaxis.Key, 14 14 winsize: vaxis.Winsize, 15 15 focus_in, 16 + focus_out, 16 17 foo: u8, 17 18 }; 18 19 ··· 52 53 // Sends queries to terminal to detect certain features. This should 53 54 // _always_ be called, but is left to the application to decide when 54 55 try vx.queryTerminal(); 56 + 57 + try vx.setMouseMode(true); 55 58 56 59 // The main event loop. Vaxis provides a thread safe, blocking, buffered 57 60 // queue which can serve as the primary event queue for an application
+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 + // mouse 14 + pub const mouse_set = "\x1b[?1003;1004;1006h"; 15 + pub const mouse_reset = "\x1b[?1003;1004;1006l"; 16 + 13 17 // sync 14 18 pub const sync_set = "\x1b[?2026h"; 15 19 pub const sync_reset = "\x1b[?2026l";
+43 -15
src/vaxis.zig
··· 51 51 /// the next render 52 52 screen_last: InternalScreen = undefined, 53 53 54 - /// alt_screen state. We track so we can exit on deinit 55 - alt_screen: bool, 56 - 57 - /// if we have entered kitty keyboard 58 - kitty_keyboard: bool = false, 54 + state: struct { 55 + /// if we are in the alt screen 56 + alt_screen: bool = false, 57 + /// if we have entered kitty keyboard 58 + kitty_keyboard: bool = false, 59 + bracketed_paste: bool = false, 60 + mouse: bool = false, 61 + } = .{}, 59 62 60 63 caps: Capabilities = .{}, 61 64 ··· 77 80 .tty = null, 78 81 .screen = .{}, 79 82 .screen_last = .{}, 80 - .alt_screen = false, 81 83 }; 82 84 } 83 85 ··· 88 90 pub fn deinit(self: *Self, alloc: ?std.mem.Allocator) void { 89 91 if (self.tty) |_| { 90 92 var tty = &self.tty.?; 91 - if (self.kitty_keyboard) { 93 + if (self.state.kitty_keyboard) { 92 94 _ = tty.write(ctlseqs.csi_u_pop) catch {}; 93 95 } 94 - if (self.alt_screen) { 96 + if (self.state.mouse) { 97 + _ = tty.write(ctlseqs.mouse_reset) catch {}; 98 + } 99 + if (self.state.bracketed_paste) { 100 + _ = tty.write(ctlseqs.bp_reset) catch {}; 101 + } 102 + if (self.state.alt_screen) { 95 103 _ = tty.write(ctlseqs.rmcup) catch {}; 96 104 } 97 105 tty.flush() catch {}; ··· 165 173 /// enter the alternate screen. The alternate screen will automatically 166 174 /// be exited if calling deinit while in the alt screen 167 175 pub fn enterAltScreen(self: *Self) !void { 168 - if (self.alt_screen) return; 176 + if (self.state.alt_screen) return; 169 177 var tty = self.tty orelse return; 170 178 _ = try tty.write(ctlseqs.smcup); 171 179 try tty.flush(); 172 - self.alt_screen = true; 180 + self.state.alt_screen = true; 173 181 } 174 182 175 183 /// exit the alternate screen 176 184 pub fn exitAltScreen(self: *Self) !void { 177 - if (!self.alt_screen) return; 185 + if (!self.state.alt_screen) return; 178 186 var tty = self.tty orelse return; 179 187 _ = try tty.write(ctlseqs.rmcup); 180 188 try tty.flush(); 181 - self.alt_screen = false; 189 + self.state.alt_screen = false; 182 190 } 183 191 184 192 /// write queries to the terminal to determine capabilities. Individual ··· 468 476 } 469 477 470 478 fn enableKittyKeyboard(self: *Self, flags: Key.KittyFlags) !void { 471 - self.kitty_keyboard = true; 479 + self.state.kitty_keyboard = true; 472 480 const flag_int: u5 = @bitCast(flags); 473 481 try std.fmt.format( 474 482 self.tty.?.buffered_writer.writer(), ··· 511 519 // turn bracketed paste on or off. An event will be sent at the 512 520 // beginning and end of a detected paste. All keystrokes between these 513 521 // events were pasted 514 - pub fn bracketedPaste(self: *Self, enable: bool) !void { 522 + pub fn setBracketedPaste(self: *Self, enable: bool) !void { 515 523 if (self.tty == null) return; 516 - const seq = if (enable) ctlseqs.bp_set else ctlseqs.bp_reset; 524 + self.state.bracketed_paste = enable; 525 + const seq = if (enable) { 526 + self.state.bracketed_paste = true; 527 + ctlseqs.bp_set; 528 + } else { 529 + self.state.bracketed_paste = true; 530 + ctlseqs.bp_reset; 531 + }; 517 532 _ = try self.tty.?.write(seq); 518 533 try self.tty.?.flush(); 519 534 } ··· 521 536 /// set the mouse shape 522 537 pub fn setMouseShape(self: *Self, shape: Shape) void { 523 538 self.screen.mouse_shape = shape; 539 + } 540 + 541 + /// turn mouse reporting on or off 542 + pub fn setMouseMode(self: *Self, enable: bool) !void { 543 + var tty = self.tty orelse return; 544 + self.state.mouse = enable; 545 + if (enable) { 546 + _ = try tty.write(ctlseqs.mouse_set); 547 + try tty.flush(); 548 + } else { 549 + _ = try tty.write(ctlseqs.mouse_reset); 550 + try tty.flush(); 551 + } 524 552 } 525 553 }; 526 554 }