diff --git a/README.md b/README.md index 3527e73..303f2de 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ features is detected through terminal queries. Contributions are welcome. +Vaxis tracks zig `master`. Vaxis is currently compatible with zig version +`0.12.0-dev.3397+43edd53c3`. When `0.12.0` is released, a release will be tagged +against it. + ## Feature comparison | Feature | Vaxis | libvaxis | notcurses | @@ -51,8 +55,6 @@ const Cell = vaxis.Cell; const TextInput = vaxis.widgets.TextInput; const border = vaxis.widgets.border; -const log = std.log.scoped(.main); - // This can contain internal events as well as Vaxis events. // Internal events can be posted into the same queue as vaxis events to allow // for a single event loop with exhaustive switching. Booya @@ -151,17 +153,26 @@ pub fn main() !void { // vaxis double buffers the screen. This new frame will be compared to // the old and only updated cells will be drawn win.clear(); - const child = win.initChild( - win.width / 2 - 20, - win.height / 2 - 3, - .{ .limit = 40 }, - .{ .limit = 3 }, - ); - // draw the text_input using a bordered window + + // Create a style const style: vaxis.Style = .{ .fg = .{ .index = color_idx }, }; - text_input.draw(border.all(child, style)); + + // Create a bordered child window + const child = win.child(.{ + .x_off = win.width / 2 - 20, + .y_off = win.height / 2 - 3, + .width = .{ .limit = 40 }, + .height = .{ .limit = 3 }, + .border = .{ + .where = .all, + .style = .{ .fg = .index = color_idx }, + }, + }) + + // Draw the text_input in the child window + text_input.draw(child); // Render the screen try vx.render(); diff --git a/src/Tty.zig b/src/Tty.zig index ee667b9..13da20d 100644 --- a/src/Tty.zig +++ b/src/Tty.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const os = std.os; +const posix = std.posix; const Vaxis = @import("vaxis.zig").Vaxis; const Parser = @import("Parser.zig"); const GraphemeCache = @import("GraphemeCache.zig"); @@ -10,15 +10,15 @@ const log = std.log.scoped(.tty); const Tty = @This(); -const Writer = std.io.Writer(os.fd_t, os.WriteError, os.write); +const Writer = std.io.Writer(posix.fd_t, posix.WriteError, posix.write); const BufferedWriter = std.io.BufferedWriter(4096, Writer); /// the original state of the terminal, prior to calling makeRaw -termios: os.termios, +termios: posix.termios, /// The file descriptor we are using for I/O -fd: os.fd_t, +fd: posix.fd_t, should_quit: bool = false, @@ -27,7 +27,7 @@ buffered_writer: BufferedWriter, /// initializes a Tty instance by opening /dev/tty and "making it raw" pub fn init() !Tty { // Open our tty - const fd = try os.open("/dev/tty", .{ .ACCMODE = .RDWR }, 0); + const fd = try posix.open("/dev/tty", .{ .ACCMODE = .RDWR }, 0); // Set the termios of the tty const termios = try makeRaw(fd); @@ -41,16 +41,16 @@ pub fn init() !Tty { /// release resources associated with the Tty return it to its original state pub fn deinit(self: *Tty) void { - os.tcsetattr(self.fd, .FLUSH, self.termios) catch |err| { + posix.tcsetattr(self.fd, .FLUSH, self.termios) catch |err| { log.err("couldn't restore terminal: {}", .{err}); }; - os.close(self.fd); + posix.close(self.fd); } /// stops the run loop pub fn stop(self: *Tty) void { self.should_quit = true; - _ = std.os.write(self.fd, ctlseqs.device_status_report) catch {}; + _ = posix.write(self.fd, ctlseqs.device_status_report) catch {}; } /// read input from the tty @@ -73,22 +73,22 @@ pub fn run( const Self = @This(); var vx_winch: *Vaxis(Event) = undefined; - var fd: os.fd_t = undefined; + var fd: posix.fd_t = undefined; - fn init(vx_arg: *Vaxis(Event), fd_arg: os.fd_t) !void { + fn init(vx_arg: *Vaxis(Event), fd_arg: posix.fd_t) !void { vx_winch = vx_arg; fd = fd_arg; - var act = os.Sigaction{ + var act = posix.Sigaction{ .handler = .{ .handler = Self.handleWinch }, .mask = switch (builtin.os.tag) { .macos => 0, - .linux => std.os.empty_sigset, + .linux => posix.empty_sigset, else => @compileError("os not supported"), }, .flags = 0, }; - try os.sigaction(os.SIG.WINCH, &act, null); + try posix.sigaction(posix.SIG.WINCH, &act, null); } fn handleWinch(_: c_int) callconv(.C) void { @@ -111,7 +111,7 @@ pub fn run( var buf: [1024]u8 = undefined; // read loop while (!self.should_quit) { - const n = try os.read(self.fd, &buf); + const n = try posix.read(self.fd, &buf); var start: usize = 0; while (start < n) { const result = try parser.parse(buf[start..n]); @@ -198,8 +198,8 @@ pub fn flush(self: *Tty) !void { } /// makeRaw enters the raw state for the terminal. -pub fn makeRaw(fd: os.fd_t) !os.termios { - const state = try os.tcgetattr(fd); +pub fn makeRaw(fd: posix.fd_t) !posix.termios { + const state = try posix.tcgetattr(fd); var raw = state; // see termios(3) raw.iflag.IGNBRK = false; @@ -222,9 +222,9 @@ pub fn makeRaw(fd: os.fd_t) !os.termios { raw.cflag.CSIZE = .CS8; raw.cflag.PARENB = false; - raw.cc[@intFromEnum(std.posix.V.MIN)] = 1; - raw.cc[@intFromEnum(std.posix.V.TIME)] = 0; - try os.tcsetattr(fd, .FLUSH, raw); + raw.cc[@intFromEnum(posix.V.MIN)] = 1; + raw.cc[@intFromEnum(posix.V.TIME)] = 0; + try posix.tcsetattr(fd, .FLUSH, raw); return state; } @@ -236,16 +236,16 @@ pub const Winsize = struct { y_pixel: usize, }; -fn getWinsize(fd: os.fd_t) !Winsize { - var winsize = os.winsize{ +fn getWinsize(fd: posix.fd_t) !Winsize { + var winsize = posix.winsize{ .ws_row = 0, .ws_col = 0, .ws_xpixel = 0, .ws_ypixel = 0, }; - const err = os.system.ioctl(fd, os.T.IOCGWINSZ, @intFromPtr(&winsize)); - if (os.errno(err) == .SUCCESS) + const err = posix.system.ioctl(fd, posix.T.IOCGWINSZ, @intFromPtr(&winsize)); + if (posix.errno(err) == .SUCCESS) return Winsize{ .rows = winsize.ws_row, .cols = winsize.ws_col, diff --git a/src/vaxis.zig b/src/vaxis.zig index 6a70b44..a5e1c0f 100644 --- a/src/vaxis.zig +++ b/src/vaxis.zig @@ -225,7 +225,7 @@ pub fn Vaxis(comptime T: type) type { pub fn queryTerminal(self: *Self) !void { var tty = self.tty orelse return; - const colorterm = std.os.getenv("COLORTERM") orelse ""; + const colorterm = std.posix.getenv("COLORTERM") orelse ""; if (std.mem.eql(u8, colorterm, "truecolor") or std.mem.eql(u8, colorterm, "24bit")) {