mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
big improvements in action logging
This commit is contained in:
@ -99,6 +99,21 @@ pub const Action = union(enum) {
|
|||||||
pub const ESC = struct {
|
pub const ESC = struct {
|
||||||
intermediates: []u8,
|
intermediates: []u8,
|
||||||
final: u8,
|
final: u8,
|
||||||
|
|
||||||
|
// Implement formatter for logging
|
||||||
|
pub fn format(
|
||||||
|
self: ESC,
|
||||||
|
comptime layout: []const u8,
|
||||||
|
opts: std.fmt.FormatOptions,
|
||||||
|
writer: anytype,
|
||||||
|
) !void {
|
||||||
|
_ = layout;
|
||||||
|
_ = opts;
|
||||||
|
try std.fmt.format(writer, "ESC {s} {c}", .{
|
||||||
|
self.intermediates,
|
||||||
|
self.final,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DCS = struct {
|
pub const DCS = struct {
|
||||||
@ -106,6 +121,55 @@ pub const Action = union(enum) {
|
|||||||
params: []u16,
|
params: []u16,
|
||||||
final: u8,
|
final: u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Implement formatter for logging. This is mostly copied from the
|
||||||
|
// std.fmt implementation, but we modify it slightly so that we can
|
||||||
|
// print out custom formats for some of our primitives.
|
||||||
|
pub fn format(
|
||||||
|
self: Action,
|
||||||
|
comptime layout: []const u8,
|
||||||
|
opts: std.fmt.FormatOptions,
|
||||||
|
writer: anytype,
|
||||||
|
) !void {
|
||||||
|
_ = layout;
|
||||||
|
const T = Action;
|
||||||
|
const info = @typeInfo(T).Union;
|
||||||
|
|
||||||
|
try writer.writeAll(@typeName(T));
|
||||||
|
if (info.tag_type) |TagType| {
|
||||||
|
try writer.writeAll("{ .");
|
||||||
|
try writer.writeAll(@tagName(@as(TagType, self)));
|
||||||
|
try writer.writeAll(" = ");
|
||||||
|
|
||||||
|
inline for (info.fields) |u_field| {
|
||||||
|
// If this is the active field...
|
||||||
|
if (self == @field(TagType, u_field.name)) {
|
||||||
|
const value = @field(self, u_field.name);
|
||||||
|
switch (@TypeOf(value)) {
|
||||||
|
// Unicode
|
||||||
|
u21 => try std.fmt.format(writer, "'{u}'", .{value}),
|
||||||
|
|
||||||
|
// Note: we don't do ASCII (u8) because there are a lot
|
||||||
|
// of invisible characters we don't want to handle right
|
||||||
|
// now.
|
||||||
|
|
||||||
|
// All others do the default behavior
|
||||||
|
else => try std.fmt.formatType(
|
||||||
|
@field(self, u_field.name),
|
||||||
|
"any",
|
||||||
|
opts,
|
||||||
|
writer,
|
||||||
|
3,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try writer.writeAll(" }");
|
||||||
|
} else {
|
||||||
|
try format(writer, "@{x}", .{@ptrToInt(&self)});
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Keeps track of the parameter sep used for CSI params. We allow colons
|
/// Keeps track of the parameter sep used for CSI params. We allow colons
|
||||||
|
@ -49,10 +49,7 @@ 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| {
|
||||||
// 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) {
|
||||||
.print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),
|
.print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),
|
||||||
|
Reference in New Issue
Block a user