~leon_plickat/nfm

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH] Set window title using OSC 2

Details
Message ID
<20220522082400.10662-1-mail@hmachet.com>
DKIM signature
pass
Download raw message
Patch: +25 -0
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
Reply to thread Export thread (mbox)