https://github.com/mostik/terminal
Terminal tools written in Zig
https://github.com/mostik/terminal
colors terminal zig
Last synced: 10 months ago
JSON representation
Terminal tools written in Zig
- Host: GitHub
- URL: https://github.com/mostik/terminal
- Owner: Mostik
- Created: 2024-02-09T10:06:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-10T08:29:06.000Z (about 2 years ago)
- Last Synced: 2025-02-22T07:20:25.385Z (over 1 year ago)
- Topics: colors, terminal, zig
- Language: Zig
- Homepage:
- Size: 16.6 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Terminal utilities
[](https://wakatime.com/badge/user/c76fba5a-9e0d-4336-98f1-75633a3b8c09/project/018d8d57-b288-4728-8f2b-83edcd165172)
## Install
```
zig fetch --save https://github.com/Mostik/terminal/archive/v0.0.2.tar.gz
```
```zig
//build.zig
const terminal = b.dependency("terminal", .{}).module("terminal");
exe.root_module.addImport("terminal", terminal);
```
```zig
const std = @import("std");
const terminal = @import("terminal");
pub fn main() !void {
...
}
```
## ANSI Colors

```zig
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
```zig
std.debug.print("{any}", .{terminal.size()});
// Size{ .rows = 47, .columns = 95, .x_pixels = 950, .y_pixels = 987 }
```
## Cursor Position
```zig
const row = 10;
const col = 10;
try terminal.cursorPos(row, col);
```
## getch
```zig
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});
}
}
```