tty: shadow os.system with our own switch
When linking lib_c, os.system gets overwritten with std.c. The linux implementation of std.c doesn't contain the constants we need. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
parent
927b4120b5
commit
2b8346f691
1 changed files with 29 additions and 21 deletions
50
src/Tty.zig
50
src/Tty.zig
|
@ -16,6 +16,14 @@ const Writer = std.io.Writer(os.fd_t, os.WriteError, os.write);
|
||||||
|
|
||||||
const BufferedWriter = std.io.BufferedWriter(4096, Writer);
|
const BufferedWriter = std.io.BufferedWriter(4096, Writer);
|
||||||
|
|
||||||
|
const system = switch (builtin.os.tag) {
|
||||||
|
.linux => os.linux,
|
||||||
|
.plan9 => os.plan9,
|
||||||
|
.wasi => os.wasi,
|
||||||
|
.uefi => os.uefi,
|
||||||
|
else => std.c,
|
||||||
|
};
|
||||||
|
|
||||||
/// the original state of the terminal, prior to calling makeRaw
|
/// the original state of the terminal, prior to calling makeRaw
|
||||||
termios: os.termios,
|
termios: os.termios,
|
||||||
|
|
||||||
|
@ -227,42 +235,42 @@ pub fn makeRaw(fd: os.fd_t) !os.termios {
|
||||||
// see termios(3)
|
// see termios(3)
|
||||||
raw.iflag &= ~@as(
|
raw.iflag &= ~@as(
|
||||||
os.tcflag_t,
|
os.tcflag_t,
|
||||||
os.system.IGNBRK |
|
system.IGNBRK |
|
||||||
os.system.BRKINT |
|
system.BRKINT |
|
||||||
os.system.PARMRK |
|
system.PARMRK |
|
||||||
os.system.ISTRIP |
|
system.ISTRIP |
|
||||||
os.system.INLCR |
|
system.INLCR |
|
||||||
os.system.IGNCR |
|
system.IGNCR |
|
||||||
os.system.ICRNL |
|
system.ICRNL |
|
||||||
os.system.IXON,
|
system.IXON,
|
||||||
);
|
);
|
||||||
raw.oflag &= ~@as(os.tcflag_t, os.system.OPOST);
|
raw.oflag &= ~@as(os.tcflag_t, system.OPOST);
|
||||||
raw.lflag &= ~@as(
|
raw.lflag &= ~@as(
|
||||||
os.tcflag_t,
|
os.tcflag_t,
|
||||||
os.system.ECHO |
|
system.ECHO |
|
||||||
os.system.ECHONL |
|
system.ECHONL |
|
||||||
os.system.ICANON |
|
system.ICANON |
|
||||||
os.system.ISIG |
|
system.ISIG |
|
||||||
os.system.IEXTEN,
|
system.IEXTEN,
|
||||||
);
|
);
|
||||||
raw.cflag &= ~@as(
|
raw.cflag &= ~@as(
|
||||||
os.tcflag_t,
|
os.tcflag_t,
|
||||||
os.system.CSIZE |
|
system.CSIZE |
|
||||||
os.system.PARENB,
|
system.PARENB,
|
||||||
);
|
);
|
||||||
raw.cflag |= @as(
|
raw.cflag |= @as(
|
||||||
os.tcflag_t,
|
os.tcflag_t,
|
||||||
os.system.CS8,
|
system.CS8,
|
||||||
);
|
);
|
||||||
raw.cc[os.system.V.MIN] = 1;
|
raw.cc[system.V.MIN] = 1;
|
||||||
raw.cc[os.system.V.TIME] = 0;
|
raw.cc[system.V.TIME] = 0;
|
||||||
try os.tcsetattr(fd, .FLUSH, raw);
|
try os.tcsetattr(fd, .FLUSH, raw);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TIOCGWINSZ = switch (builtin.os.tag) {
|
const TIOCGWINSZ = switch (builtin.os.tag) {
|
||||||
.linux => 0x5413,
|
.linux => 0x5413,
|
||||||
.macos => ior(0x40000000, 't', 104, @sizeOf(os.system.winsize)),
|
.macos => ior(0x40000000, 't', 104, @sizeOf(system.winsize)),
|
||||||
else => @compileError("Missing termiosbits for this target, sorry."),
|
else => @compileError("Missing termiosbits for this target, sorry."),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -280,7 +288,7 @@ pub const Winsize = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn getWinsize(fd: os.fd_t) !Winsize {
|
fn getWinsize(fd: os.fd_t) !Winsize {
|
||||||
var winsize = os.system.winsize{
|
var winsize = system.winsize{
|
||||||
.ws_row = 0,
|
.ws_row = 0,
|
||||||
.ws_col = 0,
|
.ws_col = 0,
|
||||||
.ws_xpixel = 0,
|
.ws_xpixel = 0,
|
||||||
|
|
Loading…
Reference in a new issue