ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
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 lib/options/parsing/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 lib/options/parsing/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 lib/options/parsing/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 lib/options/parsing/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 lib/options/parsing/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 lib/options/parsing/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 339 of file lib/options/parsing/actions.c.

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

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 321 of file lib/options/parsing/actions.c.

321 {
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}
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ASCIICHAT_OK
Definition error_codes.h:50
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.
#define OPTIONS_PARSING_ACTIONS_NOTIFICATION_BUFFER_SIZE
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 546 of file lib/options/parsing/actions.c.

546 {
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}
bool errno_peek_since(asciichat_errno_scope_t scope, asciichat_error_context_t *out)
asciichat_errno_scope_t errno_checkpoint(void)
#define SET_ERRNO(code,...)
FILE * platform_fopen(const char *name, const char *filename, const char *mode)
Definition filesystem.c:18
@ ERROR_PROMPT_TIMEOUT
@ ERROR_CONFIG
Definition error_codes.h:56
@ ERROR_FILE_OPERATION
@ ERROR_USAGE
Definition error_codes.h:52
#define log_error(...)
Log an ERROR message.
Definition log/log.h:628
#define log_plain(...)
Plain logging - writes to both log file and stderr without timestamps or log levels.
Definition log/log.h:659
@ OPTION_MODE_ALL
All modes + binary.
Definition options.h:943
#define OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE
struct flags_schema_builder flags_schema_builder_t
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
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
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, errno_checkpoint(), errno_peek_since(), ERROR_CONFIG, ERROR_FILE_OPERATION, ERROR_PROMPT_TIMEOUT, ERROR_USAGE, log_error, log_plain, OPTION_MODE_ALL, OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE, platform_fopen(), registry_add_all_to_flags_builder(), SET_ERRNO, 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 510 of file lib/options/parsing/actions.c.

510 {
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}
#define HAS_ERRNO(context)
asciichat_error_t config_create_default(const char *config_path)
Create default configuration file with all default values.
#define log_info(...)
Log an INFO message.
Definition log/log.h:602

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

◆ 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 479 of file lib/options/parsing/actions.c.

479 {
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}
int platform_open(const char *name, const char *pathname, int flags,...)
Definition filesystem.c:65
flags_schema_builder_t * options_config_build_flags_schema(option_mode_bitmask_t mode_mask)

References ERROR_FILE_OPERATION, log_info, OPTION_MODE_ALL, options_config_build_flags_schema(), and platform_open().

◆ 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 465 of file lib/options/parsing/actions.c.

465 {
467 action_exit(0);
468}
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:920

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 455 of file lib/options/parsing/actions.c.

455 {
456 usage(stdout, MODE_CLIENT);
457 action_exit(0);
458}
@ MODE_CLIENT
Client mode - network client options.
Definition options.h:918

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 470 of file lib/options/parsing/actions.c.

470 {
471 usage(stdout, MODE_DISCOVERY);
472 action_exit(0);
473}
@ MODE_DISCOVERY
Discovery mode - participant that can dynamically become host.
Definition options.h:921

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 460 of file lib/options/parsing/actions.c.

460 {
461 usage(stdout, MODE_MIRROR);
462 action_exit(0);
463}
@ MODE_MIRROR
Mirror mode - local webcam viewing (no network).
Definition options.h:919

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 450 of file lib/options/parsing/actions.c.

450 {
451 usage(stdout, MODE_SERVER);
452 action_exit(0);
453}
@ MODE_SERVER
Server mode - network server options.
Definition options.h:917

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 159 of file lib/options/parsing/actions.c.

159 {
160 // Defer execution until after options are fully parsed
162}
@ ACTION_LIST_MICROPHONES
Definition actions.h:27

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 197 of file lib/options/parsing/actions.c.

197 {
198 // Defer execution until after options are fully parsed
200}
@ ACTION_LIST_SPEAKERS
Definition actions.h:28

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 121 of file lib/options/parsing/actions.c.

121 {
122 // Defer execution until after options are fully parsed
124}
@ ACTION_LIST_WEBCAMS
Definition actions.h:26

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 308 of file lib/options/parsing/actions.c.

308 {
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}
@ ACTION_SHOW_CAPABILITIES
Definition actions.h:29

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 242 of file lib/options/parsing/actions.c.

242 {
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}
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24
unsigned int uint32_t
log_color_t
Color enum for logging - indexes into color arrays.
Definition log/log.h:146
@ 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
#define options_terminal_settings()
Definition options.h:1287
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
#define OPTIONS_PARSING_ACTIONS_BITMASK_BUFFER_SIZE
#define OPTIONS_PARSING_ACTIONS_COLORS_BUFFER_SIZE
#define OPTIONS_PARSING_ACTIONS_SIZE_BUFFER_SIZE
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)

References colored_string(), detect_terminal_capabilities_into(), 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, terminal_get_size(), terminal_should_color_output(), 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 434 of file lib/options/parsing/actions.c.

434 {
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}

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

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 89 of file lib/options/parsing/actions.c.

89 {
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}
action_args_t args
deferred_action_t action
Action argument structure.
Definition actions.h:38

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 652 of file lib/options/parsing/actions.c.

652 {
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}
deferred_action_t
action args is intentionally a small, concrete record. Fields such as output_path,...
Definition actions.h:24
@ ACTION_NONE
Definition actions.h:25
#define log_warn(...)
Log a WARN message.
Definition log/log.h:615
deferred_action_t actions_get_deferred(void)
Get the deferred action (if any) that was set.

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 110 of file lib/options/parsing/actions.c.

110 {
111 if (!g_deferred_action_state.has_action) {
112 return NULL;
113 }
114 return &g_deferred_action_state.args;
115}

◆ 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 106 of file lib/options/parsing/actions.c.

106 {
107 return g_deferred_action_state.action;
108}

Referenced by actions_execute_deferred().

◆ options_action_callback()

option_action_fn options_action_callback ( const char * name,
bool immediate )

Definition at line 686 of file lib/options/parsing/actions.c.

686 {
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}
void(* option_action_fn)(void)
Definition actions.h:228
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_capabilities(void)
Show terminal capabilities and exit.
void action_list_microphones(void)
List available microphone devices 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_show_capabilities_immediate(void)
Execute show capabilities immediately (for early binary-level execution).

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().

Variable Documentation

◆ action

◆ args

◆ has_action

bool has_action

Definition at line 82 of file lib/options/parsing/actions.c.