mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
Merge pull request #235 from mitchellh/insert-mode
terminal: implement insert mode (mode = 4)
This commit is contained in:
@ -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 }),
|
||||
|
@ -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,
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user