this repo has no description
13
fork

Configure Feed

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

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