summaryrefslogtreecommitdiff
path: root/src/RawMode.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/RawMode.zig')
-rw-r--r--src/RawMode.zig19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/RawMode.zig b/src/RawMode.zig
index ed71819..7298922 100644
--- a/src/RawMode.zig
+++ b/src/RawMode.zig
@@ -1,38 +1,37 @@
1const linux = std.os.linux; 1const linux = std.os.linux;
2const std = @import("std"); 2const std = @import("std");
3 3
4const STDIN_FILENO = std.os.STDIN_FILENO;
5const RawMode = @This(); 4const RawMode = @This();
6const tcflag_t = linux.tcflag_t;
7const tcgetattr = std.os.tcgetattr;
8const tcsetattr = std.os.tcsetattr;
9const termios = std.os.termios; 5const termios = std.os.termios;
10 6
11orig: termios, 7orig: termios,
12 8
13pub fn init() !RawMode { 9pub fn init() !RawMode {
14 const orig = try tcgetattr(STDIN_FILENO); 10 const orig = try std.os.tcgetattr(std.os.STDIN_FILENO);
15 const self = RawMode{ .orig = orig }; 11 const self = RawMode{ .orig = orig };
16 errdefer self.deinit(); 12 errdefer self.deinit();
17 13
18 var raw = orig; 14 var raw = orig;
19 15
20 raw.iflag &= ~@as(tcflag_t, linux.BRKINT | linux.ICRNL | linux.INPCK | linux.ISTRIP | linux.IXON); 16 raw.iflag &= ~@as(
21 raw.lflag &= ~@as(tcflag_t, linux.ECHO | linux.ICANON | linux.IEXTEN | linux.ISIG); 17 linux.tcflag_t,
22 raw.oflag &= ~@as(tcflag_t, linux.OPOST); 18 linux.BRKINT | linux.ICRNL | linux.INPCK | linux.ISTRIP | linux.IXON,
19 );
20 raw.lflag &= ~@as(linux.tcflag_t, linux.ECHO | linux.ICANON | linux.IEXTEN | linux.ISIG);
21 raw.oflag &= ~@as(linux.tcflag_t, linux.OPOST);
23 22
24 raw.cflag |= linux.CS8; 23 raw.cflag |= linux.CS8;
25 24
26 raw.cc[linux.V.MIN] = 0; 25 raw.cc[linux.V.MIN] = 0;
27 raw.cc[linux.V.TIME] = 1; 26 raw.cc[linux.V.TIME] = 1;
28 27
29 try tcsetattr(STDIN_FILENO, .FLUSH, raw); 28 try std.os.tcsetattr(std.os.STDIN_FILENO, .FLUSH, raw);
30 29
31 return self; 30 return self;
32} 31}
33 32
34pub fn deinit(self: RawMode) void { 33pub fn deinit(self: RawMode) void {
35 tcsetattr(STDIN_FILENO, .FLUSH, self.orig) catch |err| { 34 std.os.tcsetattr(std.os.STDIN_FILENO, .FLUSH, self.orig) catch |err| {
36 std.log.err("Failed to reset termios: {}", .{err}); 35 std.log.err("Failed to reset termios: {}", .{err});
37 }; 36 };
38} 37}