this repo has no description
13
fork

Configure Feed

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

tty: use grapheme cache in the tty run method

We only need the grapheme cache when we are parsing input

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

+11 -7
+11 -2
src/Tty.zig
··· 6 6 const Event = @import("event.zig").Event; 7 7 const parser = @import("parser.zig"); 8 8 const Key = vaxis.Key; 9 + const GraphemeCache = @import("GraphemeCache.zig"); 9 10 10 11 const log = std.log.scoped(.tty); 11 12 ··· 112 113 }; 113 114 try WinchHandler.init(vx, self.fd); 114 115 116 + // initialize a grapheme cache 117 + var cache: GraphemeCache = .{}; 118 + 115 119 // Set up fds for polling 116 120 var pollfds: [2]std.os.pollfd = .{ 117 121 .{ .fd = self.fd, .events = std.os.POLL.IN, .revents = undefined }, ··· 132 136 var start: usize = 0; 133 137 while (start < n) { 134 138 const result = try parser.parse(buf[start..n]); 135 - start = result.n; 139 + start += result.n; 136 140 // TODO: if we get 0 byte read, copy the remaining bytes to the 137 141 // beginning of the buffer and read mmore? this should only happen 138 142 // if we are in the middle of a grapheme at and filled our ··· 143 147 switch (event) { 144 148 .key_press => |key| { 145 149 if (@hasField(EventType, "key_press")) { 146 - vx.postEvent(.{ .key_press = key }); 150 + // HACK: yuck. there has to be a better way 151 + var mut_key = key; 152 + if (key.text) |text| { 153 + mut_key.text = cache.put(text); 154 + } 155 + vx.postEvent(.{ .key_press = mut_key }); 147 156 } 148 157 }, 149 158 .focus_in => {
-1
src/parser.zig
··· 79 79 state = .escape; 80 80 continue; 81 81 }, 82 - // 0x20...0x7E => .{ .codepoint = b }, 83 82 0x7F => .{ .codepoint = Key.backspace }, 84 83 else => blk: { 85 84 var iter: CodePointIterator = .{ .bytes = input[i..] };
-4
src/vaxis.zig
··· 9 9 const Window = @import("Window.zig"); 10 10 const Options = @import("Options.zig"); 11 11 const Style = @import("cell.zig").Style; 12 - const GraphemeCache = @import("GraphemeCache.zig"); 13 12 14 13 /// Vaxis is the entrypoint for a Vaxis application. The provided type T should 15 14 /// be a tagged union which contains all of the events the application will ··· 46 45 // statistics 47 46 renders: usize = 0, 48 47 render_dur: i128 = 0, 49 - 50 - // grapheme cache 51 - g_cache: GraphemeCache = .{}, 52 48 53 49 /// Initialize Vaxis with runtime options 54 50 pub fn init(_: Options) !Self {