This repository has no description

libghostty: add initial C API for terminal, formatter (#11506) master

This adds an initial C API for terminals and formatting. There is a new example that shows how to use this. With these APIs in place, users of the C API can now create a terminal, pass raw VT streams to it, and dump the terminal viewport to various formats. As noted in the docs, **the formatter API is not a rendering API**, it isn't high performance enough for that. But it's a simpler API to implement than the render state API so I started with that. Both APIs are purposely fairly minimal, we're just setting the stage for future functionality. ## Example ```c #include <ghostty/vt.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { GhosttyTerminal term; GhosttyTerminalOptions opts = { .cols = 80, .rows = 24, .max_scrollback = 0 }; ghostty_terminal_new(NULL, &term, opts); const char *input = "Hello, \033[1mBold\033[0m World!\r\nLine 2\r\n"; ghostty_terminal_vt_write(term, (const uint8_t *)input, strlen(input)); GhosttyFormatterTerminalOptions fmt = GHOSTTY_INIT_SIZED(GhosttyFormatterTerminalOptions); fmt.emit = GHOSTTY_FORMATTER_FORMAT_PLAIN; fmt.trim = true; GhosttyFormatter fmtr; ghostty_formatter_terminal_new(NULL, &fmtr, term, fmt); uint8_t *buf; size_t len; ghostty_formatter_format_alloc(fmtr, NULL, &buf, &len); fwrite(buf, 1, len, stdout); free(buf); ghostty_formatter_free(fmtr); ghostty_terminal_free(term); } ``` ## New APIs | Function | Description | |----------|-------------| | `ghostty_terminal_new` | Create a new terminal instance | | `ghostty_terminal_free` | Free a terminal instance | | `ghostty_terminal_reset` | Full reset of the terminal (RIS) | | `ghostty_terminal_resize` | Resize the terminal to given dimensions | | `ghostty_terminal_vt_write` | Write VT-encoded data to the terminal | | `ghostty_terminal_scroll_viewport` | Scroll the terminal viewport | | `ghostty_formatter_terminal_new` | Create a formatter for a terminal's active screen | | `ghostty_formatter_format_buf` | Format into a caller-provided buffer | | `ghostty_formatter_format_alloc` | Format into an allocated buffer | | `ghostty_formatter_free` | Free a formatter instance | ## Future - Obviously need to expose a lot more from the terminal: * Read current set modes * Read cursor information * Read screen information * etc... - Need an optional callback system so that `vt_write` can invoke callbacks for side effect sequences like clipboards, title setting, responses, etc. - `terminal.RenderState` C API so that people can build high performance renderers on top of libghostty-vt And so on...