mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-06 07:38:21 +00:00
docs: extract inline code examples into standalone projects
Extract inline @code blocks from vt headers (size_report.h, modes.h, sgr.h, paste.h, mouse.h, key.h) into standalone buildable examples under example/. Each header now uses Doxygen @snippet tags to include code from the example source files, keeping documentation in sync with code that is verified to compile and run. New example projects: c-vt-size-report and c-vt-modes. Existing examples (c-vt-sgr, c-vt-paste, c-vt-mouse-encode, c-vt-key-encode) gain snippet markers so their code can be referenced from the headers. Conceptual snippets in key.h, mouse.h, and key/encoder.h that show terminal-state usage patterns remain inline since they cannot be compiled standalone.
This commit is contained in:
@@ -2,18 +2,23 @@
|
||||
#include <string.h>
|
||||
#include <ghostty/vt.h>
|
||||
|
||||
int main() {
|
||||
// Test safe paste data
|
||||
const char *safe_data = "hello world";
|
||||
//! [paste-safety]
|
||||
void basic_example() {
|
||||
const char* safe_data = "hello world";
|
||||
const char* unsafe_data = "rm -rf /\n";
|
||||
|
||||
if (ghostty_paste_is_safe(safe_data, strlen(safe_data))) {
|
||||
printf("'%s' is safe to paste\n", safe_data);
|
||||
printf("Safe to paste\n");
|
||||
}
|
||||
|
||||
// Test unsafe paste data with newline
|
||||
const char *unsafe_newline = "rm -rf /\n";
|
||||
if (!ghostty_paste_is_safe(unsafe_newline, strlen(unsafe_newline))) {
|
||||
printf("'%s' is UNSAFE - contains newline\n", unsafe_newline);
|
||||
if (!ghostty_paste_is_safe(unsafe_data, strlen(unsafe_data))) {
|
||||
printf("Unsafe! Contains newline\n");
|
||||
}
|
||||
}
|
||||
//! [paste-safety]
|
||||
|
||||
int main() {
|
||||
basic_example();
|
||||
|
||||
// Test unsafe paste data with bracketed paste end sequence
|
||||
const char *unsafe_escape = "evil\x1b[201~code";
|
||||
|
||||
Reference in New Issue
Block a user