Skip to content

Commit c0e6ad0

Browse files
authored
Add terminal-related escape codes (#40)
1 parent c36f75d commit c0e6ad0

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/clear.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const std = @import("std");
2-
31
const esc = "\x1B";
42
const csi = esc ++ "[";
53

src/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub const cursor = @import("cursor.zig");
44
pub const clear = @import("clear.zig");
55
pub const style = @import("style.zig");
66
pub const format = @import("format.zig");
7+
pub const terminal = @import("terminal.zig");
78

89
test {
910
std.testing.refAllDeclsRecursive(@This());

src/terminal.zig

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const esc = "\x1B";
2+
const csi = esc ++ "[";
3+
4+
pub fn disableLineWrap(writer: anytype) !void {
5+
try writer.writeAll(csi ++ "?7l");
6+
}
7+
8+
pub fn enableLineWrap(writer: anytype) !void {
9+
try writer.writeAll(csi ++ "?7h");
10+
}
11+
12+
pub fn saveScreen(writer: anytype) !void {
13+
try writer.writeAll(csi ++ "?47h");
14+
}
15+
16+
pub fn restoreScreen(writer: anytype) !void {
17+
try writer.writeAll(csi ++ "?47l");
18+
}
19+
20+
pub fn enterAlternateScreen(writer: anytype) !void {
21+
try writer.writeAll(csi ++ "?1049h");
22+
}
23+
24+
pub fn leaveAlternateScreen(writer: anytype) !void {
25+
try writer.writeAll(csi ++ "?1049l");
26+
}
27+
28+
pub fn setSize(writer: anytype, columns: u16, rows: u16) !void {
29+
try writer.print(csi ++ "8;{d};{d}t", .{ rows, columns });
30+
}
31+
32+
pub fn setTitle(writer: anytype, title: []const u8) !void {
33+
try writer.print(esc ++ "]0;{s}\x07", .{title});
34+
}
35+
36+
pub fn beginSynchronizedUpdate(writer: anytype) !void {
37+
try writer.writeAll(csi ++ "?2026h");
38+
}
39+
40+
pub fn endSynchronizedUpdate(writer: anytype) !void {
41+
try writer.writeAll(csi ++ "?2026l");
42+
}

0 commit comments

Comments
 (0)