diff options
Diffstat (limited to 'src/RawMode.zig')
| -rw-r--r-- | src/RawMode.zig | 19 |
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 @@ | |||
| 1 | const linux = std.os.linux; | 1 | const linux = std.os.linux; |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | const STDIN_FILENO = std.os.STDIN_FILENO; | ||
| 5 | const RawMode = @This(); | 4 | const RawMode = @This(); |
| 6 | const tcflag_t = linux.tcflag_t; | ||
| 7 | const tcgetattr = std.os.tcgetattr; | ||
| 8 | const tcsetattr = std.os.tcsetattr; | ||
| 9 | const termios = std.os.termios; | 5 | const termios = std.os.termios; |
| 10 | 6 | ||
| 11 | orig: termios, | 7 | orig: termios, |
| 12 | 8 | ||
| 13 | pub fn init() !RawMode { | 9 | pub 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 | ||
| 34 | pub fn deinit(self: RawMode) void { | 33 | pub 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 | } |