DOOM's fire algo, in zig, for 256 color terminals w/no dependencies
0
fork

Configure Feed

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

Merge pull request #6 from marler8997/win32

add win32 support

authored by

const void* and committed by
GitHub
c259c485 fa035dc2

+50 -3
+50 -3
src/main.zig
··· 3 3 // 4 4 // Copy/paste as it helps! 5 5 // 6 + const builtin = @import("builtin"); 6 7 const std = @import("std"); 7 8 const c = @cImport({ 8 - @cInclude("sys/ioctl.h"); 9 + switch (builtin.os.tag) { 10 + .windows => {}, 11 + else => { 12 + @cInclude("sys/ioctl.h"); 13 + }, 14 + } 9 15 }); 10 16 11 17 const allocator = std.heap.page_allocator; 12 18 13 - const stdout = std.io.getStdOut().writer(); 14 - const stdin = std.io.getStdIn().reader(); 19 + var stdout: std.fs.File.Writer = undefined; 20 + var stdin: std.fs.File.Reader = undefined; 15 21 16 22 /////////////////////////////////// 17 23 // Tested on M1 osx12.1 + Artix Linux. ··· 146 152 147 153 //get terminal size given a tty 148 154 pub fn getTermSz(tty: std.os.fd_t) !TermSz { 155 + if (builtin.os.tag == .windows) { 156 + var info: win32.CONSOLE_SCREEN_BUFFER_INFO = undefined; 157 + if (0 == win32.GetConsoleScreenBufferInfo(tty, &info)) switch ( 158 + std.os.windows.kernel32.GetLastError() 159 + ) { 160 + else => |e| return std.os.windows.unexpectedError(e), 161 + }; 162 + return TermSz{ 163 + .height = @intCast(info.srWindow.Bottom - info.srWindow.Top + 1), 164 + .width = @intCast(info.srWindow.Right - info.srWindow.Left + 1), 165 + }; 166 + } 149 167 var winsz = c.winsize{ .ws_col = 0, .ws_row = 0, .ws_xpixel = 0, .ws_ypixel = 0 }; 150 168 const rv = std.os.system.ioctl(tty, TIOCGWINSZ, @intFromPtr(&winsz)); 151 169 const err = std.os.errno(rv); ··· 652 670 /////////////////////////////////// 653 671 654 672 pub fn main() anyerror!void { 673 + stdout = std.io.getStdOut().writer(); 674 + stdin = std.io.getStdIn().reader(); 675 + 655 676 try initTerm(); 656 677 defer complete(); 657 678 ··· 659 680 showTermCap(); 660 681 showDoomFire(); 661 682 } 683 + 684 + const win32 = struct { 685 + pub const BOOL = i32; 686 + pub const HANDLE = std.os.windows.HANDLE; 687 + pub const COORD = extern struct { 688 + X: i16, 689 + Y: i16, 690 + }; 691 + pub const SMALL_RECT = extern struct { 692 + Left: i16, 693 + Top: i16, 694 + Right: i16, 695 + Bottom: i16, 696 + }; 697 + pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct { 698 + dwSize: COORD, 699 + dwCursorPosition: COORD, 700 + wAttributes: u16, 701 + srWindow: SMALL_RECT, 702 + dwMaximumWindowSize: COORD, 703 + }; 704 + pub extern "kernel32" fn GetConsoleScreenBufferInfo( 705 + hConsoleOutput: ?HANDLE, 706 + lpConsoleScreenBufferInfo: ?*CONSOLE_SCREEN_BUFFER_INFO, 707 + ) callconv(std.os.windows.WINAPI) BOOL; 708 + };