terminal: stream handles new SemanticPrompt type

This commit is contained in:
Mitchell Hashimoto
2026-01-23 14:09:24 -08:00
parent edafe86203
commit 9f2808ce40
4 changed files with 87 additions and 3 deletions

View File

@@ -325,6 +325,7 @@ pub const StreamHandler = struct {
.prompt_start => self.promptStart(value.aid, value.redraw),
.prompt_continuation => self.promptContinuation(value.aid),
.end_of_command => self.endOfCommand(value.exit_code),
.semantic_prompt => self.semanticPrompt(value),
.mouse_shape => try self.setMouseShape(value),
.configure_charset => self.configureCharset(value.slot, value.charset),
.set_attribute => {
@@ -1094,6 +1095,48 @@ pub const StreamHandler = struct {
self.surfaceMessageWriter(.{ .stop_command = exit_code });
}
fn semanticPrompt(
self: *StreamHandler,
cmd: Stream.Action.SemanticPrompt,
) void {
switch (cmd.action) {
.fresh_line => {
if (self.terminal.screens.active.cursor.x != 0) {
self.terminal.carriageReturn();
self.terminal.index() catch {};
}
},
.fresh_line_new_prompt => {
if (self.terminal.screens.active.cursor.x != 0) {
self.terminal.carriageReturn();
self.terminal.index() catch {};
}
self.promptStart(cmd.options.aid, false);
},
.new_command => {},
.prompt_start => {
const kind = cmd.options.prompt_kind orelse .initial;
switch (kind) {
.initial, .right => self.promptStart(cmd.options.aid, false),
.continuation, .secondary => self.promptContinuation(cmd.options.aid),
}
},
.end_prompt_start_input => self.terminal.markSemanticPrompt(.input),
.end_prompt_start_input_terminate_eol => self.terminal.markSemanticPrompt(.input),
.end_input_start_output => {
self.terminal.markSemanticPrompt(.command);
self.surfaceMessageWriter(.start_command);
},
.end_command => {
const exit_code: ?u8 = if (cmd.options.exit_code) |code|
if (code >= 0 and code <= 255) @intCast(code) else null
else
null;
self.surfaceMessageWriter(.{ .stop_command = exit_code });
},
}
}
fn reportPwd(self: *StreamHandler, url: []const u8) !void {
// Special handling for the empty URL. We treat the empty URL
// as resetting the pwd as if we never saw a pwd. I can't find any