this repo has no description
13
fork

Configure Feed

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

widgets(terminal): improve logging

+47 -7
+11 -7
src/widgets/terminal/Terminal.zig
··· 109 109 self.thread = try std.Thread.spawn(.{}, Terminal.run, .{self}); 110 110 } 111 111 112 - /// resize the screen. Locks access to the back screen. Should only be called from the main thread 112 + /// resize the screen. Locks access to the back screen. Should only be called from the main thread. 113 + /// This is safe to call every render cycle: there is a guard to only perform a resize if the size 114 + /// of the window has changed. 113 115 pub fn resize(self: *Terminal, ws: Winsize) !void { 114 116 // don't deinit with no size change 115 117 if (ws.cols == self.front_screen.width and 116 118 ws.rows == self.front_screen.height) 117 - { 118 - std.log.debug("resize requested but no change", .{}); 119 119 return; 120 - } 121 120 122 121 self.back_mutex.lock(); 123 122 defer self.back_mutex.unlock(); ··· 181 180 const event = try parser.parseReader(reader); 182 181 self.back_mutex.lock(); 183 182 defer self.back_mutex.unlock(); 183 + 184 184 switch (event) { 185 185 .print => |str| { 186 - std.log.err("print: {s}", .{str}); 187 186 var iter = grapheme.Iterator.init(str, &self.unicode.grapheme_data); 188 187 while (iter.next()) |g| { 189 188 const bytes = g.bytes(str); ··· 192 191 } 193 192 }, 194 193 .c0 => |b| try self.handleC0(b), 194 + .escape => |str| std.log.err("unhandled escape: {s}", .{str}), 195 + .ss2 => |ss2| std.log.err("unhandled ss2: {c}", .{ss2}), 196 + .ss3 => |ss3| std.log.err("unhandled ss3: {c}", .{ss3}), 195 197 .csi => |seq| { 196 198 switch (seq.final) { 197 199 'B' => { // CUD ··· 219 221 self.back_screen.sgr(seq); 220 222 } 221 223 }, 222 - else => {}, 224 + else => std.log.err("unhandled CSI: {}", .{seq}), 223 225 } 224 226 }, 225 - else => {}, 227 + .osc => |osc| std.log.err("unhandled osc: {s}", .{osc}), 228 + .apc => |apc| std.log.err("unhandled apc: {s}", .{apc}), 226 229 } 227 230 } 228 231 } ··· 230 233 inline fn handleC0(self: *Terminal, b: ansi.C0) !void { 231 234 switch (b) { 232 235 .NUL, .SOH, .STX => {}, 236 + .EOT => {}, // we send EOT to quit the read thread 233 237 .ENQ => {}, 234 238 .BEL => self.pending_events.bell.store(true, .unordered), 235 239 .BS => self.back_screen.cursorLeft(1),
+36
src/widgets/terminal/ansi.zig
··· 1 + const std = @import("std"); 2 + 1 3 /// Control bytes. See man 7 ascii 2 4 pub const C0 = enum(u8) { 3 5 NUL = 0x00, ··· 51 53 52 54 pub fn iterator(self: CSI, comptime T: type) ParamIterator(T) { 53 55 return .{ .bytes = self.params }; 56 + } 57 + 58 + pub fn format( 59 + self: CSI, 60 + comptime layout: []const u8, 61 + opts: std.fmt.FormatOptions, 62 + writer: anytype, 63 + ) !void { 64 + _ = layout; 65 + _ = opts; 66 + if (self.private_marker == null and self.intermediate == null) 67 + try std.fmt.format(writer, "CSI {s} {c}", .{ 68 + self.params, 69 + self.final, 70 + }) 71 + else if (self.private_marker != null and self.intermediate == null) 72 + try std.fmt.format(writer, "CSI {c} {s} {c}", .{ 73 + self.private_marker.?, 74 + self.params, 75 + self.final, 76 + }) 77 + else if (self.private_marker == null and self.intermediate != null) 78 + try std.fmt.format(writer, "CSI {s} {c} {c}", .{ 79 + self.params, 80 + self.intermediate.?, 81 + self.final, 82 + }) 83 + else 84 + try std.fmt.format(writer, "CSI {c} {s} {c} {c}", .{ 85 + self.private_marker.?, 86 + self.params, 87 + self.intermediate.?, 88 + self.final, 89 + }); 54 90 } 55 91 }; 56 92