This commit is contained in:
Jeeves 2024-04-05 18:03:30 -06:00
parent 5e7c8bdae7
commit 9f0c0d4afb
2 changed files with 67 additions and 10 deletions

View file

@ -190,7 +190,8 @@ strings: std.StringHashMap([]const u8),
/// Writes the formatted sequence to a given writer.
pub fn writeString(self: *Self, string: String, writer: anytype, arguments: []const u32) !void {
const output = self.strings.get(string.toCapName());
const capname = string.toCapName();
const output = if (capname) |cn| self.strings.get(cn) else string.default() orelse return error.NoDefaultString;
if (output) |out| {
var formatted = std.ArrayList(u8).init(self.allocator);
defer formatted.deinit();
@ -218,6 +219,7 @@ pub fn writeString(self: *Self, string: String, writer: anytype, arguments: []co
'9' => args[8],
else => return error.InvalidFormatChar,
};
i += 1;
try fmt.format(stack.writer(), "{d}", .{arg});
},
'P' => {},
@ -411,6 +413,7 @@ pub const String = enum {
exit_am_mode,
exit_attribute_mode,
exit_ca_mode,
exit_bold_mode,
exit_delete_mode,
exit_doublewide_mode,
exit_insert_mode,
@ -534,7 +537,7 @@ pub const String = enum {
xon_character,
zero_motion,
pub fn toCapName(self: String) []const u8 {
pub fn toCapName(self: String) ?[]const u8 {
return switch (self) {
.acs_chars => "acsc",
.back_tab => "cbt",
@ -604,6 +607,7 @@ pub const String = enum {
.exit_am_mode => "rmam",
.exit_attribute_mode => "sgr0",
.exit_ca_mode => "rmcup",
.exit_bold_mode => null,
.exit_delete_mode => "rmdc",
.exit_doublewide_mode => "rwidm",
.exit_insert_mode => "rmir",
@ -728,6 +732,13 @@ pub const String = enum {
// else => "",
};
}
pub fn default(self: String) ?[]const u8 {
return switch (self) {
.exit_bold_mode => "\x1b[22m",
else => null,
};
}
};
test "parse terminfo" {