libghostty-vt
0.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
c-vt-osc/src/main.c
Parse an OSC sequence and read the window title out of it.
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <
ghostty/vt.h
>
int
main() {
GhosttyOscParser
parser;
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
GhosttyOscCommandType
type =
ghostty_osc_command_type
(command);
printf(
"Command type: %d\n"
, type);
// Extract and print the title
GhosttyString
extracted;
if
(
ghostty_osc_command_data
(command,
GHOSTTY_OSC_DATA_CHANGE_WINDOW_TITLE_STR
, &extracted) ==
GHOSTTY_SUCCESS
) {
printf(
"Extracted title: %.*s\n"
, (
int
)extracted.
len
, (
const
char
*)extracted.
ptr
);
}
else
{
printf(
"Failed to extract title\n"
);
}
ghostty_osc_free
(parser);
return
0;
}
GHOSTTY_SUCCESS
@ GHOSTTY_SUCCESS
Definition
types.h:145
ghostty_osc_command_type
GHOSTTY_API GhosttyOscCommandType ghostty_osc_command_type(GhosttyOscCommand command)
ghostty_osc_end
GHOSTTY_API GhosttyOscCommand ghostty_osc_end(GhosttyOscParser parser, uint8_t terminator)
GhosttyOscCommandType
GhosttyOscCommandType
Definition
osc.h:61
ghostty_osc_next
GHOSTTY_API void ghostty_osc_next(GhosttyOscParser parser, uint8_t byte)
GhosttyOscParser
struct GhosttyOscParserImpl * GhosttyOscParser
Definition
types.h:314
ghostty_osc_new
GHOSTTY_API GhosttyResult ghostty_osc_new(const GhosttyAllocator *allocator, GhosttyOscParser *parser)
GhosttyOscCommand
struct GhosttyOscCommandImpl * GhosttyOscCommand
Definition
types.h:324
ghostty_osc_command_data
GHOSTTY_API GhosttyResult ghostty_osc_command_data(GhosttyOscCommand command, GhosttyOscCommandData data, void *out)
ghostty_osc_free
GHOSTTY_API void ghostty_osc_free(GhosttyOscParser parser)
GHOSTTY_OSC_DATA_CHANGE_WINDOW_TITLE_STR
@ GHOSTTY_OSC_DATA_CHANGE_WINDOW_TITLE_STR
Definition
osc.h:224
GhosttyString
Definition
types.h:439
GhosttyString::len
size_t len
Definition
types.h:444
GhosttyString::ptr
const uint8_t * ptr
Definition
types.h:441
vt.h
Generated by
1.17.0