ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
options/parsing/actions.c
Go to the documentation of this file.
1
12
13/* Storage capacities in elements; text buffers include the terminating NUL. */
14#define OPTIONS_PARSING_ACTIONS_SIZE_BUFFER_SIZE 64
15#define OPTIONS_PARSING_ACTIONS_COLORS_BUFFER_SIZE 64
16#define OPTIONS_PARSING_ACTIONS_BITMASK_BUFFER_SIZE 64
17#define OPTIONS_PARSING_ACTIONS_NOTIFICATION_BUFFER_SIZE 1024
18#define OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE 4096
19
21
22#include <options/actions.h>
23#include <options/config.h>
24#include <string.h>
25#include <stddef.h>
26
28#include <ascii-chat/common.h>
30#include <ascii-chat/log/log.h>
32#include <libflags/builder.h>
33#include <options/config.h>
35#include <libflags/completions/completions.h>
36#include <libplatform/terminal.h>
37#include <libplatform/filesystem.h>
38#include <libplatform/question.h>
39#include <sys/stat.h>
40#include <ascii-chat/version.h>
45#include <libflags/manpage/manpage.h>
46#include <libflags/manpage/formatter.h>
47
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51
52// ============================================================================
53// Action Exit Helper
54// ============================================================================
55
63static _Noreturn void action_exit(int code) {
64 fflush(NULL);
65 asciichat_coverage_flush();
66 _Exit(code);
67}
68
69// ============================================================================
70// Deferred Action Tracking System
71// ============================================================================
72
79static struct {
83} g_deferred_action_state = {
84 .action = ACTION_NONE,
85 .args = {0},
86 .has_action = false,
87};
88
90 // Only remember the first action found
91 if (g_deferred_action_state.has_action) {
92 return; // Action already deferred, ignore subsequent actions
93 }
94
95 g_deferred_action_state.action = action;
96 g_deferred_action_state.has_action = true;
97
98 // Copy arguments if provided
99 if (args) {
100 memcpy(&g_deferred_action_state.args, args, sizeof(action_args_t));
101 } else {
102 memset(&g_deferred_action_state.args, 0, sizeof(action_args_t));
103 }
104}
105
107 return g_deferred_action_state.action;
108}
109
111 if (!g_deferred_action_state.has_action) {
112 return NULL;
113 }
114 return &g_deferred_action_state.args;
115}
116
117// ============================================================================
118// Webcam Action
119// ============================================================================
120
122 // Defer execution until after options are fully parsed
124}
125
132static void execute_list_webcams(void) {
133 webcam_device_info_t *devices = NULL;
134 unsigned int device_count = 0;
135
136 asciichat_error_t result = webcam_list_devices(&devices, &device_count);
137 if (result != ASCIICHAT_OK) {
138 log_error("Failed to enumerate webcam devices");
139 action_exit(ERROR_WEBCAM);
140 }
141
142 if (device_count == 0) {
143 log_plain_stdout("No webcam devices found.");
144 } else {
145 log_plain_stdout("Available Webcam Devices:");
146 for (unsigned int i = 0; i < device_count; i++) {
147 log_plain_stdout(" %u %s", devices[i].index, devices[i].name);
148 }
149 }
150
152 action_exit(0);
153}
154
155// ============================================================================
156// Audio Device Actions
157// ============================================================================
158
160 // Defer execution until after options are fully parsed
162}
163
170static void execute_list_microphones(void) {
171 audio_device_info_t *devices = NULL;
172 unsigned int device_count = 0;
173
174 asciichat_error_t result = audio_list_input_devices(&devices, &device_count);
175 if (result != ASCIICHAT_OK) {
176 log_error("Failed to enumerate audio input devices");
177 action_exit(ERROR_AUDIO);
178 }
179
180 if (device_count == 0) {
181 log_plain_stdout("No microphone devices found.");
182 } else {
183 log_plain_stdout("Available Microphone Devices:");
184 for (unsigned int i = 0; i < device_count; i++) {
185 if (devices[i].is_default_input) {
186 log_plain_stdout(" %d %s (default)", devices[i].index, devices[i].name);
187 } else {
188 log_plain_stdout(" %d %s", devices[i].index, devices[i].name);
189 }
190 }
191 }
192
193 audio_free_device_list(devices);
194 action_exit(0);
195}
196
198 // Defer execution until after options are fully parsed
200}
201
208static void execute_list_speakers(void) {
209 audio_device_info_t *devices = NULL;
210 unsigned int device_count = 0;
211
212 asciichat_error_t result = audio_list_output_devices(&devices, &device_count);
213 if (result != ASCIICHAT_OK) {
214 log_error("Failed to enumerate audio output devices");
215 action_exit(ERROR_AUDIO);
216 }
217
218 if (device_count == 0) {
219 log_plain_stdout("No speaker devices found.");
220 } else {
221 log_plain_stdout("Available Speaker Devices:");
222 for (unsigned int i = 0; i < device_count; i++) {
223 if (devices[i].is_default_output) {
224 log_plain_stdout(" %d %s (default)", devices[i].index, devices[i].name);
225 } else {
226 log_plain_stdout(" %d %s", devices[i].index, devices[i].name);
227 }
228 }
229 }
230
231 audio_free_device_list(devices);
232 action_exit(0);
233}
234
235// ============================================================================
236// Terminal Capabilities Action
237// ============================================================================
238
243 terminal_capabilities_t caps;
245
246 // Determine if we should use colored output
247 bool use_colors = terminal_should_color_output(STDOUT_FILENO, options_terminal_settings());
248
249 // Override color level if colors should not be shown
250 if (!use_colors) {
251 caps.color_level = TERM_COLOR_NONE;
252 caps.color_count = 0;
253 caps.capabilities &= ~((uint32_t)(TERM_CAP_COLOR_TRUE | TERM_CAP_COLOR_256 | TERM_CAP_COLOR_16));
254 }
255
256 // Use detected terminal size (immediate execution doesn't have parsed options yet)
257 terminal_size_t size;
258 terminal_get_size(&size);
259 unsigned short width = (unsigned short)size.cols;
260 unsigned short height = (unsigned short)size.rows;
261
262 log_color_t label_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
263 log_color_t string_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
264 log_color_t good_color = use_colors ? LOG_COLOR_INFO : LOG_COLOR_GREY;
265 log_color_t bad_color = use_colors ? LOG_COLOR_ERROR : LOG_COLOR_GREY;
266 log_color_t number_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
267
268 printf("%s\n", colored_string(LOG_COLOR_WARN, "Terminal Capabilities:"));
269
271 snprintf(size_buf, sizeof(size_buf), "%ux%u", width, height);
272 printf(" %s: %s\n", colored_string(label_color, "Terminal Size"), colored_string(number_color, size_buf));
273
274 const char *color_level_name = terminal_color_level_name(caps.color_level);
275 log_color_t color_level_color = (caps.color_level == TERM_COLOR_NONE) ? bad_color : string_color;
276 printf(" %s: %s\n", colored_string(label_color, "Color Level"), colored_string(color_level_color, (char *)color_level_name));
277
279 snprintf(colors_buf, sizeof(colors_buf), "%u", caps.color_count);
280 printf(" %s: %s\n", colored_string(label_color, "Max Colors"), colored_string(number_color, colors_buf));
281
282 log_color_t utf8_color = caps.utf8_support ? good_color : bad_color;
283 printf(" %s: %s\n", colored_string(label_color, "UTF-8 Support"), colored_string(utf8_color, (char *)(caps.utf8_support ? "Yes" : "No")));
284
285 const char *render_mode_str = "unknown";
286 if (caps.render_mode == RENDER_MODE_FOREGROUND) {
287 render_mode_str = "foreground";
288 } else if (caps.render_mode == RENDER_MODE_BACKGROUND) {
289 render_mode_str = "background";
290 } else if (caps.render_mode == RENDER_MODE_HALF_BLOCK) {
291 render_mode_str = "half-block";
292 }
293 printf(" %s: %s\n", colored_string(label_color, "Render Mode"), colored_string(string_color, (char *)render_mode_str));
294 printf(" %s: %s\n", colored_string(label_color, "TERM"), colored_string(string_color, (char *)caps.term_type));
295 printf(" %s: %s\n", colored_string(label_color, "COLORTERM"), colored_string(string_color, (char *)(strlen(caps.colorterm) ? caps.colorterm : "(not set)")));
296
297 log_color_t reliable_color = caps.detection_reliable ? good_color : bad_color;
298 printf(" %s: %s\n", colored_string(label_color, "Detection Reliable"), colored_string(reliable_color, (char *)(caps.detection_reliable ? "Yes" : "No")));
299
301 snprintf(bitmask_buf, sizeof(bitmask_buf), "0x%08x", caps.capabilities);
302 printf(" %s: %s\n", colored_string(label_color, "Capabilities Bitmask"), colored_string(number_color, bitmask_buf));
303
304 fflush(stdout);
305 action_exit(0);
306}
307
309 // Defer execution until after options are fully parsed and dimensions updated
310 // This ensures --width and --height flags are properly reflected in the output
312}
313
314// ============================================================================
315// Update Check Action
316// ============================================================================
317
322 printf("Checking for updates...\n");
325 if (err != ASCIICHAT_OK) {
326 printf("\nFailed to check for updates.\n\n");
327 action_exit(1);
328 }
329 if (result.update_available) {
331 update_check_format_notification(&result, notification, sizeof(notification));
332 printf("\n%s\n\n", notification);
333 } else {
334 printf("\nYou are already on the latest version: %s (%.8s)\n\n", result.current_version, result.current_sha);
335 }
336 action_exit(0);
337}
338
340 // Defer execution until after options are fully parsed
342}
343
354static void execute_show_capabilities(void) {
355 terminal_capabilities_t caps;
357
358 // Determine if we should use colored output
359 bool use_colors = terminal_should_color_output(STDOUT_FILENO, options_terminal_settings());
360
361 // Override color level if colors should not be shown
362 if (!use_colors) {
363 // User requested no colors or output is piped or CLAUDECODE is set
364 caps.color_level = TERM_COLOR_NONE;
365 caps.color_count = 0;
366 caps.capabilities &= ~((uint32_t)(TERM_CAP_COLOR_TRUE | TERM_CAP_COLOR_256 | TERM_CAP_COLOR_16));
367 }
368
369 // Get width and height from parsed options (respects --width and --height flags)
370 const options_t *opts = options_get();
371 unsigned short width = opts ? (unsigned short)opts->width : 110;
372 unsigned short height = opts ? (unsigned short)opts->height : 70;
373
374 // Color scheme:
375 // - Labels: grey
376 // - Regular string values: blue (DEBUG - cyan/blue)
377 // - Affirmative values (Yes, true): green (INFO)
378 // - Bad/negative values (No, false, error): red (ERROR)
379 // - Numbers and hex: magenta (FATAL)
380 log_color_t label_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
381 log_color_t string_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
382 log_color_t good_color = use_colors ? LOG_COLOR_INFO : LOG_COLOR_GREY;
383 log_color_t bad_color = use_colors ? LOG_COLOR_ERROR : LOG_COLOR_GREY;
384 log_color_t number_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
385
386 printf("%s\n", colored_string(LOG_COLOR_WARN, "Terminal Capabilities:"));
387
389 snprintf(size_buf, sizeof(size_buf), "%ux%u", width, height);
390 printf(" %s: %s\n", colored_string(label_color, "Terminal Size"), colored_string(number_color, size_buf));
391
392 // Color Level: green if good, red if none/bad
393 const char *color_level_name = terminal_color_level_name(caps.color_level);
394 log_color_t color_level_color = (caps.color_level == TERM_COLOR_NONE) ? bad_color : string_color;
395 printf(" %s: %s\n", colored_string(label_color, "Color Level"), colored_string(color_level_color, (char *)color_level_name));
396
398 snprintf(colors_buf, sizeof(colors_buf), "%u", caps.color_count);
399 printf(" %s: %s\n", colored_string(label_color, "Max Colors"), colored_string(number_color, colors_buf));
400
401 // UTF-8: green if Yes, red if No
402 log_color_t utf8_color = caps.utf8_support ? good_color : bad_color;
403 printf(" %s: %s\n", colored_string(label_color, "UTF-8 Support"), colored_string(utf8_color, (char *)(caps.utf8_support ? "Yes" : "No")));
404
405 const char *render_mode_str = "unknown";
406 if (caps.render_mode == RENDER_MODE_FOREGROUND) {
407 render_mode_str = "foreground";
408 } else if (caps.render_mode == RENDER_MODE_BACKGROUND) {
409 render_mode_str = "background";
410 } else if (caps.render_mode == RENDER_MODE_HALF_BLOCK) {
411 render_mode_str = "half-block";
412 }
413 printf(" %s: %s\n", colored_string(label_color, "Render Mode"), colored_string(string_color, (char *)render_mode_str));
414 printf(" %s: %s\n", colored_string(label_color, "TERM"), colored_string(string_color, (char *)caps.term_type));
415 printf(" %s: %s\n", colored_string(label_color, "COLORTERM"), colored_string(string_color, (char *)(strlen(caps.colorterm) ? caps.colorterm : "(not set)")));
416
417 // Detection Reliable: green if Yes, red if No
418 log_color_t reliable_color = caps.detection_reliable ? good_color : bad_color;
419 printf(" %s: %s\n", colored_string(label_color, "Detection Reliable"), colored_string(reliable_color, (char *)(caps.detection_reliable ? "Yes" : "No")));
420
422 snprintf(bitmask_buf, sizeof(bitmask_buf), "0x%08x", caps.capabilities);
423 printf(" %s: %s\n", colored_string(label_color, "Capabilities Bitmask"), colored_string(number_color, bitmask_buf));
424
425 fflush(stdout);
426
427 action_exit(0);
428}
429
430// ============================================================================
431// Version Action
432// ============================================================================
433
435 bool use_colors = terminal_should_color_output(STDOUT_FILENO, options_terminal_settings());
436 if (use_colors) {
437 printf("%s %s (%s, %s)\n", colored_string(LOG_COLOR_WARN, "ascii-chat"), colored_string(LOG_COLOR_INFO, (char *)ASCII_CHAT_VERSION_FULL),
438 colored_string(LOG_COLOR_DEBUG, (char *)ASCII_CHAT_BUILD_TYPE), colored_string(LOG_COLOR_GREY, (char *)ASCII_CHAT_BUILD_DATE));
439 } else {
440 printf("ascii-chat %s (%s, %s)\n", ASCII_CHAT_VERSION_FULL, ASCII_CHAT_BUILD_TYPE, ASCII_CHAT_BUILD_DATE);
441 }
442
443 action_exit(0);
444}
445
446// ============================================================================
447// Help Actions
448// ============================================================================
449
451 usage(stdout, MODE_SERVER);
452 action_exit(0);
453}
454
456 usage(stdout, MODE_CLIENT);
457 action_exit(0);
458}
459
461 usage(stdout, MODE_MIRROR);
462 action_exit(0);
463}
464
467 action_exit(0);
468}
469
471 usage(stdout, MODE_DISCOVERY);
472 action_exit(0);
473}
474
475// ============================================================================
476// Man Page Generation Action
477// ============================================================================
478
479void action_create_manpage(const char *output_path) {
481 if (!builder)
482 action_exit(ERROR_FILE_OPERATION);
483 FILE *output = stdout;
484 if (output_path && *output_path && strcmp(output_path, "-") != 0) {
485 output = NULL;
486 const int fd = platform_open("manpage_output", output_path, PLATFORM_O_WRONLY | PLATFORM_O_CREAT | PLATFORM_O_TRUNC, FILE_PERM_PRIVATE);
487 if (fd >= 0)
488 output = platform_fdopen("manpage_output_stream", fd, "w");
489 }
490 if (!output) {
491 flags_schema_builder_destroy(builder);
492 action_exit(ERROR_FILE_OPERATION);
493 }
494 const flags_manpage_metadata_t metadata = {.program_name = "ascii-chat", .section = "1", .description = "Video chat in your terminal"};
495 const bool written = flags_manpage_write(flags_schema_builder_schema(builder), &metadata, output) && flags_manpage_write_environment(flags_schema_builder_schema(builder), "ASCII_CHAT_", output);
496 if (written) {
497 fputs("\n.SH MCP SERVER\n"
498 "ascii-chat mcp-server exposes ASCII rendering tools through the Model Context Protocol.\n"
499 "Use the stdio transport for an MCP client-launched process, or \\fB--transport http\\fR\n"
500 "to serve Streamable HTTP at the configured address and port.\n\n"
501 "Example:\n\n"
502 "ascii-chat mcp-server --transport stdio\n\n"
503 "MCP mode reserves stdin for protocol messages and skips startup update checks.\n",
504 output);
505 }
506 if (output != stdout)
507 fclose(output);
508 flags_schema_builder_destroy(builder);
509 if (!written)
510 action_exit(ERROR_FILE_OPERATION);
511 log_info("Man page written to %s", output_path && *output_path ? output_path : "stdout");
512
513 action_exit(0);
514}
515
516// ============================================================================
517// Config Creation Action
518// ============================================================================
519
520void action_create_config(const char *output_path) {
521 const char *config_path = NULL;
522
523 // Determine output path: use provided path, or NULL for stdout
524 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
525 // User provided explicit path - use it as-is
526 config_path = output_path;
527 } else {
528 // No path or "-" means stdout
529 config_path = NULL;
530 }
531
532 // Create config with default options
533 asciichat_error_t result = config_create_default(config_path);
534 if (result != ASCIICHAT_OK) {
536 if (HAS_ERRNO(&err_ctx)) {
537 log_error("Error creating config: %s", err_ctx.context_message);
538 } else {
539 log_error("Failed to create config file");
540 }
541 action_exit(ERROR_CONFIG);
542 }
543
544 if (config_path) {
545 log_info("Created default config file at: %s", config_path);
546 } else {
547 log_info("Config written to stdout");
548 }
549 action_exit(0);
550}
551
552// ============================================================================
553// Shell Completions Action
554// ============================================================================
555
556void action_completions(const char *shell_name, const char *output_path) {
557 if (!shell_name || strlen(shell_name) == 0) {
558 log_error("--completions requires shell name (bash, fish, zsh, powershell)");
559 action_exit(ERROR_USAGE);
560 }
561
562 flags_completion_shell_t format = flags_completion_shell_parse(shell_name);
563 if (format == FLAGS_COMPLETION_UNKNOWN) {
564 log_error("Unknown shell '%s' (supported: bash, fish, zsh, powershell)", shell_name);
565 action_exit(ERROR_USAGE);
566 }
567
568 FILE *output = stdout;
569 bool should_close = false;
570
571 // Determine output: use provided path if given and not "-", otherwise stdout
572 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
573 // Check if file already exists and prompt for confirmation
574 struct stat st;
575 if (stat(output_path, &st) == 0) {
576 // File exists - ask user if they want to overwrite
577 log_plain("Completions file already exists: %s", output_path);
578
580 safe_snprintf(question, sizeof(question), "File already exists: %s\n\nOverwrite", output_path);
582 bool overwrite = ui_notice_confirm_kind(UI_PROMPT_COMPLETION_OVERWRITE, UI_NOTICE_WARNING, question, 30); // Default to No
583 if (!overwrite) {
584 log_plain("Completions generation cancelled.");
586 action_exit(errno_peek_since(prompt_scope, &context) && context.code == ERROR_PROMPT_TIMEOUT ? ERROR_PROMPT_TIMEOUT : 0);
587 }
588
589 log_plain("Overwriting existing completions file...");
590 }
591
592 output = platform_fopen("file_stream", output_path, "w");
593 if (!output) {
594 log_error("Failed to open %s for writing", output_path);
595 action_exit(ERROR_FILE_OPERATION);
596 }
597 should_close = true;
598 }
599
600 flags_schema_builder_t *builder = flags_schema_builder_create();
602 if (builder)
603 flags_schema_builder_destroy(builder);
604 if (should_close)
605 fclose(output);
606 log_error("Failed to build completion schema");
607 action_exit(ERROR_CONFIG);
608 }
609 const bool written = flags_completion_write(flags_schema_builder_schema(builder), "ascii-chat", format, output);
610 flags_schema_builder_destroy(builder);
611 asciichat_error_t result = written ? ASCIICHAT_OK : SET_ERRNO(ERROR_FILE_OPERATION, "Failed to write completion script");
612
613 if (should_close) {
614 fclose(output);
615 }
616
617 if (result != ASCIICHAT_OK) {
618 log_error("Failed to generate %s completions", flags_completion_shell_name(format));
619 action_exit(ERROR_USAGE);
620 }
621
622 // Silently exit - completions are written (either to file or stdout)
623 action_exit(0);
624}
625
632static void execute_check_update(void) {
633 printf("Checking for updates...\n");
634
637
638 if (err != ASCIICHAT_OK) {
640 if (HAS_ERRNO(&ctx)) {
641 fprintf(stderr, "Update check failed: %s\n", ctx.context_message);
642 }
643 action_exit(1);
644 }
645
646 // Display results
647 if (result.update_available) {
649 update_check_format_notification(&result, notification, sizeof(notification));
650 printf("\n%s\n\n", notification);
651 } else {
652 printf("\nYou are already on the latest version: %s (%.8s)\n\n", result.current_version, result.current_sha);
653 }
654
655 action_exit(0);
656}
657
658// ============================================================================
659// Deferred Action Execution
660// ============================================================================
661
664
665 switch (action) {
666 case ACTION_NONE:
667 // No action to execute
668 break;
669
671 execute_list_webcams();
672 break;
673
675 execute_list_microphones();
676 break;
677
679 execute_list_speakers();
680 break;
681
683 execute_show_capabilities();
684 break;
685
687 execute_check_update();
688 break;
689
690 default:
691 log_warn("Unknown deferred action: %d", action);
692 break;
693 }
694}
695
696option_action_fn options_action_callback(const char *name, bool immediate) {
697 static const struct {
698 const char *name;
699 option_action_fn callback;
700 option_action_fn early_callback;
701 } actions[] = {
705 };
706 if (!name)
707 return NULL;
708 for (size_t i = 0; i < sizeof(actions) / sizeof(actions[0]); ++i) {
709 if (strcmp(name, actions[i].name) == 0)
710 return immediate ? actions[i].early_callback : actions[i].callback;
711 }
712 return NULL;
713}
Action option callbacks for ascii-chat.
deferred_action_t
action args is intentionally a small, concrete record. Fields such as output_path,...
Definition actions.h:25
@ ACTION_CHECK_UPDATE
Definition actions.h:31
@ ACTION_LIST_SPEAKERS
Definition actions.h:29
@ ACTION_LIST_MICROPHONES
Definition actions.h:28
@ ACTION_NONE
Definition actions.h:26
@ ACTION_LIST_WEBCAMS
Definition actions.h:27
@ ACTION_SHOW_CAPABILITIES
Definition actions.h:30
void(* option_action_fn)(void)
Definition actions.h:234
bool errno_peek_since(asciichat_errno_scope_t scope, asciichat_error_context_t *out)
asciichat_errno_scope_t errno_checkpoint(void)
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define SET_ERRNO(code,...)
#define HAS_ERRNO(context)
log_color_t
Definition color.h:6
@ LOG_COLOR_GREY
Definition color.h:13
@ LOG_COLOR_ERROR
Definition color.h:11
@ LOG_COLOR_DEBUG
Definition color.h:8
@ LOG_COLOR_INFO
Definition color.h:9
@ LOG_COLOR_WARN
Definition color.h:10
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24
int platform_open(const char *name, const char *pathname, int flags,...)
Definition filesystem.c:65
FILE * platform_fopen(const char *name, const char *filename, const char *mode)
Definition filesystem.c:18
void audio_free_device_list(audio_device_info_t *devices)
Free device list allocated by audio_list_input_devices/audio_list_output_devices.
asciichat_error_t audio_list_input_devices(audio_device_info_t **out_devices, unsigned int *out_count)
List available audio input devices (microphones).
asciichat_error_t audio_list_output_devices(audio_device_info_t **out_devices, unsigned int *out_count)
List available audio output devices (speakers).
unsigned int uint32_t
flags_schema_builder_t * options_config_build_flags_schema(option_mode_bitmask_t mode_mask)
asciichat_error_t config_create_default(const char *config_path)
Create default configuration file with all default values.
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_PROMPT_TIMEOUT
@ ERROR_AUDIO
Definition error_codes.h:66
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_CONFIG
Definition error_codes.h:56
@ ERROR_FILE_OPERATION
@ ERROR_USAGE
Definition error_codes.h:52
@ ERROR_WEBCAM
Definition error_codes.h:63
#define log_warn(...)
Log a WARN message.
Definition log/log.h:591
#define log_error(...)
Log an ERROR message.
Definition log/log.h:604
#define log_plain_stdout(...)
Plain logging to stdout with newline.
Definition log/log.h:649
#define log_info(...)
Log an INFO message.
Definition log/log.h:578
#define log_plain(...)
Plain logging - writes to both log file and stderr without timestamps or log levels.
Definition log/log.h:635
asciichat_error_t update_check_perform(update_check_result_t *result)
Check for updates from GitHub releases API.
void update_check_format_notification(const update_check_result_t *result, char *buffer, size_t buffer_size)
Format update notification message.
struct options_state options_t
Immutable, RCU-published snapshot of the application's runtime configuration.
const options_t * options_get(void)
Get pointer to current options struct (lock-free, thread-safe).
Definition rcu.c:513
void usage(FILE *desc, asciichat_mode_t mode)
Print usage information for a specific mode.
#define options_terminal_settings()
Definition options.h:1287
@ MODE_CLIENT
Client mode - network client options.
Definition options.h:918
@ 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
@ MODE_MIRROR
Mirror mode - local webcam viewing (no network).
Definition options.h:919
@ MODE_DISCOVERY
Discovery mode - participant that can dynamically become host.
Definition options.h:921
@ OPTION_MODE_ALL
All modes + binary.
Definition options.h:943
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
asciichat_error_t webcam_list_devices(webcam_device_info_t **out_devices, unsigned int *out_count)
Enumerate available webcam devices.
void webcam_free_device_list(webcam_device_info_t *devices)
Free device list returned by webcam_list_devices().
🔊 Audio Capture and Playback Interface for ascii-chat
⚙️ Common definitions, error codes, macros, and types shared throughout the application
Central registry of all command-line options with mode applicability.
struct flags_schema_builder flags_schema_builder_t
📝 Logging API with multiple log levels and terminal output control
bool ui_notice_confirm_kind(ui_prompt_kind_t kind, ui_notice_severity_t severity, const char *text, unsigned timeout_seconds)
Definition notice.c:548
@ UI_NOTICE_WARNING
Definition notice.h:15
TOML configuration file support for ascii-chat.
option_action_fn options_action_callback(const char *name, bool immediate)
void action_check_update_immediate(void)
Execute update check immediately (for early binary-level execution).
#define OPTIONS_PARSING_ACTIONS_BITMASK_BUFFER_SIZE
#define OPTIONS_PARSING_ACTIONS_NOTIFICATION_BUFFER_SIZE
const action_args_t * actions_get_args(void)
Get the arguments for the deferred action.
void action_check_update(void)
Check for updates and display results.
deferred_action_t actions_get_deferred(void)
Get the deferred action (if any) that was set.
void actions_defer(deferred_action_t action, const action_args_t *args)
Set which action to defer until options are fully initialized.
bool has_action
void action_help_acds(void)
Show discovery-service mode help and exit.
void action_show_capabilities(void)
Show terminal capabilities and exit.
void action_help_server(void)
Show server mode help and exit.
void action_help_discovery(void)
Show discovery mode help and exit.
action_args_t args
#define OPTIONS_PARSING_ACTIONS_COLORS_BUFFER_SIZE
void action_create_manpage(const char *output_path)
Generate man page template from options builder.
void action_completions(const char *shell_name, const char *output_path)
Generate shell completions and output to stdout or file.
deferred_action_t action
void action_list_microphones(void)
List available microphone devices and exit.
void action_show_version(void)
Show version information and exit.
#define OPTIONS_PARSING_ACTIONS_SIZE_BUFFER_SIZE
void action_help_mirror(void)
Show mirror mode help and exit.
void action_create_config(const char *output_path)
Create default configuration file and exit.
void action_list_webcams(void)
List available webcam devices and exit.
void action_list_speakers(void)
List available speaker devices and exit.
void action_help_client(void)
Show client mode help and exit.
void actions_execute_deferred(void)
Execute the deferred action (if any).
void action_show_capabilities_immediate(void)
Execute show capabilities immediately (for early binary-level execution).
#define OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE
📂 Path Manipulation Utilities
asciichat_error_t registry_add_all_to_flags_builder(flags_schema_builder_t *builder, option_mode_bitmask_t mode_mask)
Definition public_api.c:84
static bool size_t index
Definition queries.h:10
bool terminal_should_color_output(int fd, const terminal_options_t *options)
void detect_terminal_capabilities_into(const terminal_options_t *options, terminal_capabilities_t *out)
int terminal_get_size(terminal_size_t *size)
🔤 String Manipulation and Shell Escaping Utilities
Action argument structure.
Definition actions.h:40
When code needs to work with asciichat errno snapshot, it keeps total, copied here instead of scatter...
Audio device information structure.
int height
Terminal height in characters (int for OPTION_TYPE_INT compat).
Definition options.h:992
int width
Terminal width in characters (int for OPTION_TYPE_INT compat).
Definition options.h:991
update check result keeps the values that move through the subsystem: update_available,...
char current_sha[41]
Current commit SHA.
char current_version[64]
string
bool update_available
True if newer version exists.
Webcam device information structure.
Definition webcam.h:93
🔄 Update checker for GitHub releases with DNS connectivity test and cache