pub const Colors = @import("colors.zig"); const std = @import("std"); const c = @cImport({ @cInclude("flanterm.h"); @cInclude("flanterm_backends/fb.h"); }); pub const Context = struct { backing: ?*c.struct_flanterm_context, const Self = @This(); /// Initialize the context pub fn init( args: struct { // Malloc and Free malloc: ?*const fn (usize) callconv(.c) ?*anyopaque = null, free: ?*const fn (?*anyopaque, usize) callconv(.c) void = null, // Framebuffer Info (required) fb: [*]u32, width: usize, height: usize, pitch: usize, // Framebuffer Color Info red_mask_size: u8, red_mask_shift: u8, green_mask_size: u8, green_mask_shift: u8, blue_mask_size: u8, blue_mask_shift: u8, // Canvas (scratch space) canvas: ?[*]u32 = null, // Color Pointers ansi_colours: *Colors.Palette = &Colors.default_colors, ansi_bright_colours: *Colors.Palette = &Colors.default_bold_colors, // Default Color choices default_bg: *u32 = &Colors.default_colors.black, default_fg: *u32 = &Colors.default_colors.cyan, default_bg_bright: *u32 = &Colors.default_bold_colors.black, default_fg_bright: *u32 = &Colors.default_bold_colors.cyan, // Font Information font: ?*anyopaque = null, font_width: usize = 0, font_height: usize = 0, font_spacing: usize = 1, // Font Scale values font_scale_x: usize = 0, font_scale_y: usize = 0, // Margin margin: usize = 0, }, ) Self { const ansi_colours: [*]u32 = @ptrCast(args.ansi_colours); const ansi_bright_colours: [*]u32 = @ptrCast(args.ansi_bright_colours); const ctx = c.flanterm_fb_init( args.malloc, args.free, args.fb, args.width, args.height, args.pitch, args.red_mask_size, args.red_mask_shift, args.green_mask_size, args.green_mask_shift, args.blue_mask_size, args.blue_mask_shift, args.canvas, ansi_colours, ansi_bright_colours, args.default_bg, args.default_fg, args.default_bg_bright, args.default_fg_bright, args.font, args.font_width, args.font_height, args.font_spacing, args.font_scale_x, args.font_scale_y, args.margin, ); return .{ .backing = ctx, }; } /// Write to the console pub fn write_slice(self: *Self, buf: []u8) void { c.flanterm_write(self.backing, buf.ptr, buf.len); } };