https://github.com/joachimschmidt557/zig-termbox
A termbox implementation in zig
https://github.com/joachimschmidt557/zig-termbox
zig zig-package
Last synced: about 1 year ago
JSON representation
A termbox implementation in zig
- Host: GitHub
- URL: https://github.com/joachimschmidt557/zig-termbox
- Owner: joachimschmidt557
- License: mit
- Created: 2020-01-30T13:48:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-08T20:23:47.000Z (almost 2 years ago)
- Last Synced: 2025-02-23T17:44:23.266Z (over 1 year ago)
- Topics: zig, zig-package
- Language: Zig
- Homepage:
- Size: 54.7 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zig-termbox
termbox-inspired library for creating terminal user interfaces
Works with Zig 0.14.0.
## Concepts
`termbox` is a *double-buffered* terminal library. This means that
when you call functions to draw on the screen, you are not actually
sending data to the terminal, but instead act on an intermediate data
structure called the *back buffer*. Only when you call
`Termbox.present`, the terminal is actually updated to reflect the
state of the *back buffer*.
An advantage of this design is that repeated calls to
`Termbox.present` only update the parts of the terminal interface that
have actually changed since the last call. `termbox` achieves this by
tracking the current state of the terminal in the internal *front
buffer*.
## Examples
```zig
const std = @import("std");
const termbox = @import("termbox");
const Termbox = termbox.Termbox;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var t = try Termbox.init(allocator);
defer t.shutdown() catch {};
var anchor = t.back_buffer.anchor(1, 1);
try anchor.writer().print("Hello {s}!", .{"World"});
anchor.move(1, 2);
try anchor.writer().print("Press any key to quit", .{});
try t.present();
_ = try t.pollEvent();
}
```
Further examples can be found in the `examples` subdirectory.