ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
actions.c File Reference

Action option callbacks for ascii-chat. More...

Go to the source code of this file.

Macros

#define OPTIONS_PARSING_ACTIONS_SIZE_BUFFER_SIZE   64
#define OPTIONS_PARSING_ACTIONS_COLORS_BUFFER_SIZE   64
#define OPTIONS_PARSING_ACTIONS_BITMASK_BUFFER_SIZE   64
#define OPTIONS_PARSING_ACTIONS_NOTIFICATION_BUFFER_SIZE   1024
#define OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE   4096

Functions

void actions_defer (deferred_action_t action, const action_args_t *args)
 Set which action to defer until options are fully initialized.
deferred_action_t actions_get_deferred (void)
 Get the deferred action (if any) that was set.
const action_args_t * actions_get_args (void)
 Get the arguments for the deferred action.
void action_list_webcams (void)
 List available webcam devices and exit.
void action_list_microphones (void)
 List available microphone devices and exit.
void action_list_speakers (void)
 List available speaker devices and exit.
void action_show_capabilities_immediate (void)
 Execute show capabilities immediately (for early binary-level execution).
void action_show_capabilities (void)
 Show terminal capabilities and exit.
void action_check_update_immediate (void)
 Execute update check immediately (for early binary-level execution).
void action_check_update (void)
 Check for updates and display results.
void action_show_version (void)
 Show version information and exit.
void action_help_server (void)
 Show server mode help and exit.
void action_help_client (void)
 Show client mode help and exit.
void action_help_mirror (void)
 Show mirror mode help and exit.
void action_help_acds (void)
 Show discovery-service mode help and exit.
void action_help_discovery (void)
 Show discovery mode help and exit.
void action_create_manpage (const char *output_path)
 Generate man page template from options builder.
void action_create_config (const char *output_path)
 Create default configuration file and exit.
void action_completions (const char *shell_name, const char *output_path)
 Generate shell completions and output to stdout or file.
void actions_execute_deferred (void)
 Execute the deferred action (if any).
option_action_fn options_action_callback (const char *name, bool immediate)

Detailed Description

Action option callbacks for ascii-chat.

Action options are deferred until after all options are fully parsed and initialized. This ensures that options like –width and –height are properly reflected in action output (e.g., –show-capabilities displays the final terminal dimensions).

Examples: –list-webcams, –list-microphones, –list-speakers, –show-capabilities

Definition in file actions.c.

Macro Definition Documentation

◆ OPTIONS_PARSING_ACTIONS_BITMASK_BUFFER_SIZE

#define OPTIONS_PARSING_ACTIONS_BITMASK_BUFFER_SIZE   64

Definition at line 16 of file actions.c.

Referenced by action_show_capabilities_immediate().

◆ OPTIONS_PARSING_ACTIONS_COLORS_BUFFER_SIZE

#define OPTIONS_PARSING_ACTIONS_COLORS_BUFFER_SIZE   64

Definition at line 15 of file actions.c.

Referenced by action_show_capabilities_immediate().

◆ OPTIONS_PARSING_ACTIONS_NOTIFICATION_BUFFER_SIZE

#define OPTIONS_PARSING_ACTIONS_NOTIFICATION_BUFFER_SIZE   1024

Definition at line 17 of file actions.c.

Referenced by action_check_update_immediate().

◆ OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE

#define OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE   4096

Definition at line 18 of file actions.c.

Referenced by action_completions().

◆ OPTIONS_PARSING_ACTIONS_SIZE_BUFFER_SIZE

#define OPTIONS_PARSING_ACTIONS_SIZE_BUFFER_SIZE   64

Definition at line 14 of file actions.c.

Referenced by action_show_capabilities_immediate().

Function Documentation

◆ action_check_update()

void action_check_update ( void )

Check for updates and display results.

Performs update check against GitHub releases API and displays results. Exits with code 0 on success, 1 on error.

Definition at line 341 of file actions.c.

341 {
342 // Defer execution until after options are fully parsed
344}
void actions_defer(deferred_action_t action, const action_args_t *args)
Set which action to defer until options are fully initialized.
Definition actions.c:86
@ ACTION_CHECK_UPDATE
Definition actions.h:24

References ACTION_CHECK_UPDATE, and actions_defer().

Referenced by options_action_callback().

◆ action_check_update_immediate()

void action_check_update_immediate ( void )

Execute update check immediately (for early binary-level execution).

Execute update check immediately (for binary-level execution).

Definition at line 323 of file actions.c.

323 {
324 printf("Checking for updates...\n");
327 if (err != ASCIICHAT_OK) {
328 printf("\nFailed to check for updates.\n\n");
329 action_exit(1);
330 }
331 if (result.update_available) {
333 update_check_format_notification(&result, notification, sizeof(notification));
334 printf("\n%s\n\n", notification);
335 } else {
336 printf("\nYou are already on the latest version: %s (%.8s)\n\n", result.current_version, result.current_sha);
337 }
338 action_exit(0);
339}
#define OPTIONS_PARSING_ACTIONS_NOTIFICATION_BUFFER_SIZE
Definition actions.c:17
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ASCIICHAT_OK
Definition error_codes.h:46
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.
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.

References ASCIICHAT_OK, update_check_result_t::current_sha, update_check_result_t::current_version, OPTIONS_PARSING_ACTIONS_NOTIFICATION_BUFFER_SIZE, update_check_result_t::update_available, update_check_format_notification(), and update_check_perform().

Referenced by options_action_callback().

◆ action_completions()

void action_completions ( const char * shell_name,
const char * output_path )

Generate shell completions and output to stdout or file.

Generates shell completion script for the specified shell (bash, fish, zsh, powershell). Output is dynamically generated from the options registry, ensuring completions are always in sync with current options. Outputs to stdout by default, or to specified file path if provided. Prompts for overwrite confirmation if file already exists. Exits with code 0 on success, 1 on error.

Parameters
shell_nameShell name: "bash", "fish", "zsh", or "powershell"
output_pathOptional file path to write completions to. NULL or empty string = stdout.

Definition at line 584 of file actions.c.

584 {
585 if (!shell_name || strlen(shell_name) == 0) {
586 log_error("--completions requires shell name (bash, fish, zsh, powershell)");
587 action_exit(ERROR_USAGE);
588 }
589
591 if (format == COMPLETION_FORMAT_UNKNOWN) {
592 log_error("Unknown shell '%s' (supported: bash, fish, zsh, powershell)", shell_name);
593 action_exit(ERROR_USAGE);
594 }
595
596 FILE *output = stdout;
597 bool should_close = false;
598
599 // Determine output: use provided path if given and not "-", otherwise stdout
600 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
601 // Check if file already exists and prompt for confirmation
602 struct stat st;
603 if (stat(output_path, &st) == 0) {
604 // File exists - ask user if they want to overwrite
605 log_plain("Completions file already exists: %s", output_path);
606
608 safe_snprintf(question, sizeof(question), "File already exists: %s\n\nOverwrite", output_path);
610 bool overwrite =
611 ui_notice_confirm_kind(UI_PROMPT_COMPLETION_OVERWRITE, UI_NOTICE_WARNING, question, 30); // Default to No
612 if (!overwrite) {
613 log_plain("Completions generation cancelled.");
615 action_exit(errno_peek_since(prompt_scope, &context) && context.code == ERROR_PROMPT_TIMEOUT
617 : 0);
618 }
619
620 log_plain("Overwriting existing completions file...");
621 }
622
623 output = platform_fopen("file_stream", output_path, "w");
624 if (!output) {
625 log_error("Failed to open %s for writing", output_path);
626 action_exit(ERROR_FILE_OPERATION);
627 }
628 should_close = true;
629 }
630
631 asciichat_error_t result = completions_generate_for_shell(format, output);
632
633 if (should_close) {
634 fclose(output);
635 }
636
637 if (result != ASCIICHAT_OK) {
638 log_error("Failed to generate %s completions", completions_get_shell_name(format));
639 action_exit(ERROR_USAGE);
640 }
641
642 // Silently exit - completions are written (either to file or stdout)
643 action_exit(0);
644}
#define OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE
Definition actions.c:18
bool errno_peek_since(asciichat_errno_scope_t scope, asciichat_error_context_t *out)
asciichat_errno_scope_t errno_checkpoint(void)
completion_format_t completions_parse_shell_name(const char *shell_name)
Parse shell name string to completion format.
Definition completions.c:58
asciichat_error_t completions_generate_for_shell(completion_format_t format, FILE *output)
Generate shell completions and write to output stream.
Definition completions.c:24
const char * completions_get_shell_name(completion_format_t format)
Get human-readable shell name for format.
Definition completions.c:43
completion_format_t
Supported shell completion formats.
Definition completions.h:66
@ COMPLETION_FORMAT_UNKNOWN
Definition completions.h:71
@ ERROR_PROMPT_TIMEOUT
@ ERROR_FILE_OPERATION
@ ERROR_USAGE
Definition error_codes.h:48
#define log_error(...)
Log an ERROR message.
Definition log/log.h:634
#define log_plain(...)
Plain logging - writes to both log file and stderr without timestamps or log levels.
Definition log/log.h:665
int safe_snprintf(char *buffer, size_t buffer_size, const char *format,...)
Platform-safe snprintf wrapper.
bool ui_notice_confirm_kind(ui_prompt_kind_t kind, ui_notice_severity_t severity, const char *text, unsigned timeout_seconds)
Definition notice.c:498
@ UI_NOTICE_WARNING
Definition notice.h:11
When code needs to work with asciichat errno snapshot, it keeps total, copied here instead of scatter...

References ASCIICHAT_OK, asciichat_error_context_t::code, COMPLETION_FORMAT_UNKNOWN, completions_generate_for_shell(), completions_get_shell_name(), completions_parse_shell_name(), errno_checkpoint(), errno_peek_since(), ERROR_FILE_OPERATION, ERROR_PROMPT_TIMEOUT, ERROR_USAGE, log_error, log_plain, OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE, safe_snprintf(), ui_notice_confirm_kind(), and UI_NOTICE_WARNING.

◆ action_create_config()

void action_create_config ( const char * output_path)

Create default configuration file and exit.

Creates a default configuration file. Outputs to stdout by default, or to specified file path if provided. Prompts for overwrite confirmation if file already exists. Exits with code 0 on success, 1 on error.

Parameters
output_pathOptional file path to write config to. NULL or empty string = stdout.

Definition at line 537 of file actions.c.

537 {
538 // Build the schema first so config_create_default can generate options from it
539 const options_config_t *unified_config = options_preset_unified(NULL, NULL);
540 if (unified_config) {
541 asciichat_error_t schema_build_result = config_schema_build_from_configs(&unified_config, 1);
542 if (schema_build_result != ASCIICHAT_OK) {
543 // Schema build failed, but continue anyway
544 (void)schema_build_result;
545 }
546 // options_config_destroy(unified_config);
547 }
548
549 const char *config_path = NULL;
550
551 // Determine output path: use provided path, or NULL for stdout
552 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
553 // User provided explicit path - use it as-is
554 config_path = output_path;
555 } else {
556 // No path or "-" means stdout
557 config_path = NULL;
558 }
559
560 // Create config with default options
561 asciichat_error_t result = config_create_default(config_path);
562 if (result != ASCIICHAT_OK) {
564 if (HAS_ERRNO(&err_ctx)) {
565 log_error("Error creating config: %s", err_ctx.context_message);
566 } else {
567 log_error("Failed to create config file");
568 }
569 action_exit(ERROR_CONFIG);
570 }
571
572 if (config_path) {
573 log_info("Created default config file at: %s", config_path);
574 } else {
575 log_info("Config written to stdout");
576 }
577 action_exit(0);
578}
#define HAS_ERRNO(context)
asciichat_error_t config_create_default(const char *config_path)
Create default configuration file with all default values.
@ ERROR_CONFIG
Definition error_codes.h:52
#define log_info(...)
Log an INFO message.
Definition log/log.h:608
options_config_t * options_preset_unified(const char *program_name, const char *description)
Build unified options config with ALL options (binary + all modes).
Definition presets.c:58
asciichat_error_t config_schema_build_from_configs(const options_config_t **configs, size_t num_configs)
Build schema dynamically from options builder configs.
Definition schema.c:252
Immutable parsing tables produced from an options builder.
Definition builder.h:414

References ASCIICHAT_OK, config_create_default(), config_schema_build_from_configs(), asciichat_error_context_t::context_message, ERROR_CONFIG, HAS_ERRNO, log_error, log_info, and options_preset_unified().

◆ action_create_manpage()

void action_create_manpage ( const char * output_path)

Generate man page template from options builder.

Generates a merged man page template preserving manual content. Outputs to stdout by default, or to specified file path if provided. Prompts for overwrite confirmation if file already exists. Exits with code 0 on success, 1 on error.

Parameters
output_pathOptional file path to write man page to. NULL or empty string = stdout.

Definition at line 488 of file actions.c.

488 {
489 // Get binary-level config
490 const options_config_t *config = options_preset_unified(NULL, NULL);
491
492 if (!config) {
493 log_error("Failed to get binary options config");
494 action_exit(ERROR_FILE_OPERATION);
495 }
496
497 // Determine output path: use provided path, or NULL for stdout
498 const char *path_to_use = NULL;
499 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
500 // User provided explicit path - use it
501 path_to_use = output_path;
502 } else {
503 // No path or "-" means stdout
504 path_to_use = NULL;
505 }
506
507 // Generate merged man page from embedded or filesystem resources
508 // Resources are loaded automatically based on build type:
509 // - Production (Release): From embedded binary data
510 // - Development (Debug): From filesystem files
512 options_config_generate_manpage_merged(config, "ascii-chat", NULL, path_to_use, "Video chat in your terminal");
513
514 if (err != ASCIICHAT_OK) {
516 if (HAS_ERRNO(&err_ctx)) {
517 log_error("%s", err_ctx.context_message);
518 } else {
519 log_error("Failed to generate man page");
520 }
521 action_exit(ERROR_FILE_OPERATION);
522 }
523
524 if (path_to_use) {
525 log_info("Man page written to: %s", path_to_use);
526 } else {
527 log_info("Man page written to stdout");
528 }
529
530 action_exit(0);
531}
asciichat_error_t options_config_generate_manpage_merged(const options_config_t *config, const char *program_name, const char *mode_name, const char *output_path, const char *brief_description)
Generate merged man page template preserving manual content.
Definition manpage.c:688

References ASCIICHAT_OK, asciichat_error_context_t::context_message, ERROR_FILE_OPERATION, HAS_ERRNO, log_error, log_info, options_config_generate_manpage_merged(), and options_preset_unified().

◆ action_help_acds()

void action_help_acds ( void )

Show discovery-service mode help and exit.

Displays discovery-service mode usage and options. Exits with code 0.

Definition at line 474 of file actions.c.

474 {
476 action_exit(0);
477}
void usage(FILE *desc, asciichat_mode_t mode)
Print usage information for a specific mode.
@ MODE_DISCOVERY_SERVICE
Discovery server mode - session management and WebRTC signaling.
Definition options.h:923

References MODE_DISCOVERY_SERVICE, and usage().

◆ action_help_client()

void action_help_client ( void )

Show client mode help and exit.

Displays client mode usage and options. Exits with code 0.

Definition at line 464 of file actions.c.

464 {
465 usage(stdout, MODE_CLIENT);
466 action_exit(0);
467}
@ MODE_CLIENT
Client mode - network client options.
Definition options.h:921

References MODE_CLIENT, and usage().

◆ action_help_discovery()

void action_help_discovery ( void )

Show discovery mode help and exit.

Displays discovery mode usage and options. Exits with code 0.

Definition at line 479 of file actions.c.

479 {
480 usage(stdout, MODE_DISCOVERY);
481 action_exit(0);
482}
@ MODE_DISCOVERY
Discovery mode - participant that can dynamically become host.
Definition options.h:924

References MODE_DISCOVERY, and usage().

◆ action_help_mirror()

void action_help_mirror ( void )

Show mirror mode help and exit.

Displays mirror mode usage and options. Exits with code 0.

Definition at line 469 of file actions.c.

469 {
470 usage(stdout, MODE_MIRROR);
471 action_exit(0);
472}
@ MODE_MIRROR
Mirror mode - local webcam viewing (no network).
Definition options.h:922

References MODE_MIRROR, and usage().

◆ action_help_server()

void action_help_server ( void )

Show server mode help and exit.

Displays server mode usage and options. Exits with code 0.

Definition at line 459 of file actions.c.

459 {
460 usage(stdout, MODE_SERVER);
461 action_exit(0);
462}
@ MODE_SERVER
Server mode - network server options.
Definition options.h:920

References MODE_SERVER, and usage().

◆ action_list_microphones()

void action_list_microphones ( void )

List available microphone devices and exit.

Enumerates all audio input devices and prints them to stdout. Exits with code 0 on success, 1 on error.

Definition at line 156 of file actions.c.

156 {
157 // Defer execution until after options are fully parsed
159}
@ ACTION_LIST_MICROPHONES
Definition actions.h:21

References ACTION_LIST_MICROPHONES, and actions_defer().

Referenced by options_action_callback().

◆ action_list_speakers()

void action_list_speakers ( void )

List available speaker devices and exit.

Enumerates all audio output devices and prints them to stdout. Exits with code 0 on success, 1 on error.

Definition at line 194 of file actions.c.

194 {
195 // Defer execution until after options are fully parsed
197}
@ ACTION_LIST_SPEAKERS
Definition actions.h:22

References ACTION_LIST_SPEAKERS, and actions_defer().

Referenced by options_action_callback().

◆ action_list_webcams()

void action_list_webcams ( void )

List available webcam devices and exit.

Enumerates all webcam devices and prints them to stdout. Exits with code 0 on success, 1 on error.

Definition at line 118 of file actions.c.

118 {
119 // Defer execution until after options are fully parsed
121}
@ ACTION_LIST_WEBCAMS
Definition actions.h:20

References ACTION_LIST_WEBCAMS, and actions_defer().

Referenced by options_action_callback().

◆ action_show_capabilities()

void action_show_capabilities ( void )

Show terminal capabilities and exit.

Detects and displays terminal color support, UTF-8 support, dimensions, and terminal program name. Exits with code 0.

Note: This action is deferred until after all options are parsed and dimensions are calculated, so that –width and –height flags are properly reflected in the output.

Definition at line 310 of file actions.c.

310 {
311 // Defer execution until after options are fully parsed and dimensions updated
312 // This ensures --width and --height flags are properly reflected in the output
314}
@ ACTION_SHOW_CAPABILITIES
Definition actions.h:23

References ACTION_SHOW_CAPABILITIES, and actions_defer().

Referenced by options_action_callback().

◆ action_show_capabilities_immediate()

void action_show_capabilities_immediate ( void )

Execute show capabilities immediately (for early binary-level execution).

Execute show capabilities immediately (for binary-level execution).

Definition at line 239 of file actions.c.

239 {
240 terminal_capabilities_t caps;
241 detect_terminal_capabilities_into(options_terminal_settings(), &caps);
242
243 // Determine if we should use colored output
244 bool use_colors = terminal_should_color_output(STDOUT_FILENO, options_terminal_settings());
245
246 // Override color level if colors should not be shown
247 if (!use_colors) {
248 caps.color_level = TERM_COLOR_NONE;
249 caps.color_count = 0;
250 caps.capabilities &= ~((uint32_t)(TERM_CAP_COLOR_TRUE | TERM_CAP_COLOR_256 | TERM_CAP_COLOR_16));
251 }
252
253 // Use detected terminal size (immediate execution doesn't have parsed options yet)
254 terminal_size_t size;
255 terminal_get_size(&size);
256 unsigned short width = size.cols;
257 unsigned short height = size.rows;
258
259 log_color_t label_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
260 log_color_t string_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
261 log_color_t good_color = use_colors ? LOG_COLOR_INFO : LOG_COLOR_GREY;
262 log_color_t bad_color = use_colors ? LOG_COLOR_ERROR : LOG_COLOR_GREY;
263 log_color_t number_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
264
265 printf("%s\n", colored_string(LOG_COLOR_WARN, "Terminal Capabilities:"));
266
268 snprintf(size_buf, sizeof(size_buf), "%ux%u", width, height);
269 printf(" %s: %s\n", colored_string(label_color, "Terminal Size"), colored_string(number_color, size_buf));
270
271 const char *color_level_name = terminal_color_level_name(caps.color_level);
272 log_color_t color_level_color = (caps.color_level == TERM_COLOR_NONE) ? bad_color : string_color;
273 printf(" %s: %s\n", colored_string(label_color, "Color Level"),
274 colored_string(color_level_color, (char *)color_level_name));
275
277 snprintf(colors_buf, sizeof(colors_buf), "%u", caps.color_count);
278 printf(" %s: %s\n", colored_string(label_color, "Max Colors"), colored_string(number_color, colors_buf));
279
280 log_color_t utf8_color = caps.utf8_support ? good_color : bad_color;
281 printf(" %s: %s\n", colored_string(label_color, "UTF-8 Support"),
282 colored_string(utf8_color, (char *)(caps.utf8_support ? "Yes" : "No")));
283
284 const char *render_mode_str = "unknown";
285 if (caps.render_mode == RENDER_MODE_FOREGROUND) {
286 render_mode_str = "foreground";
287 } else if (caps.render_mode == RENDER_MODE_BACKGROUND) {
288 render_mode_str = "background";
289 } else if (caps.render_mode == RENDER_MODE_HALF_BLOCK) {
290 render_mode_str = "half-block";
291 }
292 printf(" %s: %s\n", colored_string(label_color, "Render Mode"),
293 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"),
296 colored_string(string_color, (char *)(strlen(caps.colorterm) ? caps.colorterm : "(not set)")));
297
298 log_color_t reliable_color = caps.detection_reliable ? good_color : bad_color;
299 printf(" %s: %s\n", colored_string(label_color, "Detection Reliable"),
300 colored_string(reliable_color, (char *)(caps.detection_reliable ? "Yes" : "No")));
301
303 snprintf(bitmask_buf, sizeof(bitmask_buf), "0x%08x", caps.capabilities);
304 printf(" %s: %s\n", colored_string(label_color, "Capabilities Bitmask"), colored_string(number_color, bitmask_buf));
305
306 fflush(stdout);
307 action_exit(0);
308}
#define OPTIONS_PARSING_ACTIONS_BITMASK_BUFFER_SIZE
Definition actions.c:16
#define OPTIONS_PARSING_ACTIONS_COLORS_BUFFER_SIZE
Definition actions.c:15
#define OPTIONS_PARSING_ACTIONS_SIZE_BUFFER_SIZE
Definition actions.c:14
unsigned int height
Definition fft.c:23
unsigned int width
Definition fft.c:23
unsigned int uint32_t
Definition common.h:62
log_color_t
Color enum for logging - indexes into color arrays.
Definition log/log.h:147
@ LOG_COLOR_GREY
Definition log/log.h:154
@ LOG_COLOR_ERROR
Definition log/log.h:152
@ LOG_COLOR_DEBUG
Definition log/log.h:149
@ LOG_COLOR_INFO
Definition log/log.h:150
@ LOG_COLOR_WARN
Definition log/log.h:151
#define options_terminal_settings()
Definition options.h:1296
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
Definition string.c:284

References colored_string(), height, LOG_COLOR_DEBUG, LOG_COLOR_ERROR, LOG_COLOR_GREY, LOG_COLOR_INFO, LOG_COLOR_WARN, OPTIONS_PARSING_ACTIONS_BITMASK_BUFFER_SIZE, OPTIONS_PARSING_ACTIONS_COLORS_BUFFER_SIZE, OPTIONS_PARSING_ACTIONS_SIZE_BUFFER_SIZE, options_terminal_settings, and width.

Referenced by options_action_callback().

◆ action_show_version()

void action_show_version ( void )

Show version information and exit.

Displays ascii-chat version, build type, build date, and compiler information. Exits with code 0.

Definition at line 441 of file actions.c.

441 {
442 bool use_colors = terminal_should_color_output(STDOUT_FILENO, options_terminal_settings());
443 if (use_colors) {
444 printf("%s %s (%s, %s)\n", colored_string(LOG_COLOR_WARN, "ascii-chat"),
445 colored_string(LOG_COLOR_INFO, (char *)ASCII_CHAT_VERSION_FULL),
446 colored_string(LOG_COLOR_DEBUG, (char *)ASCII_CHAT_BUILD_TYPE),
447 colored_string(LOG_COLOR_GREY, (char *)ASCII_CHAT_BUILD_DATE));
448 } else {
449 printf("ascii-chat %s (%s, %s)\n", ASCII_CHAT_VERSION_FULL, ASCII_CHAT_BUILD_TYPE, ASCII_CHAT_BUILD_DATE);
450 }
451
452 action_exit(0);
453}

References colored_string(), LOG_COLOR_DEBUG, LOG_COLOR_GREY, LOG_COLOR_INFO, LOG_COLOR_WARN, and options_terminal_settings.

Referenced by main().

◆ actions_defer()

void actions_defer ( deferred_action_t action,
const action_args_t * args )

Set which action to defer until options are fully initialized.

Only the first action found is remembered. If multiple actions are specified, only the first one will be executed.

Parameters
actionThe action type to defer
argsOptional action arguments (can be NULL)

Definition at line 86 of file actions.c.

86 {
87 // Only remember the first action found
88 if (g_deferred_action_state.has_action) {
89 return; // Action already deferred, ignore subsequent actions
90 }
91
92 g_deferred_action_state.action = action;
93 g_deferred_action_state.has_action = true;
94
95 // Copy arguments if provided
96 if (args) {
97 memcpy(&g_deferred_action_state.args, args, sizeof(action_args_t));
98 } else {
99 memset(&g_deferred_action_state.args, 0, sizeof(action_args_t));
100 }
101}
action_args_t args
Definition actions.c:78
deferred_action_t action
Definition actions.c:77
Action argument structure.
Definition actions.h:32

References action, and args.

Referenced by action_check_update(), action_list_microphones(), action_list_speakers(), action_list_webcams(), and action_show_capabilities().

◆ actions_execute_deferred()

void actions_execute_deferred ( void )

Execute the deferred action (if any).

This function should be called during STAGE 8 of options_init() after all options are fully parsed and dimensions are calculated.

Definition at line 682 of file actions.c.

682 {
684
685 switch (action) {
686 case ACTION_NONE:
687 // No action to execute
688 break;
689
691 execute_list_webcams();
692 break;
693
695 execute_list_microphones();
696 break;
697
699 execute_list_speakers();
700 break;
701
703 execute_show_capabilities();
704 break;
705
707 execute_check_update();
708 break;
709
710 default:
711 log_warn("Unknown deferred action: %d", action);
712 break;
713 }
714}
deferred_action_t actions_get_deferred(void)
Get the deferred action (if any) that was set.
Definition actions.c:103
deferred_action_t
action args is intentionally a small, concrete record. Fields such as output_path,...
Definition actions.h:18
@ ACTION_NONE
Definition actions.h:19
#define log_warn(...)
Log a WARN message.
Definition log/log.h:621

References action, ACTION_CHECK_UPDATE, ACTION_LIST_MICROPHONES, ACTION_LIST_SPEAKERS, ACTION_LIST_WEBCAMS, ACTION_NONE, ACTION_SHOW_CAPABILITIES, actions_get_deferred(), and log_warn.

Referenced by options_init().

◆ actions_get_args()

const action_args_t * actions_get_args ( void )

Get the arguments for the deferred action.

Returns
Pointer to action arguments, or NULL if no arguments were set

Definition at line 107 of file actions.c.

107 {
108 if (!g_deferred_action_state.has_action) {
109 return NULL;
110 }
111 return &g_deferred_action_state.args;
112}

◆ actions_get_deferred()

deferred_action_t actions_get_deferred ( void )

Get the deferred action (if any) that was set.

Returns
The deferred action type, or ACTION_NONE if no action was deferred

Definition at line 103 of file actions.c.

103 {
104 return g_deferred_action_state.action;
105}

Referenced by actions_execute_deferred().

◆ options_action_callback()

option_action_fn options_action_callback ( const char * name,
bool immediate )

Definition at line 716 of file actions.c.

716 {
717 static const struct {
718 const char *name;
719 option_action_fn callback;
720 option_action_fn early_callback;
721 } actions[] = {
722 {"list-webcams", action_list_webcams, action_list_webcams},
724 {"list-speakers", action_list_speakers, action_list_speakers},
727 };
728 if (!name)
729 return NULL;
730 for (size_t i = 0; i < sizeof(actions) / sizeof(actions[0]); ++i) {
731 if (strcmp(name, actions[i].name) == 0)
732 return immediate ? actions[i].early_callback : actions[i].callback;
733 }
734 return NULL;
735}
void action_check_update_immediate(void)
Execute update check immediately (for early binary-level execution).
Definition actions.c:323
void action_check_update(void)
Check for updates and display results.
Definition actions.c:341
void action_show_capabilities(void)
Show terminal capabilities and exit.
Definition actions.c:310
void action_list_microphones(void)
List available microphone devices and exit.
Definition actions.c:156
void action_list_webcams(void)
List available webcam devices and exit.
Definition actions.c:118
void action_list_speakers(void)
List available speaker devices and exit.
Definition actions.c:194
void action_show_capabilities_immediate(void)
Execute show capabilities immediately (for early binary-level execution).
Definition actions.c:239
void(* option_action_fn)(void)
Definition actions.h:222

References action_check_update(), action_check_update_immediate(), action_list_microphones(), action_list_speakers(), action_list_webcams(), action_show_capabilities(), and action_show_capabilities_immediate().

Referenced by options_registry_add_all_to_builder().

Variable Documentation

◆ action

◆ args

◆ has_action

bool has_action

Definition at line 79 of file actions.c.