remove helpers in favor of enums
This commit is contained in:
parent
5b6395e864
commit
3d63eb374f
2 changed files with 175 additions and 61 deletions
|
@ -88,7 +88,8 @@ pub const Terminal = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursorLeft(self: *Terminal) !void {
|
pub fn cursorLeft(self: *Terminal) !void {
|
||||||
try self.info.cursorLeft(self.tty.writer());
|
try self.info.writeString(.cursor_left, self.tty.writer());
|
||||||
|
// try self.info.cursorLeft(self.tty.writer());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const Info = @import("terminfo.zig");
|
pub const Info = @import("terminfo.zig");
|
||||||
|
|
233
src/terminfo.zig
233
src/terminfo.zig
|
@ -188,65 +188,12 @@ bools: std.StringHashMap(bool),
|
||||||
ints: std.StringHashMap(u32),
|
ints: std.StringHashMap(u32),
|
||||||
strings: std.StringHashMap([]const u8),
|
strings: std.StringHashMap([]const u8),
|
||||||
|
|
||||||
// TODO: move these to a single function taking a tuple for the args
|
/// Writes the formatted sequence to a given writer.
|
||||||
|
pub fn writeString(self: *Self, string: String, writer: anytype) !void {
|
||||||
pub fn clearScreen(self: *Self, writer: anytype) !void {
|
const output = self.strings.get(string.toCapName());
|
||||||
try writer.writeAll(self.strings.get("clear") orelse "\x1b[H\x1b[2J");
|
if (output) |o| try writer.writeAll(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clearToLineBegin(self: *Self, writer: anytype) !void {
|
|
||||||
try writer.writeAll(self.strings.get("el1") orelse "\x1b[1K");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clearToLineEnd(self: *Self, writer: anytype) !void {
|
|
||||||
try writer.writeAll(self.strings.get("el") orelse "\x1b[K");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clearToScreenEnd(self: *Self, writer: anytype) !void {
|
|
||||||
try writer.writeAll(self.strings.get("ed") orelse "\x1b[J");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cursorHome(self: *Self, writer: anytype) !void {
|
|
||||||
try writer.writeAll(self.strings.get("home") orelse "\x1b[H");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cursorDown(self: *Self, writer: anytype) !void {
|
|
||||||
try writer.writeAll(self.strings.get("cud1") orelse "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cursorLeft(self: *Self, writer: anytype) !void {
|
|
||||||
try writer.writeAll(self.strings.get("cub1") orelse "\x08");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cursorRight(self: *Self, writer: anytype) !void {
|
|
||||||
try writer.writeAll(self.strings.get("cuf1") orelse "\x1b[C");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cursorUp(self: *Self, writer: anytype) !void {
|
|
||||||
try writer.writeAll(self.strings.get("cuu1") orelse "\x1b[A");
|
|
||||||
}
|
|
||||||
|
|
||||||
// pub const Sequence = struct {
|
|
||||||
// info: *Self,
|
|
||||||
// bytes: std.ArrayList(u8),
|
|
||||||
|
|
||||||
// pub fn init(allocator: mem.Allocator, info: *Self) Sequence {
|
|
||||||
// return .{ .info = info, .bytes = std.ArrayList(u8).init(allocator) };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn deinit(self: *Sequence) void {
|
|
||||||
// self.bytes.deinit();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn writeOut(self: *Sequence, writer: anytype) !void {
|
|
||||||
// try writer.writeAll(self.bytes.items);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn cursorLeft(self: *Sequence) !void {
|
|
||||||
// try self.bytes.appendSlice(self.info.strings.get("cub1") orelse "\x08");
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
pub const Bool = enum {
|
pub const Bool = enum {
|
||||||
auto_left_margin,
|
auto_left_margin,
|
||||||
auto_right_margin,
|
auto_right_margin,
|
||||||
|
@ -329,7 +276,7 @@ pub const Bool = enum {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Ints = enum {
|
pub const Int = enum {
|
||||||
columns,
|
columns,
|
||||||
init_tabs,
|
init_tabs,
|
||||||
label_height,
|
label_height,
|
||||||
|
@ -348,9 +295,10 @@ pub const Ints = enum {
|
||||||
width_status_line,
|
width_status_line,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Strings = enum {
|
pub const String = enum {
|
||||||
acs_chars,
|
acs_chars,
|
||||||
back_tab_bell,
|
back_tab,
|
||||||
|
bell,
|
||||||
carriage_return,
|
carriage_return,
|
||||||
change_char_pitch,
|
change_char_pitch,
|
||||||
change_line_pitch,
|
change_line_pitch,
|
||||||
|
@ -359,6 +307,171 @@ pub const Strings = enum {
|
||||||
change_scroll_region,
|
change_scroll_region,
|
||||||
char_padding,
|
char_padding,
|
||||||
clear_all_tabs,
|
clear_all_tabs,
|
||||||
|
clear_margins,
|
||||||
|
clear_screen,
|
||||||
|
clr_bol,
|
||||||
|
clr_eol,
|
||||||
|
clr_eos,
|
||||||
|
column_address,
|
||||||
|
command_character,
|
||||||
|
create_window,
|
||||||
|
cursor_address,
|
||||||
|
cursor_down,
|
||||||
|
cursor_home,
|
||||||
|
cursor_invisible,
|
||||||
|
cursor_left,
|
||||||
|
cursor_mem_address,
|
||||||
|
cursor_normal,
|
||||||
|
cursor_right,
|
||||||
|
cursor_to_ll,
|
||||||
|
cursor_up,
|
||||||
|
cursor_visible,
|
||||||
|
define_char,
|
||||||
|
delete_character,
|
||||||
|
delete_line,
|
||||||
|
dial_phone,
|
||||||
|
dis_status_line,
|
||||||
|
display_clock,
|
||||||
|
down_half_line,
|
||||||
|
ena_acs,
|
||||||
|
enter_alt_charset_mode,
|
||||||
|
enter_am_mode,
|
||||||
|
enter_blink_mode,
|
||||||
|
enter_bold_mode,
|
||||||
|
enter_ca_mode,
|
||||||
|
enter_delete_mode,
|
||||||
|
enter_dim_mode,
|
||||||
|
enter_doublewide_mode,
|
||||||
|
enter_draft_quality,
|
||||||
|
enter_insert_mode,
|
||||||
|
enter_italics_mode,
|
||||||
|
enter_leftward_mode,
|
||||||
|
enter_micro_mode,
|
||||||
|
enter_near_letter_quality,
|
||||||
|
enter_normal_quality,
|
||||||
|
enter_protected_mode,
|
||||||
|
enter_reverse_mode,
|
||||||
|
enter_secure_mode,
|
||||||
|
enter_shadow_mode,
|
||||||
|
enter_standout_mode,
|
||||||
|
enter_subscript_mode,
|
||||||
|
enter_superscript_mode,
|
||||||
|
enter_underline_mode,
|
||||||
|
enter_upward_mode,
|
||||||
|
enter_xon_mode,
|
||||||
|
erase_chars,
|
||||||
|
exit_alt_charset_mode,
|
||||||
|
exit_am_mode,
|
||||||
|
exit_attribute_mode,
|
||||||
|
exit_ca_mode,
|
||||||
|
exit_delete_mode,
|
||||||
|
exit_doublewide_mode,
|
||||||
|
exit_insert_mode,
|
||||||
|
exit_italics_mode,
|
||||||
|
exit_leftward_mode,
|
||||||
|
exit_micro_mode,
|
||||||
|
exit_shadow_mode,
|
||||||
|
exit_standout_mode,
|
||||||
|
exit_subscript_mode,
|
||||||
|
exit_superscript_mode,
|
||||||
|
exit_underline_mode,
|
||||||
|
exit_upward_mode,
|
||||||
|
exit_xon_mode,
|
||||||
|
fixed_pause,
|
||||||
|
flash_hook,
|
||||||
|
flash_screen,
|
||||||
|
|
||||||
|
// TODO: rest
|
||||||
|
|
||||||
|
pub fn toCapName(self: String) []const u8 {
|
||||||
|
return switch (self) {
|
||||||
|
.acs_chars => "acsc",
|
||||||
|
.back_tab => "cbt",
|
||||||
|
.bell => "bel",
|
||||||
|
.carriage_return => "cr",
|
||||||
|
.change_char_pitch => "cpi",
|
||||||
|
.change_line_pitch => "lpi",
|
||||||
|
.change_res_horz => "chr",
|
||||||
|
.change_res_vert => "cvr",
|
||||||
|
.change_scroll_region => "csr",
|
||||||
|
.char_padding => "rmp",
|
||||||
|
.clear_all_tabs => "tbc",
|
||||||
|
.clear_margins => "mgc",
|
||||||
|
.clear_screen => "clear",
|
||||||
|
.clr_bol => "el1",
|
||||||
|
.clr_eol => "el",
|
||||||
|
.clr_eos => "ed",
|
||||||
|
.column_address => "hpa",
|
||||||
|
.command_character => "cmdch",
|
||||||
|
.create_window => "cwin",
|
||||||
|
.cursor_address => "cup",
|
||||||
|
.cursor_down => "cud1",
|
||||||
|
.cursor_home => "home",
|
||||||
|
.cursor_invisible => "civis",
|
||||||
|
.cursor_left => "cub1",
|
||||||
|
.cursor_mem_address => "mrcup",
|
||||||
|
.cursor_normal => "cnorm",
|
||||||
|
.cursor_right => "cuf1",
|
||||||
|
.cursor_to_ll => "ll",
|
||||||
|
.cursor_up => "cuu1",
|
||||||
|
.cursor_visible => "cvvis",
|
||||||
|
.define_char => "defc",
|
||||||
|
.delete_character => "dch1",
|
||||||
|
.delete_line => "dl1",
|
||||||
|
.dial_phone => "dial",
|
||||||
|
.dis_status_line => "dsl",
|
||||||
|
.display_clock => "dclk",
|
||||||
|
.down_half_line => "hd",
|
||||||
|
.ena_acs => "enacs",
|
||||||
|
.enter_alt_charset_mode => "smacs",
|
||||||
|
.enter_am_mode => "smam",
|
||||||
|
.enter_blink_mode => "blink",
|
||||||
|
.enter_bold_mode => "bold",
|
||||||
|
.enter_ca_mode => "smcup",
|
||||||
|
.enter_delete_mode => "smdc",
|
||||||
|
.enter_dim_mode => "dim",
|
||||||
|
.enter_doublewide_mode => "swidm",
|
||||||
|
.enter_draft_quality => "sdrfq",
|
||||||
|
.enter_insert_mode => "smir",
|
||||||
|
.enter_italics_mode => "sitm",
|
||||||
|
.enter_leftward_mode => "slm",
|
||||||
|
.enter_micro_mode => "smicm",
|
||||||
|
.enter_near_letter_quality => "snlq",
|
||||||
|
.enter_normal_quality => "snrmq",
|
||||||
|
.enter_protected_mode => "prot",
|
||||||
|
.enter_reverse_mode => "rev",
|
||||||
|
.enter_secure_mode => "invis",
|
||||||
|
.enter_shadow_mode => "sshm",
|
||||||
|
.enter_standout_mode => "smso",
|
||||||
|
.enter_subscript_mode => "ssub,",
|
||||||
|
.enter_superscript_mode => "ssupm",
|
||||||
|
.enter_underline_mode => "smul",
|
||||||
|
.enter_upward_mode => "sum",
|
||||||
|
.enter_xon_mode => "smxon",
|
||||||
|
.erase_chars => "ech",
|
||||||
|
.exit_alt_charset_mode => "rmacs",
|
||||||
|
.exit_am_mode => "rmam",
|
||||||
|
.exit_attribute_mode => "sgr0",
|
||||||
|
.exit_ca_mode => "rmcup",
|
||||||
|
.exit_delete_mode => "rmdc",
|
||||||
|
.exit_doublewide_mode => "rwidm",
|
||||||
|
.exit_insert_mode => "rmir",
|
||||||
|
.exit_italics_mode => "ritm",
|
||||||
|
.exit_leftward_mode => "rlm",
|
||||||
|
.exit_micro_mode => "rmicm",
|
||||||
|
.exit_shadow_mode => "rshm",
|
||||||
|
.exit_standout_mode => "rmso",
|
||||||
|
.exit_subscript_mode => "rsubm",
|
||||||
|
.exit_superscript_mode => "rsupm",
|
||||||
|
.exit_underline_mode => "rmul",
|
||||||
|
.exit_upward_mode => "rum",
|
||||||
|
.exit_xon_mode => "rmxon",
|
||||||
|
.fixed_pause => "pause",
|
||||||
|
.flash_hook => "hook",
|
||||||
|
.flash_screen => "flash",
|
||||||
|
// else => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
test "parse terminfo" {
|
test "parse terminfo" {
|
||||||
|
|
Loading…
Add table
Reference in a new issue