From e4655a4ab42fdf48e80569376dd1bf6a01876050 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 19 Aug 2024 21:48:53 +0200 Subject: [PATCH] feat: add setTerminalWorkingDirectory (OSC7) --- src/Vaxis.zig | 8 ++++++++ src/ctlseqs.zig | 1 + 2 files changed, 9 insertions(+) diff --git a/src/Vaxis.zig b/src/Vaxis.zig index c1dfe0d..eeb6c37 100644 --- a/src/Vaxis.zig +++ b/src/Vaxis.zig @@ -1223,3 +1223,11 @@ pub fn prettyPrint(self: *Vaxis, tty: AnyWriter) !void { } try tty.writeAll("\r\n"); } + +/// Set the terminal's current working directory +pub fn setTerminalWorkingDirectory(_: *Vaxis, tty: AnyWriter, path: []const u8) !void { + if (path.len == 0 or path[0] != '/') + return error.InvalidAbsolutePath; + const hostname = std.posix.getenv("HOSTNAME") orelse "localhost"; + try tty.print(ctlseqs.osc7, .{ hostname, path }); +} diff --git a/src/ctlseqs.zig b/src/ctlseqs.zig index e02163e..ded4883 100644 --- a/src/ctlseqs.zig +++ b/src/ctlseqs.zig @@ -113,6 +113,7 @@ pub const strikethrough_reset = "\x1b[29m"; // OSC sequences pub const osc2_set_title = "\x1b]2;{s}\x1b\\"; +pub const osc7 = "\x1b]7;file://{s}{s}\x1b\\"; pub const osc8 = "\x1b]8;{s};{s}\x1b\\"; pub const osc8_clear = "\x1b]8;;\x1b\\"; pub const osc9_notify = "\x1b]9;{s}\x1b\\";