mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 03:25:50 +00:00
terminal: OSC 133;I
This commit is contained in:
@@ -137,6 +137,7 @@ pub const Cursor = struct {
|
||||
/// The current semantic content type for the cursor that will be
|
||||
/// applied to any newly written cells.
|
||||
semantic_content: pagepkg.Cell.SemanticContent = .output,
|
||||
semantic_content_clear_eol: bool = false,
|
||||
|
||||
/// The pointers into the page list where the cursor is currently
|
||||
/// located. This makes it faster to move the cursor.
|
||||
|
||||
@@ -1082,6 +1082,7 @@ pub fn semanticPrompt(
|
||||
// the prompt types (k=) because it isn't of value to us
|
||||
// currently. This may change in the future.
|
||||
self.screens.active.cursor.semantic_content = .prompt;
|
||||
self.screens.active.cursor.semantic_content_clear_eol = false;
|
||||
|
||||
// This is a kitty-specific flag that notes that the shell
|
||||
// is capable of redraw.
|
||||
@@ -1114,17 +1115,26 @@ pub fn semanticPrompt(
|
||||
|
||||
// As noted above, we don't currently utilize the prompt type.
|
||||
self.screens.active.cursor.semantic_content = .prompt;
|
||||
self.screens.active.cursor.semantic_content_clear_eol = false;
|
||||
},
|
||||
|
||||
.end_prompt_start_input => {
|
||||
// End of prompt and start of user input, terminated by a OSC
|
||||
// "133;C" or another prompt (OSC "133;P").
|
||||
self.screens.active.cursor.semantic_content = .input;
|
||||
self.screens.active.cursor.semantic_content_clear_eol = false;
|
||||
},
|
||||
|
||||
.end_prompt_start_input_terminate_eol => {
|
||||
// End of prompt and start of user input, terminated by end-of-line.
|
||||
self.semanticPromptSet(.input);
|
||||
self.screens.active.cursor.semantic_content_clear_eol = true;
|
||||
},
|
||||
|
||||
.end_input_start_output => {
|
||||
// "End of input, and start of output."
|
||||
self.screens.active.cursor.semantic_content = .output;
|
||||
self.screens.active.cursor.semantic_content_clear_eol = false;
|
||||
},
|
||||
|
||||
.end_command => {
|
||||
@@ -1133,9 +1143,8 @@ pub fn semanticPrompt(
|
||||
// its reasonable at this point to reset our semantic content
|
||||
// state but the spec doesn't really say what to do.
|
||||
self.screens.active.cursor.semantic_content = .output;
|
||||
self.screens.active.cursor.semantic_content_clear_eol = false;
|
||||
},
|
||||
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1295,6 +1304,13 @@ pub fn index(self: *Terminal) !void {
|
||||
// Unset pending wrap state
|
||||
self.screens.active.cursor.pending_wrap = false;
|
||||
|
||||
// Always reset any semantic content clear-eol state
|
||||
if (self.screens.active.cursor.semantic_content_clear_eol) {
|
||||
@branchHint(.unlikely);
|
||||
self.screens.active.cursor.semantic_content = .output;
|
||||
self.screens.active.cursor.semantic_content_clear_eol = false;
|
||||
}
|
||||
|
||||
// Outside of the scroll region we move the cursor one line down.
|
||||
if (self.screens.active.cursor.y < self.scrolling_region.top or
|
||||
self.screens.active.cursor.y > self.scrolling_region.bottom)
|
||||
|
||||
@@ -999,3 +999,19 @@ test "semantic prompt new_command at column zero" {
|
||||
try testing.expectEqual(@as(usize, 0), t.screens.active.cursor.y);
|
||||
try testing.expectEqual(.prompt, t.screens.active.cursor.semantic_content);
|
||||
}
|
||||
|
||||
test "semantic prompt end_prompt_start_input_terminate_eol clears on linefeed" {
|
||||
var t: Terminal = try .init(testing.allocator, .{ .cols = 10, .rows = 10 });
|
||||
defer t.deinit(testing.allocator);
|
||||
|
||||
var s: Stream = .initAlloc(testing.allocator, .init(&t));
|
||||
defer s.deinit();
|
||||
|
||||
// Set input terminated by EOL
|
||||
try s.nextSlice("\x1b]133;I\x07");
|
||||
try testing.expectEqual(.input, t.screens.active.cursor.semantic_content);
|
||||
|
||||
// Linefeed should reset semantic content to output
|
||||
try s.nextSlice("\n");
|
||||
try testing.expectEqual(.output, t.screens.active.cursor.semantic_content);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user