blob: f657ac836da385fd59124633c61798e84ff3233c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
const system = std.os.system;
const std = @import("std");
const RawMode = @This();
const termios = std.os.termios;
orig: termios,
pub fn init() !RawMode {
const orig = try std.os.tcgetattr(std.os.STDIN_FILENO);
const self = RawMode{ .orig = orig };
errdefer self.deinit();
var raw = orig;
raw.iflag &= ~@as(
system.tcflag_t,
system.BRKINT | system.ICRNL | system.INPCK | system.ISTRIP | system.IXON,
);
raw.lflag &= ~@as(system.tcflag_t, system.ECHO | system.ICANON | system.IEXTEN | system.ISIG);
raw.oflag &= ~@as(system.tcflag_t, system.OPOST);
raw.cflag |= system.CS8;
raw.cc[system.V.MIN] = 0;
raw.cc[system.V.TIME] = 1;
try std.os.tcsetattr(std.os.STDIN_FILENO, .FLUSH, raw);
return self;
}
pub fn deinit(self: RawMode) void {
std.os.tcsetattr(std.os.STDIN_FILENO, .FLUSH, self.orig) catch |err| {
std.log.err("Failed to reset termios: {}", .{err});
};
}
|