this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 01605eebf65be21caa85ee9d840047f864553308 72 lines 1.9 kB view raw
1const std = @import("std"); 2const assert = std.debug.assert; 3 4const Cell = @import("Cell.zig"); 5const Shape = @import("Mouse.zig").Shape; 6const Image = @import("Image.zig"); 7const Winsize = @import("main.zig").Winsize; 8const Unicode = @import("Unicode.zig"); 9const Method = @import("gwidth.zig").Method; 10 11const Screen = @This(); 12 13width: u16 = 0, 14height: u16 = 0, 15 16width_pix: u16 = 0, 17height_pix: u16 = 0, 18 19buf: []Cell = &.{}, 20 21cursor_row: u16 = 0, 22cursor_col: u16 = 0, 23cursor_vis: bool = false, 24 25unicode: *const Unicode = undefined, 26 27width_method: Method = .wcwidth, 28 29mouse_shape: Shape = .default, 30cursor_shape: Cell.CursorShape = .default, 31 32pub fn init(alloc: std.mem.Allocator, winsize: Winsize, unicode: *const Unicode) std.mem.Allocator.Error!Screen { 33 const w = winsize.cols; 34 const h = winsize.rows; 35 const self = Screen{ 36 .buf = try alloc.alloc(Cell, @as(usize, @intCast(w)) * h), 37 .width = w, 38 .height = h, 39 .width_pix = winsize.x_pixel, 40 .height_pix = winsize.y_pixel, 41 .unicode = unicode, 42 }; 43 const base_cell: Cell = .{}; 44 @memset(self.buf, base_cell); 45 return self; 46} 47pub fn deinit(self: *Screen, alloc: std.mem.Allocator) void { 48 alloc.free(self.buf); 49} 50 51/// writes a cell to a location. 0 indexed 52pub fn writeCell(self: *Screen, col: u16, row: u16, cell: Cell) void { 53 if (col >= self.width or 54 row >= self.height) 55 return; 56 const i = (@as(usize, @intCast(row)) * self.width) + col; 57 assert(i < self.buf.len); 58 self.buf[i] = cell; 59} 60 61pub fn readCell(self: *const Screen, col: u16, row: u16) ?Cell { 62 if (col >= self.width or 63 row >= self.height) 64 return null; 65 const i = (@as(usize, @intCast(row)) * self.width) + col; 66 assert(i < self.buf.len); 67 return self.buf[i]; 68} 69 70test "refAllDecls" { 71 std.testing.refAllDecls(@This()); 72}