From 46db4623bca2f06b5afc196965eba6a879462de8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 21 Jun 2022 15:50:44 -0700 Subject: [PATCH] OSC 133;C --- nix/devshell.nix | 1 + src/terminal/osc.zig | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/nix/devshell.nix b/nix/devshell.nix index 8066e1b6b..9846fac88 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -32,6 +32,7 @@ # Testing gdb tracy + vttest ]; buildInputs = [ diff --git a/src/terminal/osc.zig b/src/terminal/osc.zig index 4321edd82..40ff85caf 100644 --- a/src/terminal/osc.zig +++ b/src/terminal/osc.zig @@ -32,6 +32,17 @@ pub const Command = union(enum) { /// or another prompt (OSC "133;P"). prompt_end: void, + /// The OSC "133;C" command can be used to explicitly end + /// the input area and begin the output area. However, some applications + /// don't provide a convenient way to emit that command. + /// That is why we also specify an implicit way to end the input area + /// at the end of the line. In the case of multiple input lines: If the + /// cursor is on a fresh (empty) line and we see either OSC "133;P" or + /// OSC "133;I" then this is the start of a continuation input line. + /// If we see anything else, it is the start of the output area (or end + /// of command). + end_of_input: void, + /// End of current command. /// /// The exit-code need not be specified if if there are no options, @@ -203,6 +214,12 @@ pub const Parser = struct { self.complete = true; }, + 'C' => { + self.state = .semantic_option_start; + self.command = .{ .end_of_input = .{} }; + self.complete = true; + }, + 'D' => { self.state = .semantic_exit_code_start; self.command = .{ .end_of_command = .{} }; @@ -399,6 +416,18 @@ test "OSC: prompt_end" { try testing.expect(cmd == .prompt_end); } +test "OSC: end_of_input" { + const testing = std.testing; + + var p: Parser = .{}; + + const input = "133;C"; + for (input) |ch| p.next(ch); + + const cmd = p.end().?; + try testing.expect(cmd == .end_of_input); +} + test "OSC: reset_cursor_color" { const testing = std.testing;