a modern tui library written in zig
at main 3.0 kB view raw
1const std = @import("std"); 2const builtin = @import("builtin"); 3 4pub const tty = @import("tty.zig"); 5 6pub const Vaxis = @import("Vaxis.zig"); 7 8pub const loop = @import("Loop.zig"); 9pub const Loop = loop.Loop; 10 11pub const zigimg = @import("zigimg"); 12 13pub const Queue = @import("queue.zig").Queue; 14pub const Key = @import("Key.zig"); 15pub const Cell = @import("Cell.zig"); 16pub const Segment = Cell.Segment; 17pub const PrintOptions = Window.PrintOptions; 18pub const Style = Cell.Style; 19pub const Color = Cell.Color; 20pub const Image = @import("Image.zig"); 21pub const Mouse = @import("Mouse.zig"); 22pub const Screen = @import("Screen.zig"); 23pub const AllocatingScreen = @import("InternalScreen.zig"); 24pub const Parser = @import("Parser.zig"); 25pub const Window = @import("Window.zig"); 26pub const widgets = @import("widgets.zig"); 27pub const gwidth = @import("gwidth.zig"); 28pub const ctlseqs = @import("ctlseqs.zig"); 29pub const GraphemeCache = @import("GraphemeCache.zig"); 30pub const Event = @import("event.zig").Event; 31pub const unicode = @import("unicode.zig"); 32 33pub const vxfw = @import("vxfw/vxfw.zig"); 34 35pub const Tty = tty.Tty; 36 37/// The size of the terminal screen 38pub const Winsize = struct { 39 rows: u16, 40 cols: u16, 41 x_pixel: u16, 42 y_pixel: u16, 43}; 44 45/// Initialize a Vaxis application. 46pub fn init(alloc: std.mem.Allocator, opts: Vaxis.Options) !Vaxis { 47 return Vaxis.init(alloc, opts); 48} 49 50pub const Panic = struct { 51 pub const call = panic_handler; 52 pub const sentinelMismatch = std.debug.FormattedPanic.sentinelMismatch; 53 pub const unwrapError = std.debug.FormattedPanic.unwrapError; 54 pub const outOfBounds = std.debug.FormattedPanic.outOfBounds; 55 pub const startGreaterThanEnd = std.debug.FormattedPanic.startGreaterThanEnd; 56 pub const inactiveUnionField = std.debug.FormattedPanic.inactiveUnionField; 57 pub const messages = std.debug.FormattedPanic.messages; 58}; 59 60/// Resets terminal state on a panic, then calls the default zig panic handler 61pub fn panic_handler(msg: []const u8, _: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn { 62 recover(); 63 std.debug.defaultPanic(msg, ret_addr); 64} 65 66/// Resets the terminal state using the global tty instance. Use this only to recover during a panic 67pub fn recover() void { 68 if (tty.global_tty) |*gty| { 69 const reset: []const u8 = ctlseqs.csi_u_pop ++ 70 ctlseqs.mouse_reset ++ 71 ctlseqs.bp_reset ++ 72 ctlseqs.rmcup; 73 74 gty.writer().writeAll(reset) catch {}; 75 gty.writer().flush() catch {}; 76 gty.deinit(); 77 } 78} 79 80pub const log_scopes = enum { 81 vaxis, 82}; 83 84/// the vaxis logo. In PixelCode 85pub const logo = 86 \\▄ ▄ ▄▄▄ ▄ ▄ ▄▄▄ ▄▄▄ 87 \\█ █ █▄▄▄█ ▀▄ ▄▀ █ █ ▀ 88 \\▀▄ ▄▀ █ █ ▄▀▄ █ ▀▀▀▄ 89 \\ ▀▄▀ █ █ █ █ ▄█▄ ▀▄▄▄▀ 90; 91 92test "refAllDecls" { 93 std.testing.refAllDecls(@This()); 94}