ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
input.h File Reference

Go to the source code of this file.

Data Structures

struct  tui_input_events_t

Macros

#define TUI_INPUT_PASTE_BUFFER_SIZE   8192

Functions

void ui_input_poll_sync (void)
keyboard_key_t ui_input_read_key (ui_screen_t screen)
keyboard_key_t ui_input_wait_key (ui_screen_t screen, unsigned timeout_ms)
void ui_input_shutdown (void)
uint64_t ui_input_deadline (unsigned seconds)
bool ui_input_expired (uint64_t deadline)
void ui_input_timeout_report (unsigned seconds, const char *consequence)
asciichat_error_t ui_input_prompt (const char *prompt, char *buffer, size_t max_len, prompt_opts_t opts)
asciichat_error_t ui_input_take_paste (char *buffer, size_t capacity)
asciichat_error_t ui_input_prompt_prefilled (const char *prompt, char *buffer, size_t max_len, prompt_opts_t opts)
asciichat_error_t ui_input_media_begin (const char *text)
asciichat_error_t ui_input_media_take (char *output, size_t capacity)
asciichat_error_t ui_input_password (const char *target, char *buffer, size_t capacity, bool incorrect)
keyboard_key_t tui_input_events_read (tui_input_events_t *state, keyboard_key_t(*read_key)(void), bool(*classify_paste)(const char *))

Macro Definition Documentation

◆ TUI_INPUT_PASTE_BUFFER_SIZE

#define TUI_INPUT_PASTE_BUFFER_SIZE   8192

Definition at line 7 of file tui/input.h.

Function Documentation

◆ tui_input_events_read()

keyboard_key_t tui_input_events_read ( tui_input_events_t * state,
keyboard_key_t(* read_key )(void),
bool(* classify_paste )(const char *) )

Collect paste boundaries and optional application-classified text bursts. Once ready, the caller consumes/clears paste before reading another event.

Definition at line 85 of file tui/input.c.

87 {
88 if (s->ready)
89 return KEY_NONE;
90 for (unsigned i = 0; i < 1024; ++i) {
91 bool buffered = s->count != 0;
92 keyboard_key_t key = buffered ? s->keys[s->head++] : read_key();
93 if (buffered)
94 --s->count;
95 if (key == KEY_NONE)
96 return KEY_NONE;
97 if (key == KEY_PASTE_BEGIN) {
98 s->pasting = true;
99 s->invalid = false;
100 s->length = 0;
101 continue;
102 }
103 if (key == KEY_PASTE_END) {
104 if (!s->pasting)
105 continue;
106 s->pasting = false;
107 s->paste[s->length] = '\0';
108 s->ready = true;
109 return KEY_PASTE;
110 }
111 char text[8];
112 size_t bytes = keyboard_text_encode(key, text);
113 if (s->pasting) {
114 // Paste payloads remain raw UTF-8 bytes until whole-paste validation.
115 if (key >= 128 && key <= 255) {
116 text[0] = (char)key;
117 bytes = 1;
118 }
119 if (!bytes || (key < 32 && key != '\r' && key != '\n' && key != '\t') ||
120 key == 127 || bytes >= sizeof(s->paste) - s->length)
121 s->invalid = true;
122 else {
123 memcpy(s->paste + s->length, text, bytes);
124 s->length += bytes;
125 }
126 continue;
127 }
128 if (buffered || !bytes || key < 32 || key == 127)
129 return key;
130 s->head = 0;
131 s->keys[0] = key;
132 size_t count = 1;
133 keyboard_key_t next;
134 while (count < 8192 && (next = read_key()) != KEY_NONE) {
135 s->keys[count++] = next;
136 if (next == KEY_PASTE_BEGIN || next == KEY_PASTE_END)
137 break;
138 }
139 bool boundary = s->keys[count - 1] == KEY_PASTE_BEGIN ||
140 s->keys[count - 1] == KEY_PASTE_END;
141 size_t consumed = boundary ? count - 1 : count;
142 size_t text_count = consumed;
143 while (text_count &&
144 (s->keys[text_count - 1] == '\r' || s->keys[text_count - 1] == '\n'))
145 --text_count;
146 char burst[TUI_INPUT_BURST_BUFFER_SIZE];
147 size_t length = 0;
148 bool valid = true;
149 for (size_t n = 0; n < text_count; ++n) {
150 bytes = keyboard_text_encode(s->keys[n], text);
151 if (!bytes || s->keys[n] < 32 || s->keys[n] == 127 ||
152 bytes >= sizeof(burst) - length) {
153 valid = false;
154 break;
155 }
156 memcpy(burst + length, text, bytes);
157 length += bytes;
158 }
159 burst[length] = '\0';
160 if (text_count > 1 && classify_paste && classify_paste(burst)) {
161 // Keep the delimiter queued so the following payload remains framed.
162 s->head = consumed;
163 s->count = count - consumed;
164 s->invalid = !valid;
165 s->length = valid ? length : 0;
166 memcpy(s->paste, burst, s->length);
167 s->paste[s->length] = '\0';
168 s->ready = true;
169 return KEY_PASTE;
170 }
171 s->head = 1;
172 s->count = count - 1;
173 return key;
174 }
175 return KEY_NONE;
176}
bool valid
Definition fft.c:29
#define TUI_INPUT_BURST_BUFFER_SIZE
Definition tui/input.c:4

References tui_input_events_t::count, tui_input_events_t::head, tui_input_events_t::invalid, tui_input_events_t::keys, tui_input_events_t::length, tui_input_events_t::paste, tui_input_events_t::pasting, tui_input_events_t::ready, TUI_INPUT_BURST_BUFFER_SIZE, and valid.

◆ ui_input_deadline()

uint64_t ui_input_deadline ( unsigned seconds)

Absolute monotonic deadline; user activity never extends it.

Definition at line 48 of file tui/input.c.

48 {
49 return time_get_ns() + (uint64_t)seconds * NS_PER_SEC_INT;
50}
unsigned long long uint64_t
#define NS_PER_SEC_INT
Definition time.h:173

References NS_PER_SEC_INT.

Referenced by ui_input_media_begin(), and ui_mdns_select().

◆ ui_input_expired()

bool ui_input_expired ( uint64_t deadline)

Definition at line 52 of file tui/input.c.

52{ return time_get_ns() >= deadline; }

Referenced by ui_input_read_key().

◆ ui_input_media_begin()

asciichat_error_t ui_input_media_begin ( const char * text)

Begin media text entry without blocking capture or network processing.

Definition at line 844 of file tui/input.c.

844 {
845 if (!text || !utf8_is_valid(text) ||
846 strlen(text) >= sizeof(g_media_editor.buffer) || !input_initialize())
847 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid media prompt text");
848 mutex_lock(&g_input_mutex);
849 memset(&g_media_editor, 0, sizeof(g_media_editor));
850 memcpy(g_media_editor.buffer, text, strlen(text) + 1);
851 g_media_editor.length = g_media_editor.cursor = strlen(text);
852 g_media_editor.deadline = ui_input_deadline(120);
853 asciichat_error_t result =
854 ui_prompt_present_kind("Open media: files or URLs\nDrop more files to "
855 "queue; Enter plays; Esc cancels",
856 g_media_editor.buffer, g_media_editor.cursor,
857 false, UI_PROMPT_MEDIA_INPUT);
858 g_media_editor.active = result == ASCIICHAT_OK;
859 input_unlock();
860 return result;
861}
#define SET_ERRNO(code,...)
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
bool utf8_is_valid(const char *str)
Check if a string is valid UTF-8.
Definition utf8.c:132
asciichat_error_t ui_prompt_present_kind(const char *prompt, const char *visible, size_t cursor, bool secret, ui_prompt_kind_t kind)
Definition prompt.c:309
uint64_t ui_input_deadline(unsigned seconds)
Definition tui/input.c:48

References ASCIICHAT_OK, ERROR_INVALID_PARAM, SET_ERRNO, ui_input_deadline(), ui_prompt_present_kind(), and utf8_is_valid().

Referenced by session_handle_keyboard_input().

◆ ui_input_media_take()

asciichat_error_t ui_input_media_take ( char * output,
size_t capacity )

Consume the value signaled by KEY_MEDIA_SUBMIT.

Definition at line 863 of file tui/input.c.

863 {
864 if (!output || !input_initialize())
865 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid media prompt destination");
866 mutex_lock(&g_input_mutex);
868 if (!g_media_editor.submitted || g_media_editor.length >= capacity)
869 result = SET_ERRNO(ERROR_INVALID_STATE, "No submitted media prompt");
870 else {
871 memcpy(output, g_media_editor.buffer, g_media_editor.length + 1);
873 media_playlist_t playlist = {0};
874 if (media_playlist_parse(output, &playlist) == ASCIICHAT_OK) {
875 bool file = false, url = false;
876 for (size_t i = 0; i < playlist.count; ++i) {
877 file |= !playlist.urls[i];
878 url |= playlist.urls[i];
879 }
880 if (file)
881 ascii_otel_ui_usage("media_input_prompt", "source_file", 0);
882 if (url)
883 ascii_otel_ui_usage("media_input_prompt", "source_url", 0);
884 ascii_otel_ui_usage("media_input_prompt", "queue_submitted", 0);
885 } else {
886 ascii_otel_ui_usage("media_input_prompt", "rejected", 0);
887 }
889 }
890 g_media_editor.submitted = false;
891 input_unlock();
892 return result;
893}
void errno_scope_end(asciichat_errno_scope_t scope, asciichat_errno_outcome_t outcome)
asciichat_errno_scope_t errno_scope_begin(void)
@ ASCIICHAT_ERRNO_DISMISSED
@ ERROR_INVALID_STATE
void ascii_otel_ui_usage(const char *screen, const char *event, uint64_t duration_ns)
Definition otel.c:506
asciichat_error_t media_playlist_parse(const char *text, media_playlist_t *list)
Definition playlist.c:40
When code needs to work with asciichat errno snapshot, it keeps total, copied here instead of scatter...
bool urls[64]
Definition playlist.h:15

References ascii_otel_ui_usage(), ASCIICHAT_ERRNO_DISMISSED, ASCIICHAT_OK, media_playlist_t::count, errno_scope_begin(), errno_scope_end(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, media_playlist_parse(), SET_ERRNO, and media_playlist_t::urls.

Referenced by session_handle_keyboard_input().

◆ ui_input_password()

asciichat_error_t ui_input_password ( const char * target,
char * buffer,
size_t capacity,
bool incorrect )

Server password dialog; cancellation requests normal application shutdown.

Definition at line 816 of file tui/input.c.

817 {
818 if (!target || !buffer || capacity < 2)
819 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid password dialog");
820 sodium_memzero(buffer, capacity);
821 if (env_pop_prompt_response(buffer, capacity))
822 return ASCIICHAT_OK;
824 return SET_ERRNO(
826 "Server password requires an interactive terminal or --password");
827 asciichat_error_t result = input_prompt(
828 target, buffer, capacity, PROMPT_OPTS_PASSWORD, true, incorrect);
829 if (result != ASCIICHAT_OK) {
832 return SET_ERRNO(ERROR_CRYPTO_AUTH, "Password entry cancelled");
833 }
834 return result;
835}
#define APP_CALLBACK_VOID(callback_name)
bool env_pop_prompt_response(char *response_out, size_t response_size)
Pop the first response from ASCII_CHAT_QUESTION_PROMPT_RESPONSE stack.
Definition env.c:98
@ ERROR_CRYPTO_AUTH
void shutdown_request(void)
Definition common.c:85
void signal_exit(void)
Definition main.c:262
bool platform_is_interactive(void)

References APP_CALLBACK_VOID, ASCIICHAT_OK, env_pop_prompt_response(), ERROR_CRYPTO_AUTH, ERROR_INVALID_PARAM, platform_is_interactive(), SET_ERRNO, shutdown_request(), and signal_exit().

Referenced by session_connection_establish().

◆ ui_input_poll_sync()

void ui_input_poll_sync ( void )

Poll debug controls without waiting for another input reader.

Definition at line 301 of file tui/input.c.

301 {
302#ifndef NDEBUG
303 if (atomic_load(&g_input_lifecycle.state) == LIFECYCLE_INITIALIZING ||
304 !input_initialize() || !input_ready() ||
305 mutex_trylock(&g_input_mutex) != 0)
306 return;
307 if (g_switch_pending) {
308 input_unlock();
309 return;
310 }
313 keyboard_key_t key = input_read_event();
314 if (key != KEY_PASTE && !log_search_is_entering())
315 key = ui_sync_handle_key(key);
316 if (key && g_sync_key_count < TUI_SYNC_KEY_CAPACITY) {
317 g_sync_keys[(g_sync_key_head + g_sync_key_count++) % 256] = key;
318 g_switch_pending = input_switch_key(key);
319 }
320 }
321 input_unlock();
322#endif
323}
bool log_search_is_entering(void)
Check if currently in input mode (typing pattern).
Definition search.c:423
keyboard_key_t ui_sync_handle_key(keyboard_key_t key)
Definition sync.c:388
int ui_controller_current_screen(void)
bool ui_controller_is_blocked(void)
@ UI_SCREEN_SYNC
#define TUI_SYNC_KEY_CAPACITY
Definition tui/input.c:10

References log_search_is_entering(), TUI_SYNC_KEY_CAPACITY, ui_controller_current_screen(), ui_controller_is_blocked(), UI_SCREEN_SYNC, and ui_sync_handle_key().

◆ ui_input_prompt()

asciichat_error_t ui_input_prompt ( const char * prompt,
char * buffer,
size_t max_len,
prompt_opts_t opts )

Definition at line 837 of file tui/input.c.

838 {
839 if (buffer && max_len)
840 buffer[0] = '\0';
841 return ui_input_prompt_prefilled(prompt, buffer, max_len, opts);
842}
asciichat_error_t ui_input_prompt_prefilled(const char *prompt, char *buffer, size_t max_len, prompt_opts_t opts)
Definition tui/input.c:810

References ui_input_prompt_prefilled().

◆ ui_input_prompt_prefilled()

asciichat_error_t ui_input_prompt_prefilled ( const char * prompt,
char * buffer,
size_t max_len,
prompt_opts_t opts )

Editable prompt initialized with buffer contents.

Definition at line 810 of file tui/input.c.

812 {
813 return input_prompt(prompt, buffer, max_len, opts, false, false);
814}

Referenced by ui_input_prompt().

◆ ui_input_read_key()

keyboard_key_t ui_input_read_key ( ui_screen_t screen)

Input policy is separate from presentation. Covered controls are consumed and discarded.

Definition at line 374 of file tui/input.c.

374 {
375 if (!input_initialize())
376 return KEY_NONE;
377 if (!input_ready()) {
378 // Once recovery has an empty input queue, the next key is a fresh action.
379 if (atomic_load(&g_discarding_covered_input) &&
380 !ui_controller_state().covered)
381 atomic_store(&g_discarding_covered_input, false);
382 return KEY_NONE;
383 }
384 mutex_lock(&g_input_mutex);
386 // The previous event has now been dispatched by the session. Background
387 // polling must not overtake a pending switch with the next shortcut.
388 g_switch_pending = false;
389 if (input_discard_covered(state.covered)) {
390 input_unlock();
391 return KEY_NONE;
392 }
393 if (state.screen == UI_SCREEN_HELP &&
396 keyboard_key_t key =
397 keyboard_help_check_signal_cancel() ? KEY_ESCAPE : input_next_key();
398 if (key == KEY_ESCAPE || key == KEY_QUESTION)
400 if (key == KEY_PASTE)
401 g_events.ready = false;
402 input_unlock();
403 return KEY_NONE;
404 }
406 keyboard_key_t key = input_next_key();
407 if (key != KEY_NONE)
409 if (key == KEY_PASTE)
410 g_events.ready = false;
411 input_unlock();
412 return KEY_NONE;
413 }
414 if (state.screen == UI_SCREEN_ERROR) {
415 keyboard_key_t key = input_next_key();
416 if (key == KEY_QUESTION)
418 else if (key != KEY_NONE && key != KEY_PASTE && key != 3) {
420 /* The first q dismisses the modal error. Only a later q, after the
421 * final error is gone, is allowed to reach the session exit handler. */
422 if (key == 'q' && !ui_error_popup_visible()) {
423 input_unlock();
424 return key;
425 }
426 }
427 if (key == KEY_PASTE)
428 g_events.ready = false;
429 input_unlock();
430 return key == 3 ? key : KEY_NONE;
431 }
432 if (state.screen == UI_SCREEN_NOTICE) {
433 g_events.ready = false;
434 g_sync_key_count = 0;
435 keyboard_key_t notice_key = input_read_event();
436 if (notice_key == KEY_PASTE)
437 g_events.ready = false;
438 bool first_use = ui_controller_first_use_key(notice_key);
439 if (!first_use &&
440 (notice_key == KEY_ESCAPE || notice_key == '\r' || notice_key == '\n' ||
441 notice_key == 'q' || notice_key == 3))
443 input_unlock();
444 return notice_key == 'q' || notice_key == 3 ? notice_key : KEY_NONE;
445 }
447 keyboard_key_t update_key = input_read_event();
448 if (update_key == '=' || update_key == KEY_0 ||
449 update_key == KEY_QUESTION || update_key == ']') {
450 if (update_key != KEY_QUESTION)
452 if (update_key == KEY_QUESTION) {
454 } else {
455 update_key = input_common_key(update_key, UI_SCREEN_UPDATE);
456 (void)ui_sync_handle_key(update_key);
457 }
458 } else if (update_key != KEY_NONE)
459 (void)update_banner_handle_key(update_key);
460 input_unlock();
461 return KEY_NONE;
462 }
463 if (screen == UI_SCREEN_MEDIA && g_media_editor.active &&
464 state.screen == UI_SCREEN_PROMPT) {
465 keyboard_key_t key = input_next_key();
466 bool switch_screen = input_switch_key(key) && key != '=' &&
467 (g_media_editor.length == 0 || key == 15);
468#ifndef NDEBUG
469 switch_screen |= key == KEY_0 && g_media_editor.length == 0;
470#endif
471 if (switch_screen) {
472 // Keep the old prompt on screen until its replacement is published.
473 if (key != KEY_QUESTION)
474 g_media_editor.active = false;
475 if (key == KEY_0)
476 key = ui_sync_handle_key(key);
477 key = input_common_key(key, state.screen);
478 g_switch_pending = input_switch_key(key);
479 input_unlock();
480 return key;
481 }
482 if (key == KEY_ESCAPE || key == 3 ||
483 ui_input_expired(g_media_editor.deadline)) {
484 if (key == KEY_PASTE)
485 g_events.ready = false;
487 "media_input_prompt",
488 ui_input_expired(g_media_editor.deadline) ? "timed_out" : "cancelled",
489 0);
490 g_media_editor.active = false;
492 } else if (key == '\r' || key == '\n') {
493 g_media_editor.active = false;
494 g_media_editor.submitted = true;
495 ascii_otel_ui_usage("media_input_prompt", "submitted", 0);
496 input_unlock();
497 return KEY_MEDIA_SUBMIT;
498 } else if (key != KEY_NONE) {
499 if (key == KEY_PASTE)
500 ascii_otel_ui_usage("media_input_prompt", "paste", 0);
501 if (key == KEY_PASTE) {
502 if (!g_events.invalid && utf8_is_valid(g_events.paste)) {
503 media_playlist_t items = {0}, added = {0};
504 bool valid = !g_media_editor.length ||
505 media_playlist_parse(g_media_editor.buffer, &items) ==
507 valid = valid &&
508 media_playlist_parse(g_events.paste, &added) == ASCIICHAT_OK;
509 if (valid) {
510 for (size_t i = 0; i < added.count && valid; ++i)
511 valid = media_playlist_append(&items, added.paths[i],
512 added.urls[i]) == ASCIICHAT_OK;
513 char formatted[sizeof(g_media_editor.buffer)];
514 valid = valid &&
515 media_playlist_format(&items, formatted,
516 sizeof(formatted)) == ASCIICHAT_OK;
517 if (valid) {
518 memcpy(g_media_editor.buffer, formatted, strlen(formatted) + 1);
519 g_media_editor.length = g_media_editor.cursor = strlen(formatted);
520 }
521 }
522 if (valid)
523 ascii_otel_ui_usage("media_input_prompt", "queue_changed", 0);
524 CLEAR_ERRNO();
525 }
526 g_events.ready = false;
527 g_media_editor.pasted = true;
528 } else if (!(key == ' ' && g_media_editor.pasted &&
529 g_media_editor.cursor == g_media_editor.length)) {
530 g_media_editor.pasted = false;
531 ui_input_edit_key(g_media_editor.buffer, sizeof(g_media_editor.buffer),
532 &g_media_editor.length, &g_media_editor.cursor, key);
533 }
534 if (ui_prompt_present_kind("Open media: files or URLs\nDrop more files "
535 "to queue; Enter plays; Esc cancels",
536 g_media_editor.buffer, g_media_editor.cursor,
537 false,
538 UI_PROMPT_MEDIA_INPUT) != ASCIICHAT_OK) {
539 g_media_editor.active = false;
541 CLEAR_ERRNO();
542 }
543 }
544 input_unlock();
545 return KEY_NONE;
546 }
547 bool primary = screen == UI_SCREEN_MEDIA || screen == UI_SCREEN_SPLASH ||
549 bool server = GET_OPTION(detected_mode) == MODE_SERVER ||
550 GET_OPTION(detected_mode) == MODE_DISCOVERY_SERVICE ||
551 GET_OPTION(detected_mode) == MODE_MCP_SERVER;
552 bool server_owner = screen == UI_SCREEN_STATS && server &&
554 bool active =
555 state.screen < 0 || state.screen == (int)screen ||
556 ((primary || server_owner) && state.screen <= UI_SCREEN_SYNC &&
557 state.screen != UI_SCREEN_STATS && state.screen != UI_SCREEN_RECONNECT);
558 keyboard_key_t key = KEY_NONE;
559 if (active) {
560 if (g_sync_key_count) {
561 key = g_sync_keys[g_sync_key_head];
562 g_sync_key_head = (g_sync_key_head + 1) % 256;
563 --g_sync_key_count;
564 }
565 if (key == KEY_NONE)
566 key =
568 ? KEY_QUESTION
569 : input_read_event();
570 if (key == KEY_F12) {
571 // Synchronous prompts own their input, including function keys.
572 // Opening the update checker here would suspend credential entry.
575 key = KEY_NONE;
576 }
577 if (screen != UI_SCREEN_PROMPT) {
578 key = input_common_key(key, state.screen);
579 if (key != KEY_PASTE && !log_search_is_entering() &&
580 !(screen == UI_SCREEN_MDNS && state.screen == UI_SCREEN_MDNS))
581 key = ui_sync_handle_key(key);
582 }
583 }
584 if (key == KEY_PASTE && log_search_is_entering()) {
585 if (!g_events.invalid)
586 (void)log_search_insert_text(g_events.paste);
587 g_events.ready = false;
588 key = KEY_NONE;
589 }
590 if (key == KEY_PASTE && screen != UI_SCREEN_MEDIA &&
592 g_events.ready = false;
593 key = KEY_NONE;
594 }
595 if (screen != UI_SCREEN_PROMPT && key != KEY_NONE &&
597 key = KEY_NONE;
598 g_switch_pending |= input_switch_key(key);
599 input_unlock();
600 return key;
601}
#define CLEAR_ERRNO()
bool ui_error_popup_visible(void)
Definition error_popup.c:74
void ui_error_popup_key(keyboard_key_t key)
Definition error_popup.c:88
#define GET_OPTION(field)
Definition options.h:1339
@ MODE_MCP_SERVER
Model Context Protocol rendering server.
Definition options.h:922
@ MODE_DISCOVERY_SERVICE
Discovery server mode - session management and WebRTC signaling.
Definition options.h:920
@ MODE_SERVER
Server mode - network server options.
Definition options.h:917
void keyboard_help_toggle_terminal(int fd)
int keyboard_help_parent_screen(void)
bool update_banner_handle_key(int key)
bool keyboard_help_check_signal_cancel(void)
Check if help screen closure was requested by signal handler.
void update_banner_toggle_overlay(void)
bool update_banner_is_overlay_open(void)
asciichat_error_t media_playlist_format(const media_playlist_t *list, char *text, size_t capacity)
Definition playlist.c:103
asciichat_error_t media_playlist_append(media_playlist_t *list, const char *path, bool url)
Definition playlist.c:7
void ui_prompt_remove(void)
Definition prompt.c:355
asciichat_error_t log_search_insert_text(const char *text)
Definition search.c:501
bool terminal_screen_logs_help_open(void)
bool terminal_screen_logs_handle_key(int key)
void ui_controller_remove(ui_screen_t screen)
bool ui_controller_first_use_key(int key)
ui_presentation_state_t ui_controller_state(void)
bool ui_controller_screen_live(ui_screen_t screen)
int ui_controller_active_fd(void)
@ UI_SCREEN_PROMPT
@ UI_SCREEN_NOTICE
@ UI_SCREEN_MEDIA
@ UI_SCREEN_RECONNECT
@ UI_SCREEN_STATS
@ UI_SCREEN_UPDATE
@ UI_SCREEN_SPLASH
@ UI_SCREEN_STATUS
@ UI_SCREEN_MDNS
@ UI_SCREEN_HELP
@ UI_SCREEN_ERROR
bool ui_input_expired(uint64_t deadline)
Definition tui/input.c:52
void ui_input_edit_key(char *buffer, size_t capacity, size_t *length, size_t *position, keyboard_key_t key)
Definition ui/input.c:95

References ascii_otel_ui_usage(), ASCIICHAT_OK, CLEAR_ERRNO, ui_presentation_state_t::covered, GET_OPTION, keyboard_help_check_signal_cancel(), keyboard_help_parent_screen(), keyboard_help_toggle_terminal(), log_search_insert_text(), log_search_is_entering(), media_playlist_append(), media_playlist_format(), media_playlist_parse(), MODE_DISCOVERY_SERVICE, MODE_MCP_SERVER, MODE_SERVER, media_playlist_t::paths, ui_presentation_state_t::screen, terminal_screen_logs_handle_key(), terminal_screen_logs_help_open(), ui_controller_active_fd(), ui_controller_first_use_key(), ui_controller_remove(), ui_controller_screen_live(), ui_controller_state(), ui_error_popup_key(), ui_error_popup_visible(), ui_input_edit_key(), ui_input_expired(), ui_prompt_present_kind(), ui_prompt_remove(), UI_SCREEN_ERROR, UI_SCREEN_HELP, UI_SCREEN_MDNS, UI_SCREEN_MEDIA, UI_SCREEN_NOTICE, UI_SCREEN_PROMPT, UI_SCREEN_RECONNECT, UI_SCREEN_SPLASH, UI_SCREEN_STATS, UI_SCREEN_STATUS, UI_SCREEN_SYNC, UI_SCREEN_UPDATE, ui_sync_handle_key(), update_banner_handle_key(), update_banner_is_overlay_open(), update_banner_toggle_overlay(), utf8_is_valid(), and valid.

Referenced by display_poll_keyboard(), session_render_loop(), ui_input_wait_key(), and ui_status_display_interactive().

◆ ui_input_shutdown()

void ui_input_shutdown ( void )

Definition at line 614 of file tui/input.c.

614 {
615 if (!lifecycle_destroy_once(&g_input_lifecycle))
616 return;
617 mutex_destroy(&g_input_prompt_mutex);
618 mutex_destroy(&g_input_mutex);
619 lifecycle_destroy_commit(&g_input_lifecycle);
620}

Referenced by asciichat_shared_destroy().

◆ ui_input_take_paste()

asciichat_error_t ui_input_take_paste ( char * buffer,
size_t capacity )

Copy a complete paste event. Invalid/oversized payloads fail without truncation.

Definition at line 282 of file tui/input.c.

282 {
283 if (!buffer || !capacity || !input_initialize())
284 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid paste buffer");
285 mutex_lock(&g_input_mutex);
287 if (g_events.invalid || g_events.length >= capacity ||
288 !utf8_is_valid(g_events.paste))
290 "Paste media paths or URLs without terminal controls "
291 "(maximum 8191 bytes)");
292 else
293 memcpy(buffer, g_events.paste, g_events.length + 1);
294 g_events.length = 0;
295 sodium_memzero(g_events.paste, sizeof(g_events.paste));
296 g_events.ready = false;
297 input_unlock();
298 return result;
299}

References ASCIICHAT_OK, ERROR_INVALID_PARAM, SET_ERRNO, and utf8_is_valid().

Referenced by session_handle_keyboard_input().

◆ ui_input_timeout_report()

void ui_input_timeout_report ( unsigned seconds,
const char * consequence )

Definition at line 54 of file tui/input.c.

54 {
56 int length = snprintf(message, sizeof(message),
57 "\nPrompt timed out after %u seconds; %s.\n", seconds,
58 consequence);
59 // This diagnostic must remain visible even while a background screen owns the
60 // terminal.
61 if (length > 0)
62 platform_write_all(STDERR_FILENO, message,
63 (size_t)length < sizeof(message) ? (size_t)length
64 : sizeof(message) - 1);
65 SET_ERRNO(ERROR_PROMPT_TIMEOUT, "Prompt timed out after %u seconds: %s",
66 seconds, consequence);
67}
@ ERROR_PROMPT_TIMEOUT
#define TUI_INPUT_MESSAGE_BUFFER_SIZE
Definition tui/input.c:3

References ERROR_PROMPT_TIMEOUT, SET_ERRNO, and TUI_INPUT_MESSAGE_BUFFER_SIZE.

◆ ui_input_wait_key()

keyboard_key_t ui_input_wait_key ( ui_screen_t screen,
unsigned timeout_ms )

Definition at line 603 of file tui/input.c.

603 {
604 uint64_t deadline = time_get_ns() + (uint64_t)timeout_ms * NS_PER_MS_INT;
605 do {
606 keyboard_key_t key = ui_input_read_key(screen);
607 if (key != KEY_NONE || shutdown_is_requested())
608 return key;
609 platform_sleep_ns(NS_PER_MS_INT);
610 } while (time_get_ns() < deadline);
611 return KEY_NONE;
612}
#define NS_PER_MS_INT
Definition time.h:172
bool shutdown_is_requested(void)
Check if shutdown has been requested.
Definition common.c:87
keyboard_key_t ui_input_read_key(ui_screen_t screen)
Definition tui/input.c:374

References NS_PER_MS_INT, shutdown_is_requested(), and ui_input_read_key().

Referenced by update_banner_show_prompt().