update for zig-0.12.0-2809
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
parent
4a463cfa3a
commit
6418570819
3 changed files with 25 additions and 54 deletions
|
@ -25,7 +25,7 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
const example = b.addExecutable(.{
|
const example = b.addExecutable(.{
|
||||||
.name = "vaxis_pathological_example",
|
.name = "vaxis_pathological_example",
|
||||||
.root_source_file = std.Build.LazyPath.relative("examples/pathological.zig"),
|
.root_source_file = std.Build.LazyPath.relative("examples/text_input.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
76
src/Tty.zig
76
src/Tty.zig
|
@ -13,14 +13,6 @@ 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,
|
||||||
|
|
||||||
|
@ -35,7 +27,7 @@ buffered_writer: BufferedWriter,
|
||||||
/// initializes a Tty instance by opening /dev/tty and "making it raw"
|
/// initializes a Tty instance by opening /dev/tty and "making it raw"
|
||||||
pub fn init() !Tty {
|
pub fn init() !Tty {
|
||||||
// Open our tty
|
// Open our tty
|
||||||
const fd = try os.open("/dev/tty", os.system.O.RDWR, 0);
|
const fd = try os.open("/dev/tty", .{ .ACCMODE = .RDWR }, 0);
|
||||||
|
|
||||||
// Set the termios of the tty
|
// Set the termios of the tty
|
||||||
const termios = try makeRaw(fd);
|
const termios = try makeRaw(fd);
|
||||||
|
@ -230,52 +222,30 @@ pub fn makeRaw(fd: os.fd_t) !os.termios {
|
||||||
const state = try os.tcgetattr(fd);
|
const state = try os.tcgetattr(fd);
|
||||||
var raw = state;
|
var raw = state;
|
||||||
// see termios(3)
|
// see termios(3)
|
||||||
raw.iflag &= ~@as(
|
raw.iflag.IGNBRK = false;
|
||||||
os.tcflag_t,
|
raw.iflag.BRKINT = false;
|
||||||
system.IGNBRK |
|
raw.iflag.ISTRIP = false;
|
||||||
system.BRKINT |
|
raw.iflag.INLCR = false;
|
||||||
system.PARMRK |
|
raw.iflag.IGNCR = false;
|
||||||
system.ISTRIP |
|
raw.iflag.ICRNL = false;
|
||||||
system.INLCR |
|
raw.iflag.IXON = false;
|
||||||
system.IGNCR |
|
|
||||||
system.ICRNL |
|
raw.oflag.OPOST = false;
|
||||||
system.IXON,
|
|
||||||
);
|
raw.lflag.ECHO = false;
|
||||||
raw.oflag &= ~@as(os.tcflag_t, system.OPOST);
|
raw.lflag.ECHONL = false;
|
||||||
raw.lflag &= ~@as(
|
raw.lflag.ICANON = false;
|
||||||
os.tcflag_t,
|
raw.lflag.IEXTEN = false;
|
||||||
system.ECHO |
|
|
||||||
system.ECHONL |
|
raw.cflag.CSIZE = .CS8;
|
||||||
system.ICANON |
|
raw.cflag.PARENB = false;
|
||||||
system.ISIG |
|
|
||||||
system.IEXTEN,
|
raw.cc[@intFromEnum(std.posix.V.MIN)] = 1;
|
||||||
);
|
raw.cc[@intFromEnum(std.posix.V.TIME)] = 0;
|
||||||
raw.cflag &= ~@as(
|
|
||||||
os.tcflag_t,
|
|
||||||
system.CSIZE |
|
|
||||||
system.PARENB,
|
|
||||||
);
|
|
||||||
raw.cflag |= @as(
|
|
||||||
os.tcflag_t,
|
|
||||||
system.CS8,
|
|
||||||
);
|
|
||||||
raw.cc[system.V.MIN] = 1;
|
|
||||||
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) {
|
|
||||||
.linux => 0x5413,
|
|
||||||
.macos => ior(0x40000000, 't', 104, @sizeOf(system.winsize)),
|
|
||||||
else => @compileError("Missing termiosbits for this target, sorry."),
|
|
||||||
};
|
|
||||||
|
|
||||||
const IOCPARM_MASK = 0x1fff;
|
|
||||||
fn ior(inout: u32, group: usize, num: usize, len: usize) usize {
|
|
||||||
return (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The size of the terminal screen
|
/// The size of the terminal screen
|
||||||
pub const Winsize = struct {
|
pub const Winsize = struct {
|
||||||
rows: usize,
|
rows: usize,
|
||||||
|
@ -285,14 +255,14 @@ pub const Winsize = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
fn getWinsize(fd: os.fd_t) !Winsize {
|
fn getWinsize(fd: os.fd_t) !Winsize {
|
||||||
var winsize = system.winsize{
|
var winsize = os.winsize{
|
||||||
.ws_row = 0,
|
.ws_row = 0,
|
||||||
.ws_col = 0,
|
.ws_col = 0,
|
||||||
.ws_xpixel = 0,
|
.ws_xpixel = 0,
|
||||||
.ws_ypixel = 0,
|
.ws_ypixel = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const err = os.system.ioctl(fd, TIOCGWINSZ, @intFromPtr(&winsize));
|
const err = os.system.ioctl(fd, os.T.IOCGWINSZ, @intFromPtr(&winsize));
|
||||||
if (os.errno(err) == .SUCCESS)
|
if (os.errno(err) == .SUCCESS)
|
||||||
return Winsize{
|
return Winsize{
|
||||||
.rows = winsize.ws_row,
|
.rows = winsize.ws_row,
|
||||||
|
|
|
@ -5,6 +5,7 @@ pub const Options = @import("Options.zig");
|
||||||
|
|
||||||
pub const Key = @import("Key.zig");
|
pub const Key = @import("Key.zig");
|
||||||
pub const Cell = @import("Cell.zig");
|
pub const Cell = @import("Cell.zig");
|
||||||
|
pub const Style = Cell.Style;
|
||||||
pub const Image = @import("Image.zig");
|
pub const Image = @import("Image.zig");
|
||||||
pub const Mouse = @import("Mouse.zig");
|
pub const Mouse = @import("Mouse.zig");
|
||||||
pub const Winsize = @import("Tty.zig").Winsize;
|
pub const Winsize = @import("Tty.zig").Winsize;
|
||||||
|
|
Loading…
Reference in a new issue