diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 0c1e121ce..1d5c13b7b 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -83,6 +83,7 @@ modes: packed struct { const Self = @This(); cursor_keys: bool = false, // 1 + insert: bool = false, // 4 reverse_colors: bool = false, // 5, origin: bool = false, // 6 autowrap: bool = true, // 7 @@ -107,7 +108,7 @@ modes: packed struct { // We have this here so that we explicitly fail when we change the // size of modes. The size of modes is NOT particularly important, // we just want to be mentally aware when it happens. - try std.testing.expectEqual(2, @sizeOf(Self)); + try std.testing.expectEqual(4, @sizeOf(Self)); } } = .{}, @@ -689,6 +690,11 @@ pub fn print(self: *Terminal, c: u21) !void { if (self.screen.cursor.pending_wrap and self.modes.autowrap) try self.printWrap(); + // If we have insert mode enabled then we need to handle that. We + // only do insert mode if we're not at the end of the line. + if (self.modes.insert and self.screen.cursor.x + width < self.cols) + self.insertBlanks(width); + switch (width) { // Single cell is very easy: just write in the cell 1 => _ = @call(.always_inline, printCell, .{ self, c }), diff --git a/src/terminal/ansi.zig b/src/terminal/ansi.zig index e7d3f0a52..f7d684018 100644 --- a/src/terminal/ansi.zig +++ b/src/terminal/ansi.zig @@ -62,6 +62,10 @@ pub const Mode = enum(u16) { /// wide. When unset, resizes to 80 columns. @"132_column" = 3, + /// Insert mode. This mode writes a character and pushes all existing + /// characters to the right. The existing contents are never wrapped. + insert = 4, + /// Reverses the foreground and background colors of all cells. reverse_colors = 5, diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 9d135c74b..f4fade723 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -1182,6 +1182,10 @@ const StreamHandler = struct { self.terminal.modes.cursor_keys = enabled; }, + .insert => { + self.terminal.modes.insert = enabled; + }, + .reverse_colors => { self.terminal.modes.reverse_colors = enabled;