mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-20 20:48:06 +00:00
libghostty: C api to stream formatter output through a GhosttyWriter
Add `ghostty_formatter_format` which uses a streaming GhosttyWriter type to write. Update the example to show this.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <ghostty/vt/allocator.h>
|
||||
#include <ghostty/vt/io.h>
|
||||
#include <ghostty/vt/selection.h>
|
||||
#include <ghostty/vt/types.h>
|
||||
#include <ghostty/vt/terminal.h>
|
||||
@@ -137,6 +138,30 @@ GHOSTTY_API GhosttyResult ghostty_formatter_terminal_new(
|
||||
GhosttyTerminal terminal,
|
||||
GhosttyFormatterTerminalOptions options);
|
||||
|
||||
/**
|
||||
* Run the formatter and stream output to a writer.
|
||||
*
|
||||
* Each call formats the current terminal state and invokes the writer
|
||||
* synchronously as output becomes available. The callback may be called more
|
||||
* than once and must not call formatter or terminal APIs using the same
|
||||
* formatter or its terminal.
|
||||
*
|
||||
* If an error occurs, the writer may already contain a partial formatted
|
||||
* output. The operation cannot be resumed from that partial output. This
|
||||
* function does not flush or make the caller's destination durable.
|
||||
*
|
||||
* @param formatter The formatter handle (must not be NULL)
|
||||
* @param writer Destination writer whose write callback must not be NULL
|
||||
* @return GHOSTTY_SUCCESS on success, GHOSTTY_IO_ERROR if the writer rejects
|
||||
* output, GHOSTTY_LIMIT_EXCEEDED if output accounting overflows, or
|
||||
* GHOSTTY_INVALID_VALUE if an argument is invalid
|
||||
*
|
||||
* @ingroup formatter
|
||||
*/
|
||||
GHOSTTY_API GhosttyResult ghostty_formatter_format(
|
||||
GhosttyFormatter formatter,
|
||||
GhosttyWriter writer);
|
||||
|
||||
/**
|
||||
* Run the formatter and produce output into the caller-provided buffer.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user