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;
}
GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command)
struct GhosttyOscCommand * GhosttyOscCommand
Definition osc.h:34
struct GhosttyOscParser * GhosttyOscParser
Definition osc.h:24
bool ghostty_osc_command_data(GhosttyOscCommand command, GhosttyOscCommandData data, void *out)
GhosttyOscCommandType
Definition osc.h:62
void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte)
GhosttyOscCommand ghostty_osc_end(GhosttyOscParser parser, uint8_t terminator)
void ghostty_osc_free(GhosttyOscParser parser)
GhosttyResult ghostty_osc_new(const GhosttyAllocator *allocator, GhosttyOscParser *parser)
@ GHOSTTY_OSC_DATA_CHANGE_WINDOW_TITLE_STR
Definition osc.h:108
@ GHOSTTY_SUCCESS
Definition result.h:15