libghostty
Loading...
Searching...
No Matches
c-vt/src/main.c

This example demonstrates how to use the OSC parser to parse an OSC sequence, extract command information, and retrieve command-specific data like window titles.

#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <ghostty/vt.h>
int main() {
if (ghostty_osc_new(NULL, &parser) != GHOSTTY_SUCCESS) {
return 1;
}
// Setup change window title command to change the title to "hello"
ghostty_osc_next(parser, '0');
ghostty_osc_next(parser, ';');
const char *title = "hello";
for (size_t i = 0; i < strlen(title); i++) {
ghostty_osc_next(parser, title[i]);
}
// End parsing and get command
GhosttyOscCommand command = ghostty_osc_end(parser, 0);
// Get and print command type
printf("Command type: %d\n", type);
// Extract and print the title
printf("Extracted title: %s\n", title);
} else {
printf("Failed to extract title\n");
}
return 0;
}
GHOSTTY_API GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command)
GHOSTTY_API GhosttyOscCommand ghostty_osc_end(GhosttyOscParser parser, uint8_t terminator)
GhosttyOscCommandType
Definition osc.h:42
GHOSTTY_API void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte)
struct GhosttyOscParserImpl * GhosttyOscParser
Definition types.h:173
GHOSTTY_API GhosttyResult ghostty_osc_new(const GhosttyAllocator *allocator, GhosttyOscParser *parser)
GHOSTTY_API bool ghostty_osc_command_data(GhosttyOscCommand command, GhosttyOscCommandData data, void *out)
struct GhosttyOscCommandImpl * GhosttyOscCommand
Definition types.h:183
GHOSTTY_API void ghostty_osc_free(GhosttyOscParser parser)
@ GHOSTTY_OSC_DATA_CHANGE_WINDOW_TITLE_STR
Definition osc.h:91
@ GHOSTTY_SUCCESS
Definition types.h:76