[PATCH zig-spoon v2] Add Term.setWindowTitle()
Export this patch
---
v1 -> v2
* fix title in example menu
* flush the writer
* Add doc comment about rendering function
* Fix return value of moveCursorTo(), let me know if you prefer this in an
other commit
example/menu.zig | 1 +
lib/Term.zig | 11 ++++++++++ -
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/example/menu.zig b/example/menu.zig
index d34abef3bd18..bd65e5ab2e5b 100644
--- a/example/menu.zig
@@ -33,6 +33,7 @@ pub fn main() !void {
try term.hideCursor();
try term.fetchSize();
+ try term.setWindowTitle("zig-spoon example: menu");
try term.updateContent();
var buf: [16]u8 = undefined;
diff --git a/lib/Term.zig b/lib/Term.zig
index 467df2024294..497ac026c3bb 100644
--- a/lib/Term.zig
+++ b/lib/Term.zig
@@ -180,10 +180,19 @@ pub fn clear(self: *Self) !void {
try writer.writeAll(spells.clear);
}
+ /// Set window title using OSC 2.
+ /// Should not be called inside a rendering function.
+ pub fn setWindowTitle(self: *Self, title: []const u8) !void {
+ const writer = self.stdout.writer();
+ defer self.stdout.flush() catch {};
+
+ try writer.print("\x1b]2;{s}\x1b\\", .{title});
+ }
+
/// Move the cursor to the specified cell.
pub fn moveCursorTo(self: *Self, row: usize, col: usize) !void {
const writer = self.stdout.writer();
- _ = try writer.print(spells.move_cursor_fmt, .{ row + 1, col + 1 });
+ try writer.print(spells.move_cursor_fmt, .{ row + 1, col + 1 });
}
/// Hide the cursor.
--
2.36.0
zig-spoon/patches/alpine.yml: SUCCESS in 34s
[Add Term.setWindowTitle()][0] v2 from [Hugo Machet][1]
[0]: https://lists.sr.ht/~leon_plickat/public-inbox/patches/31549
[1]: mailto:mail@hmachet.com
✓ #743973 SUCCESS zig-spoon/patches/alpine.yml https://builds.sr.ht/~leon_plickat/job/743973
Final review round!
On Mon Apr 25, 2022 at 12:57 PM CEST, Hugo Machet wrote:
> + try term.setWindowTitle("zig-spoon example: menu");
The input-demo example also deserves a title.
> + try writer.print("\x1b]2;{s}\x1b\\", .{title});
Instead of print, I'd prefer three writer.writeAll() calls.
> - _ = try writer.print(spells.move_cursor_fmt, .{ row + 1, col + 1 });
> + try writer.print(spells.move_cursor_fmt, .{ row + 1, col + 1 });
Probably fits better in a standalone patch.
Friendly greetings,
Leon Henrik Plickat