add a formatter for CSI logs so that they're more easy to read

This commit is contained in:
Mitchell Hashimoto
2022-07-23 18:13:37 -07:00
parent bf3d6617fe
commit 4a9b8ea187
2 changed files with 19 additions and 2 deletions

View File

@ -78,6 +78,22 @@ pub const Action = union(enum) {
intermediates: []u8, intermediates: []u8,
params: []u16, params: []u16,
final: u8, final: u8,
// Implement formatter for logging
pub fn format(
self: CSI,
comptime layout: []const u8,
opts: std.fmt.FormatOptions,
writer: anytype,
) !void {
_ = layout;
_ = opts;
try std.fmt.format(writer, "ESC [ {s} {any} {c}", .{
self.intermediates,
self.params,
self.final,
});
}
}; };
pub const ESC = struct { pub const ESC = struct {

View File

@ -49,8 +49,9 @@ pub fn Stream(comptime Handler: type) type {
const actions = self.parser.next(c); const actions = self.parser.next(c);
for (actions) |action_opt| { for (actions) |action_opt| {
// if (action_opt) |action| { // if (action_opt) |action| {
// if (action != .print) { // switch (action) {
// log.info("action: {}", .{action}); // .print => |p| log.info("action: print '{u}'", .{p}),
// else => log.info("action: {}", .{action}),
// } // }
// } // }
switch (action_opt orelse continue) { switch (action_opt orelse continue) {