ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
lib/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 = size.cols;
260 unsigned short height = 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 ? opts->width : 110;
372 unsigned short height = opts ? 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 (output != stdout)
497 fclose(output);
498 flags_schema_builder_destroy(builder);
499 if (!written)
500 action_exit(ERROR_FILE_OPERATION);
501 log_info("Man page written to %s", output_path && *output_path ? output_path : "stdout");
502
503 action_exit(0);
504}
505
506// ============================================================================
507// Config Creation Action
508// ============================================================================
509
510void action_create_config(const char *output_path) {
511 const char *config_path = NULL;
512
513 // Determine output path: use provided path, or NULL for stdout
514 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
515 // User provided explicit path - use it as-is
516 config_path = output_path;
517 } else {
518 // No path or "-" means stdout
519 config_path = NULL;
520 }
521
522 // Create config with default options
523 asciichat_error_t result = config_create_default(config_path);
524 if (result != ASCIICHAT_OK) {
526 if (HAS_ERRNO(&err_ctx)) {
527 log_error("Error creating config: %s", err_ctx.context_message);
528 } else {
529 log_error("Failed to create config file");
530 }
531 action_exit(ERROR_CONFIG);
532 }
533
534 if (config_path) {
535 log_info("Created default config file at: %s", config_path);
536 } else {
537 log_info("Config written to stdout");
538 }
539 action_exit(0);
540}
541
542// ============================================================================
543// Shell Completions Action
544// ============================================================================
545
546void action_completions(const char *shell_name, const char *output_path) {
547 if (!shell_name || strlen(shell_name) == 0) {
548 log_error("--completions requires shell name (bash, fish, zsh, powershell)");
549 action_exit(ERROR_USAGE);
550 }
551
552 flags_completion_shell_t format = flags_completion_shell_parse(shell_name);
553 if (format == FLAGS_COMPLETION_UNKNOWN) {
554 log_error("Unknown shell '%s' (supported: bash, fish, zsh, powershell)", shell_name);
555 action_exit(ERROR_USAGE);
556 }
557
558 FILE *output = stdout;
559 bool should_close = false;
560
561 // Determine output: use provided path if given and not "-", otherwise stdout
562 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
563 // Check if file already exists and prompt for confirmation
564 struct stat st;
565 if (stat(output_path, &st) == 0) {
566 // File exists - ask user if they want to overwrite
567 log_plain("Completions file already exists: %s", output_path);
568
570 safe_snprintf(question, sizeof(question), "File already exists: %s\n\nOverwrite", output_path);
572 bool overwrite = ui_notice_confirm_kind(UI_PROMPT_COMPLETION_OVERWRITE, UI_NOTICE_WARNING, question, 30); // Default to No
573 if (!overwrite) {
574 log_plain("Completions generation cancelled.");
576 action_exit(errno_peek_since(prompt_scope, &context) && context.code == ERROR_PROMPT_TIMEOUT ? ERROR_PROMPT_TIMEOUT : 0);
577 }
578
579 log_plain("Overwriting existing completions file...");
580 }
581
582 output = platform_fopen("file_stream", output_path, "w");
583 if (!output) {
584 log_error("Failed to open %s for writing", output_path);
585 action_exit(ERROR_FILE_OPERATION);
586 }
587 should_close = true;
588 }
589
590 flags_schema_builder_t *builder = flags_schema_builder_create();
592 if (builder)
593 flags_schema_builder_destroy(builder);
594 if (should_close)
595 fclose(output);
596 log_error("Failed to build completion schema");
597 action_exit(ERROR_CONFIG);
598 }
599 const bool written = flags_completion_write(flags_schema_builder_schema(builder), "ascii-chat", format, output);
600 flags_schema_builder_destroy(builder);
601 asciichat_error_t result = written ? ASCIICHAT_OK : SET_ERRNO(ERROR_FILE_OPERATION, "Failed to write completion script");
602
603 if (should_close) {
604 fclose(output);
605 }
606
607 if (result != ASCIICHAT_OK) {
608 log_error("Failed to generate %s completions", flags_completion_shell_name(format));
609 action_exit(ERROR_USAGE);
610 }
611
612 // Silently exit - completions are written (either to file or stdout)
613 action_exit(0);
614}
615
622static void execute_check_update(void) {
623 printf("Checking for updates...\n");
624
627
628 if (err != ASCIICHAT_OK) {
630 if (HAS_ERRNO(&ctx)) {
631 fprintf(stderr, "Update check failed: %s\n", ctx.context_message);
632 }
633 action_exit(1);
634 }
635
636 // Display results
637 if (result.update_available) {
639 update_check_format_notification(&result, notification, sizeof(notification));
640 printf("\n%s\n\n", notification);
641 } else {
642 printf("\nYou are already on the latest version: %s (%.8s)\n\n", result.current_version, result.current_sha);
643 }
644
645 action_exit(0);
646}
647
648// ============================================================================
649// Deferred Action Execution
650// ============================================================================
651
654
655 switch (action) {
656 case ACTION_NONE:
657 // No action to execute
658 break;
659
661 execute_list_webcams();
662 break;
663
665 execute_list_microphones();
666 break;
667
669 execute_list_speakers();
670 break;
671
673 execute_show_capabilities();
674 break;
675
677 execute_check_update();
678 break;
679
680 default:
681 log_warn("Unknown deferred action: %d", action);
682 break;
683 }
684}
685
686option_action_fn options_action_callback(const char *name, bool immediate) {
687 static const struct {
688 const char *name;
689 option_action_fn callback;
690 option_action_fn early_callback;
691 } actions[] = {
695 };
696 if (!name)
697 return NULL;
698 for (size_t i = 0; i < sizeof(actions) / sizeof(actions[0]); ++i) {
699 if (strcmp(name, actions[i].name) == 0)
700 return immediate ? actions[i].early_callback : actions[i].callback;
701 }
702 return NULL;
703}
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:24
@ ACTION_CHECK_UPDATE
Definition actions.h:30
@ ACTION_LIST_SPEAKERS
Definition actions.h:28
@ ACTION_LIST_MICROPHONES
Definition actions.h:27
@ ACTION_NONE
Definition actions.h:25
@ ACTION_LIST_WEBCAMS
Definition actions.h:26
@ ACTION_SHOW_CAPABILITIES
Definition actions.h:29
void(* option_action_fn)(void)
Definition actions.h:228
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)
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:615
log_color_t
Color enum for logging - indexes into color arrays.
Definition log/log.h:146
#define log_error(...)
Log an ERROR message.
Definition log/log.h:628
#define log_plain_stdout(...)
Plain logging to stdout with newline.
Definition log/log.h:673
#define log_info(...)
Log an INFO message.
Definition log/log.h:602
#define log_plain(...)
Plain logging - writes to both log file and stderr without timestamps or log levels.
Definition log/log.h:659
@ LOG_COLOR_GREY
Definition log/log.h:153
@ LOG_COLOR_ERROR
Definition log/log.h:151
@ LOG_COLOR_DEBUG
Definition log/log.h:148
@ LOG_COLOR_INFO
Definition log/log.h:149
@ LOG_COLOR_WARN
Definition log/log.h:150
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:495
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
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.
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
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:479
@ UI_NOTICE_WARNING
Definition notice.h:13
TOML configuration file support for ascii-chat.
📂 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:8
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:38
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]
Current version 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