mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 19:45:49 +00:00
terminal/osc: semantic prompt 'N'
This commit is contained in:
@@ -8,6 +8,7 @@ const log = std.log.scoped(.osc_semantic_prompt);
|
||||
pub const Command = union(enum) {
|
||||
fresh_line,
|
||||
fresh_line_new_prompt: Options,
|
||||
new_command: Options,
|
||||
prompt_start: Options,
|
||||
};
|
||||
|
||||
@@ -104,6 +105,14 @@ pub fn parse(parser: *Parser, _: ?u8) ?*OSCCommand {
|
||||
parser.command = .{ .semantic_prompt = .fresh_line };
|
||||
},
|
||||
|
||||
'N' => new_command: {
|
||||
parser.command = .{ .semantic_prompt = .{ .new_command = .init } };
|
||||
if (data.len == 1) break :new_command;
|
||||
if (data[1] != ';') break :valid;
|
||||
var it = KVIterator.init(writer) catch break :valid;
|
||||
parser.command.semantic_prompt.new_command.parse(&it);
|
||||
},
|
||||
|
||||
'P' => prompt_start: {
|
||||
parser.command = .{ .semantic_prompt = .{ .prompt_start = .init } };
|
||||
if (data.len == 1) break :prompt_start;
|
||||
@@ -450,3 +459,70 @@ test "OSC 133: prompt_start extra contents" {
|
||||
for (input) |ch| p.next(ch);
|
||||
try testing.expect(p.end(null) == null);
|
||||
}
|
||||
|
||||
test "OSC 133: new_command" {
|
||||
const testing = std.testing;
|
||||
|
||||
var p: Parser = .init(null);
|
||||
|
||||
const input = "133;N";
|
||||
for (input) |ch| p.next(ch);
|
||||
|
||||
const cmd = p.end(null).?.*;
|
||||
try testing.expect(cmd == .semantic_prompt);
|
||||
try testing.expect(cmd.semantic_prompt == .new_command);
|
||||
try testing.expect(cmd.semantic_prompt.new_command.aid == null);
|
||||
try testing.expect(cmd.semantic_prompt.new_command.cl == null);
|
||||
}
|
||||
|
||||
test "OSC 133: new_command with aid" {
|
||||
const testing = std.testing;
|
||||
|
||||
var p: Parser = .init(null);
|
||||
|
||||
const input = "133;N;aid=foo";
|
||||
for (input) |ch| p.next(ch);
|
||||
|
||||
const cmd = p.end(null).?.*;
|
||||
try testing.expect(cmd == .semantic_prompt);
|
||||
try testing.expect(cmd.semantic_prompt == .new_command);
|
||||
try testing.expectEqualStrings("foo", cmd.semantic_prompt.new_command.aid.?);
|
||||
}
|
||||
|
||||
test "OSC 133: new_command with cl=line" {
|
||||
const testing = std.testing;
|
||||
|
||||
var p: Parser = .init(null);
|
||||
|
||||
const input = "133;N;cl=line";
|
||||
for (input) |ch| p.next(ch);
|
||||
|
||||
const cmd = p.end(null).?.*;
|
||||
try testing.expect(cmd == .semantic_prompt);
|
||||
try testing.expect(cmd.semantic_prompt == .new_command);
|
||||
try testing.expect(cmd.semantic_prompt.new_command.cl == .line);
|
||||
}
|
||||
|
||||
test "OSC 133: new_command with multiple options" {
|
||||
const testing = std.testing;
|
||||
|
||||
var p: Parser = .init(null);
|
||||
|
||||
const input = "133;N;aid=foo;cl=line";
|
||||
for (input) |ch| p.next(ch);
|
||||
|
||||
const cmd = p.end(null).?.*;
|
||||
try testing.expect(cmd == .semantic_prompt);
|
||||
try testing.expect(cmd.semantic_prompt == .new_command);
|
||||
try testing.expectEqualStrings("foo", cmd.semantic_prompt.new_command.aid.?);
|
||||
try testing.expect(cmd.semantic_prompt.new_command.cl == .line);
|
||||
}
|
||||
|
||||
test "OSC 133: new_command extra contents" {
|
||||
const testing = std.testing;
|
||||
|
||||
var p: Parser = .init(null);
|
||||
const input = "133;Nextra";
|
||||
for (input) |ch| p.next(ch);
|
||||
try testing.expect(p.end(null) == null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user