~leon_plickat/nfm

Set window title using OSC 2 v1 PROPOSED

Hugo Machet: 1
 Set window title using OSC 2

 2 files changed, 25 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~leon_plickat/nfm/patches/32433/mbox | git am -3
Learn more about email & git

[PATCH] Set window title using OSC 2 Export this patch

Views title:
  * nav => "nfm: $CWD"
  * bm, fs => "nfm: <view name>"
---
 src/nfm.zig  | 22 ++++++++++++++++++++++
 src/view.zig |  3 +++
 2 files changed, 25 insertions(+)

diff --git a/src/nfm.zig b/src/nfm.zig
index d978210d4f9f..27dd0357870e 100644
--- a/src/nfm.zig
+++ b/src/nfm.zig
@@ -129,10 +129,32 @@ pub const Context = struct {
            }
        }

        try self.updateWindowTitle();

        self.ui.list_dirty = true;
        self.ui.title_dirty = true;
    }

    pub fn updateWindowTitle(self: *Context) !void {
        switch (self.view) {
            .nav => {
                var buf: [100]u8 = undefined;
                const title = blk: {
                    break :blk fmt.bufPrint(&buf, "nfm: {s}", .{self.cwd.name}) catch {
                        break :blk try fmt.bufPrint(
                            &buf,
                            "nfm: {s}",
                            .{self.cwd.name[0 .. buf.len - 5]},
                        );
                    };
                };
                try self.ui.term.setWindowTitle(title);
            },
            .fs => try self.ui.term.setWindowTitle("nfm: Filesystem"),
            .bm => try self.ui.term.setWindowTitle("nfm: Bookmarks"),
        }
    }

    pub fn runU21(self: *Context, command: []const u21, comptime name: []const u8) !void {
        const cmd = try util.codepointSliceToUtf8SlizeZAlloc(self.gpa, command);
        defer self.gpa.free(cmd);
diff --git a/src/view.zig b/src/view.zig
index ef6172ed0189..f13f38efbdf3 100644
--- a/src/view.zig
+++ b/src/view.zig
@@ -42,6 +42,7 @@ pub const View = union(enum) {
    pub fn setNav(self: *Self) void {
        self.reset();
        self.* = .nav;
        context.updateWindowTitle() catch return;
    }

    pub fn setFs(self: *Self) !void {
@@ -51,11 +52,13 @@ pub const View = union(enum) {
            .cursor = 0,
            .scrolloff = 0,
        } };
        try context.updateWindowTitle();
    }

    pub fn setBm(self: *Self) void {
        self.reset();
        self.* = .bm;
        context.updateWindowTitle() catch return;
    }

    fn reset(self: *Self) void {
-- 
2.36.1