90 lines
2.1 KiB
Zig
90 lines
2.1 KiB
Zig
// SPDX-License-Identifier: LCL-1.0
|
|
// Copyright (c) 2026 Markus Maiwald
|
|
// Stewardship: Self Sovereign Society Foundation
|
|
//
|
|
// This file is part of the Nexus Commonwealth.
|
|
// See legal/LICENSE_COMMONWEALTH.md for license terms.
|
|
|
|
//! Rumpk HAL: HUD TUI Utilities
|
|
//!
|
|
//! Provides minimal ANSI escape code utilities for the NexShell HUD.
|
|
//! Used for basic TUI elements like boxes and color management.
|
|
//!
|
|
//! SAFETY: All operations are synchronous and communicate via UART.
|
|
|
|
const uart = @import("uart.zig");
|
|
|
|
pub const ESC = "\x1b[";
|
|
pub const CLEAR = "\x1b[2J\x1b[H";
|
|
pub const HIDE_CURSOR = "\x1b[?25l";
|
|
pub const SHOW_CURSOR = "\x1b[?25h";
|
|
|
|
pub fn move_to(row: u8, col: u8) void {
|
|
uart.print(ESC);
|
|
print_u8(row);
|
|
uart.print(";");
|
|
print_u8(col);
|
|
// Heartbeat removed
|
|
}
|
|
|
|
pub fn set_color(code: u8) void {
|
|
uart.print(ESC);
|
|
print_u8(code);
|
|
uart.print("m");
|
|
}
|
|
|
|
pub fn reset_color() void {
|
|
uart.print("\x1b[0m");
|
|
}
|
|
|
|
pub fn draw_box(x: u8, y: u8, w: u8, h: u8, title: []const u8) void {
|
|
// Basic ASCII/ANSI box
|
|
move_to(y, x);
|
|
uart.print("┌");
|
|
var i: u8 = 0;
|
|
while (i < w - 2) : (i += 1) uart.print("─");
|
|
uart.print("┐");
|
|
|
|
i = 1;
|
|
while (i < h - 1) : (i += 1) {
|
|
move_to(y + i, x);
|
|
uart.print("│");
|
|
move_to(y + i, x + w - 1);
|
|
uart.print("│");
|
|
}
|
|
|
|
move_to(y + h - 1, x);
|
|
uart.print("└");
|
|
i = 0;
|
|
while (i < w - 2) : (i += 1) uart.print("─");
|
|
uart.print("┘");
|
|
|
|
if (title.len > 0) {
|
|
move_to(y, x + 2);
|
|
uart.print("[ ");
|
|
uart.print(title);
|
|
uart.print(" ]");
|
|
}
|
|
}
|
|
|
|
// Helper to print u8 as text without full fmt
|
|
fn print_u8(n: u8) void {
|
|
if (n == 0) {
|
|
uart.print("0");
|
|
return;
|
|
}
|
|
// SAFETY(HUD): Local buffer is immediately populated by the while loop.
|
|
var buf: [3]u8 = undefined;
|
|
var i: u8 = 0;
|
|
var val = n;
|
|
while (val > 0) {
|
|
buf[i] = @as(u8, @intCast(val % 10)) + '0';
|
|
val /= 10;
|
|
i += 1;
|
|
}
|
|
while (i > 0) {
|
|
i -= 1;
|
|
uart.putc(buf[i]);
|
|
}
|
|
}
|