this repo has no description
13
fork

Configure Feed

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

tty: make init functions accept buffer parameter

Change PosixTty and WindowsTty init functions to accept a buffer slice
instead of creating a fixed-size buffer internally. This allows callers
to control buffer size and allocation strategy.

The buffer field in both structs is changed from [4096]u8 to []u8,
and the init functions now take a buffer: []u8 parameter that gets
assigned to the struct field.

Amp-Thread-ID: https://ampcode.com/threads/T-1502f393-0cb2-4350-975b-5c6305f60969
Co-authored-by: Amp <amp@ampcode.com>

+8 -8
+8 -8
src/tty.zig
··· 34 34 fd: posix.fd_t, 35 35 36 36 /// Write buffer 37 - buffer: [4096]u8, 37 + buffer: []u8, 38 38 39 39 /// Embedded writer 40 40 writer: std.io.Writer, ··· 85 85 /// initializes a Tty instance by opening /dev/tty and "making it raw". A 86 86 /// signal handler is installed for SIGWINCH. No callbacks are installed, be 87 87 /// sure to register a callback when initializing the event loop 88 - pub fn init() !PosixTty { 88 + pub fn init(buffer: []u8) !PosixTty { 89 89 // Open our tty 90 90 const fd = try posix.open("/dev/tty", .{ .ACCMODE = .RDWR }, 0); 91 91 ··· 106 106 var self: PosixTty = .{ 107 107 .fd = fd, 108 108 .termios = termios, 109 - .buffer = undefined, 109 + .buffer = buffer, 110 110 .writer = undefined, // Will be set after self is created 111 111 }; 112 112 113 113 // Initialize the writer to use our embedded buffer 114 114 self.writer = .{ 115 115 .vtable = &vtable, 116 - .buffer = &self.buffer, 116 + .buffer = self.buffer, 117 117 .end = 0, 118 118 }; 119 119 ··· 268 268 buf: [4]u8 = undefined, 269 269 270 270 /// Write buffer 271 - buffer: [4096]u8, 271 + buffer: []u8, 272 272 273 273 /// Embedded writer 274 274 writer: std.io.Writer, ··· 325 325 .ENABLE_LVB_GRID_WORLDWIDE = 1, // enables reverse video and underline 326 326 }; 327 327 328 - pub fn init() !Tty { 328 + pub fn init(buffer: []u8) !Tty { 329 329 const stdin = std.io.getStdIn().handle; 330 330 const stdout = std.io.getStdOut().handle; 331 331 ··· 346 346 .initial_codepage = initial_output_codepage, 347 347 .initial_input_mode = initial_input_mode, 348 348 .initial_output_mode = initial_output_mode, 349 - .buffer = undefined, 349 + .buffer = buffer, 350 350 .writer = undefined, // Will be set after self is created 351 351 }; 352 352 353 353 // Initialize the writer to use our embedded buffer 354 354 self.writer = .{ 355 355 .vtable = &vtable, 356 - .buffer = &self.buffer, 356 + .buffer = self.buffer, 357 357 .end = 0, 358 358 }; 359 359