Feed VT sequences into a terminal, read the final screen back as plain text, and draw it with a render state. Start here for read-only tools like replay viewers and CI log viewers.
#include <assert.h>
#include <stdio.h>
#include <string.h>
int main(void) {
const char *text = "Hello, World!\r\n";
text = "\x1b[1;32mGreen Text\x1b[0m\r\n";
text = "\x1b[1;1HTop-left corner\r\n";
text = "\x1b[5B";
text = "Moved down!\r\n";
text = "\x1b[2K";
text = "New content\r\n";
text = "Line A\r\nLine B\r\nLine C\r\n";
bool trim = true;
uint8_t *buf = NULL;
size_t len = 0;
fwrite(buf, 1, len, stdout);
printf("\n");
uint16_t y = 0;
uint8_t bytes[64];
putchar(' ');
continue;
}
if (bold) printf("\x1b[1m");
fwrite(bytes, 1, grapheme.
len, stdout);
if (bold) printf("\x1b[0m");
}
putchar('\n');
}
return 0;
}
GHOSTTY_API void ghostty_free(const GhosttyAllocator *allocator, uint8_t *ptr, size_t len)
GHOSTTY_API GhosttyResult ghostty_render_state_row_cells_new(const GhosttyAllocator *allocator, GhosttyRenderStateRowCells *out_cells)
GHOSTTY_API GhosttyResult ghostty_render_state_row_cells_get(GhosttyRenderStateRowCells cells, GhosttyRenderStateRowCellsData data, void *out)
GHOSTTY_API GhosttyResult ghostty_render_state_clean(GhosttyRenderState state)
GHOSTTY_API bool ghostty_render_state_row_cells_next(GhosttyRenderStateRowCells cells)
GHOSTTY_API GhosttyResult ghostty_render_state_update(GhosttyRenderState state, GhosttyTerminal terminal)
struct GhosttyRenderStateRowIteratorImpl * GhosttyRenderStateRowIterator
struct GhosttyRenderStateImpl * GhosttyRenderState
GHOSTTY_API GhosttyResult ghostty_render_state_new(const GhosttyAllocator *allocator, GhosttyRenderState *state)
GHOSTTY_API GhosttyResult ghostty_render_state_row_iterator_new(const GhosttyAllocator *allocator, GhosttyRenderStateRowIterator *out_iterator)
GHOSTTY_API void ghostty_render_state_row_cells_free(GhosttyRenderStateRowCells cells)
GHOSTTY_API void ghostty_render_state_row_iterator_free(GhosttyRenderStateRowIterator iterator)
GHOSTTY_API void ghostty_render_state_free(GhosttyRenderState state)
GHOSTTY_API GhosttyResult ghostty_render_state_get(GhosttyRenderState state, GhosttyRenderStateData data, void *out)
GHOSTTY_API bool ghostty_render_state_row_iterator_next_dirty(GhosttyRenderStateRowIterator iterator, uint16_t *out_y)
GHOSTTY_API GhosttyResult ghostty_render_state_row_get(GhosttyRenderStateRowIterator iterator, GhosttyRenderStateRowData data, void *out)
struct GhosttyRenderStateRowCellsImpl * GhosttyRenderStateRowCells
@ GHOSTTY_RENDER_STATE_ROW_DATA_CELLS
@ GHOSTTY_RENDER_STATE_DATA_ROW_ITERATOR
@ GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_STYLE
@ GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_GRAPHEMES_UTF8
#define GHOSTTY_STYLE_FLAG_BOLD
struct GhosttyTerminalImpl * GhosttyTerminal
GHOSTTY_API void ghostty_terminal_free(GhosttyTerminal terminal)
GHOSTTY_API void ghostty_terminal_vt_write(GhosttyTerminal terminal, const uint8_t *data, size_t len)
GHOSTTY_API GhosttyResult ghostty_terminal_new(const GhosttyAllocator *allocator, GhosttyTerminal *terminal, uint16_t cols, uint16_t rows)