mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-12-28 17:14:39 +00:00
This exposes the SGR parser to the C and Wasm APIs. An example is shown
in c-vt-sgr.
Compressed example:
```c
#include <assert.h>
#include <stdio.h>
#include <ghostty/vt.h>
int main() {
// Create parser
GhosttySgrParser parser;
assert(ghostty_sgr_new(NULL, &parser) == GHOSTTY_SUCCESS);
// Parse: ESC[1;31m (bold + red foreground)
uint16_t params[] = {1, 31};
assert(ghostty_sgr_set_params(parser, params, NULL, 2) == GHOSTTY_SUCCESS);
printf("Parsing: ESC[1;31m\n\n");
// Iterate through attributes
GhosttySgrAttribute attr;
while (ghostty_sgr_next(parser, &attr)) {
switch (attr.tag) {
case GHOSTTY_SGR_ATTR_BOLD:
printf("✓ Bold enabled\n");
break;
case GHOSTTY_SGR_ATTR_FG_8:
printf("✓ Foreground color: %d (red)\n", attr.value.fg_8);
break;
default:
break;
}
}
ghostty_sgr_free(parser);
return 0;
}
```
**AI disclosure:** Amp wrote most of the C headers, but I verified it
all. https://ampcode.com/threads/T-d9f145cb-e6ef-48a8-ad63-e5fc85c0d43e
25 lines
846 B
Zig
25 lines
846 B
Zig
.{
|
|
.name = .c_vt_sgr,
|
|
.version = "0.0.0",
|
|
.fingerprint = 0x6e9c6d318e59c268,
|
|
.minimum_zig_version = "0.15.1",
|
|
.dependencies = .{
|
|
// Ghostty dependency. In reality, you'd probably use a URL-based
|
|
// dependency like the one showed (and commented out) below this one.
|
|
// We use a path dependency here for simplicity and to ensure our
|
|
// examples always test against the source they're bundled with.
|
|
.ghostty = .{ .path = "../../" },
|
|
|
|
// Example of what a URL-based dependency looks like:
|
|
// .ghostty = .{
|
|
// .url = "https://github.com/ghostty-org/ghostty/archive/COMMIT.tar.gz",
|
|
// .hash = "N-V-__8AAMVLTABmYkLqhZPLXnMl-KyN38R8UVYqGrxqO36s",
|
|
// },
|
|
},
|
|
.paths = .{
|
|
"build.zig",
|
|
"build.zig.zon",
|
|
"src",
|
|
},
|
|
}
|