Skip to content

Latest commit

 

History

History
68 lines (58 loc) · 1.79 KB

README.md

File metadata and controls

68 lines (58 loc) · 1.79 KB

Terminal utilities

wakatime

Install

zig fetch --save https://github.com/Mostik/terminal/archive/v0.0.2.tar.gz
//build.zig
const terminal = b.dependency("terminal", .{}).module("terminal");

exe.root_module.addImport("terminal", terminal);
const std = @import("std");
const terminal = @import("terminal");

pub fn main() !void {
    ...
}

ANSI Colors

image

const std = @import("std");
const Color = @import("terminal").Color;

pub fn main() !void {
    const mystring = std.fmt.comptimePrint("{s} My text {s}", .{
        Color(null).underline(),
        Color(null).reset(),
    });
    std.debug.print("{s}\n", .{mystring});

    std.debug.print("{s}{s}\n", .{ Color(.fg).bit(3), "0-7" });
    std.debug.print("{s}{s}\n", .{ Color(.fg).byte(213), "0-255" });
    std.debug.print("{s}{s}\n", .{ Color(.fg).rgb(255, 255, 255), "rgb" });
    std.debug.print("{s}{s}\n", .{ Color(.fg).hex(0xab23f2), "hex" });
    std.debug.print("{s}{s}\n", .{ Color(.fg).enm(.red), "Colors.0-7" });
}

Terminal Size

std.debug.print("{any}", .{terminal.size()});
// Size{ .rows = 47, .columns = 95, .x_pixels = 950, .y_pixels = 987 }

Cursor Position

const row = 10;
const col = 10;
try terminal.cursorPos(row, col);

getch

const std = @import("std");
const terminal = @import("terminal");

pub fn main() !void {
    while (true) {
        const ch: u8 = try terminal.getch();

        std.debug.print("{any}", .{ch});
    }
}