Zaz
A terminal manipulation library for Rust and C/FFI bindings for other languages.
| Rust | Zig |
|---|---|
Features
- Effiecient terminal rendering (Smart Style Caching, Paul Heckel's Diff Algorithm, Cost-based Cursor Movement, etc...)
- SIMD for large screens (work in progress)
- Terminal initialization and screen management
- Cursor positioning and text output
- RGB color support with ANSI escape codes
- Text attributes (bold, italic, underline, etc.)
- Window and panel management
- Keyboard input handling with Kitty keyboard protocol
- Graphics support (Kitty image protocol, Sixel, iTerm2)
- Unicode block mosaic rendering from images
- Scrolling regions
Installation
Rust
Add to your Cargo.toml:
[]
= "*"
Zig
TODO: I will improve this flow eventually.
To use Zaz in your Zig project:
- Build the Zaz library:
- Copy the necessary files to your project:
# or
- In your
build.zig:
const zaz_mod = b.createModule(.{
.root_source_file = b.path("zaz.zig"),
.link_libc = true,
});
zaz_mod.addIncludePath(b.path("."));
const exe = b.addExecutable(.{
.name = "my-app",
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zaz", zaz_mod);
exe.addIncludePath(b.path("."));
exe.addLibraryPath(b.path("."));
exe.linkSystemLibrary("zaz");
exe.linkLibC();
- Run with library path:
# macOS
DYLD_LIBRARY_PATH=.
# Linux
LD_LIBRARY_PATH=.
Usage
Rust Example
use ;
Zig Example
const std = @import("std");
const zaz = @import("zaz");
pub fn main() !void {
const screen = try zaz.Screen.init();
defer screen.deinit() catch {};
try screen.clear();
try screen.mvprint(2, 4, "Hello from Zig + Zaz!");
try screen.setFgColor(255, 200, 0);
try screen.attrOn(.bold);
try screen.mvprint(4, 4, "Colored text!");
try screen.attrOff(.bold);
try screen.refresh();
_ = try screen.getch();
}
C FFI API
The library exports a C-compatible API for use with other languages:
Screen Management
zaz_init()- Initialize screenzaz_endwin()- Clean up and restore terminalzaz_clear()- Clear screenzaz_refresh()- Refresh display
Output
zaz_print()- Print at cursor positionzaz_mvprint()- Print at specific positionzaz_move_cursor()- Move cursor
Colors and Attributes
zaz_set_fg_color()- Set foreground RGB colorzaz_set_bg_color()- Set background RGB colorzaz_attron()- Enable text attributeszaz_attroff()- Disable text attributes
Input
zaz_getch()- Get key input
Utilities
zaz_get_size()- Get terminal dimensionszaz_render_mosaic()- Render image as Unicode artzaz_free_string()- Free mosaic string
License
See LICENSE file for details.