diff options
author | Josias <justjosias@tutanota.com> | 2020-04-18 19:39:56 +0300 |
---|---|---|
committer | Josias <justjosias@tutanota.com> | 2020-04-18 19:39:56 +0300 |
commit | 13902695b2c71df2ec7b50f69e4bfb07a4f77775 (patch) | |
tree | a5fd20e2e1e039a8d2e055ea89905807e10c83cd | |
parent | d38173f8b862b47cef5e6b192f61ced7c1d6fee6 (diff) |
Add basic max height/width function
-rw-r--r-- | curses.zig | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -6,7 +6,7 @@ const ascii = std.ascii; const STDIN_FILENO = 0; -// I need to figure out how to implement this +// TODO: make this work //pub fn CTRL_KEY(k: u8) u8 { // return ((k) & 0x1f); //} @@ -29,16 +29,34 @@ const Window = struct { try os.tcsetattr(STDIN_FILENO, os.TCSA.FLUSH, raw); + if (!(os.isatty(STDIN_FILENO))) { + // return error + } + return Window{ .original = original_termios, }; } + pub fn getmax() ![2]i32 { + // TODO: support other platforms and provide fallback + var wsz: os.winsize = undefined; + // TODO: test for false and return error + _ = std.os.linux.syscall3(.ioctl, @bitCast(usize, @as(isize, 0)), os.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; + return [2]i32{wsz.ws_col, wsz.ws_row}; + } + + test "try to get max" { + var hw = try getmax(); + warn("Width: {}. Height: {}\n", .{hw[0], hw[1]}); + } + pub fn end(self: Window) !void { try os.tcsetattr(0, os.TCSA.FLUSH, self.original); } }; + test "Window open and close" { var window = try Window.init(); try window.end(); |