commit 9e21474b2a2400fde07b6276f803cab52e863a65 parent e269f5a8edf2893d962b771996069bc4b7ab1693 Author: Martin Ashby <martin@ashbysoft.com> Date: Sat, 20 Jan 2024 08:33:20 +0000 Use the alternate screen buffer feature; It's nicer to restore the user's original terminal Diffstat:
M | src/main.zig | | | 10 | ++++++++++ |
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/main.zig b/src/main.zig @@ -32,6 +32,8 @@ pub fn main() !void { E = &es; es.termios_orig = try enterRawMode(); defer disableRawMode(&es.termios_orig); + try useAlternateScreenBuffer(); + defer exitAlternateScreenBuffer(); defer clearScreen(); try initEditor(&es); @@ -116,6 +118,14 @@ fn disableRawMode(t: *const std.os.linux.termios) void { } } +fn useAlternateScreenBuffer() !void { + try std.io.getStdOut().writer().writeAll("\x1b[?1049h"); +} + +fn exitAlternateScreenBuffer() void { + std.io.getStdOut().writer().writeAll("\x1b[?1049l") catch {}; +} + const editorKey = union(enum) { char: u8, virt: enum {