libghostty-vt
0.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
c-vt-encode-key/src/main.c
Encode Ctrl+C as an escape sequence with the Kitty keyboard protocol.
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <
ghostty/vt.h
>
int
main() {
// Create encoder
GhosttyKeyEncoder
encoder;
GhosttyResult
result =
ghostty_key_encoder_new
(NULL, &encoder);
assert(result ==
GHOSTTY_SUCCESS
);
// Enable Kitty keyboard protocol with all features
ghostty_key_encoder_set
(encoder,
GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS
,
&(uint8_t){
GHOSTTY_KITTY_KEY_ALL
});
// Create and configure key event for Ctrl+C press
GhosttyKeyEvent
event;
result =
ghostty_key_event_new
(NULL, &event);
assert(result ==
GHOSTTY_SUCCESS
);
result =
ghostty_key_event_set_action
(event,
GHOSTTY_KEY_ACTION_PRESS
);
assert(result ==
GHOSTTY_SUCCESS
);
result =
ghostty_key_event_set_key
(event, GHOSTTY_KEY_C);
assert(result ==
GHOSTTY_SUCCESS
);
result =
ghostty_key_event_set_mods
(event,
GHOSTTY_MODS_CTRL
);
assert(result ==
GHOSTTY_SUCCESS
);
result =
ghostty_key_event_set_unshifted_codepoint
(event,
'c'
);
assert(result ==
GHOSTTY_SUCCESS
);
// Encode the key event
uint8_t buf[128];
size_t
written = 0;
result =
ghostty_key_encoder_encode
(encoder, event, buf,
sizeof
(buf), &written);
assert(result ==
GHOSTTY_SUCCESS
);
// Use the encoded sequence (e.g., write to terminal)
fwrite(buf, 1, written, stdout);
// Cleanup
ghostty_key_event_free
(event);
ghostty_key_encoder_free
(encoder);
return
0;
}
GhosttyResult
GhosttyResult
Definition
types.h:143
GHOSTTY_SUCCESS
@ GHOSTTY_SUCCESS
Definition
types.h:145
GhosttyKeyEncoder
struct GhosttyKeyEncoderImpl * GhosttyKeyEncoder
Definition
key/encoder.h:25
ghostty_key_event_new
GHOSTTY_API GhosttyResult ghostty_key_event_new(const GhosttyAllocator *allocator, GhosttyKeyEvent *event)
ghostty_key_event_set_key
GHOSTTY_API GhosttyResult ghostty_key_event_set_key(GhosttyKeyEvent event, GhosttyKey key)
ghostty_key_event_set_action
GHOSTTY_API GhosttyResult ghostty_key_event_set_action(GhosttyKeyEvent event, GhosttyKeyAction action)
GHOSTTY_MODS_CTRL
#define GHOSTTY_MODS_CTRL
Definition
key/event.h:62
GhosttyKeyEvent
struct GhosttyKeyEventImpl * GhosttyKeyEvent
Definition
key/event.h:24
ghostty_key_event_set_unshifted_codepoint
GHOSTTY_API GhosttyResult ghostty_key_event_set_unshifted_codepoint(GhosttyKeyEvent event, uint32_t codepoint)
ghostty_key_encoder_set
GHOSTTY_API GhosttyResult ghostty_key_encoder_set(GhosttyKeyEncoder encoder, GhosttyKeyEncoderOption option, const void *value)
ghostty_key_event_set_mods
GHOSTTY_API GhosttyResult ghostty_key_event_set_mods(GhosttyKeyEvent event, GhosttyMods mods)
ghostty_key_encoder_new
GHOSTTY_API GhosttyResult ghostty_key_encoder_new(const GhosttyAllocator *allocator, GhosttyKeyEncoder *encoder)
ghostty_key_encoder_free
GHOSTTY_API void ghostty_key_encoder_free(GhosttyKeyEncoder encoder)
ghostty_key_encoder_encode
GHOSTTY_API GhosttyResult ghostty_key_encoder_encode(GhosttyKeyEncoder encoder, GhosttyKeyEvent event, uint8_t *buf, size_t buf_len, size_t *out_written)
GHOSTTY_KITTY_KEY_ALL
#define GHOSTTY_KITTY_KEY_ALL
Definition
key/encoder.h:57
ghostty_key_event_free
GHOSTTY_API void ghostty_key_event_free(GhosttyKeyEvent event)
GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS
@ GHOSTTY_KEY_ENCODER_OPT_KITTY_FLAGS
Definition
key/encoder.h:116
GHOSTTY_KEY_ACTION_PRESS
@ GHOSTTY_KEY_ACTION_PRESS
Definition
key/event.h:35
vt.h
Generated by
1.17.0