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

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

Go to the source code of this file.

Data Structures

struct  action_args_t
 Action argument structure. More...

Typedefs

typedef void(* option_action_fn) (void)

Enumerations

enum  deferred_action_t {
  ACTION_NONE = 0 , ACTION_LIST_WEBCAMS , ACTION_LIST_MICROPHONES , ACTION_LIST_SPEAKERS ,
  ACTION_SHOW_CAPABILITIES , ACTION_CHECK_UPDATE
}
 action args is intentionally a small, concrete record. Fields such as output_path, shell_name give callers the identity and current value they need. It is normally borrowed from, or owned by, the surrounding subsystem—not independently managed. More...

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 actions_execute_deferred (void)
 Execute the deferred action (if any).
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 (void)
 Show terminal capabilities and exit.
void action_show_capabilities_immediate (void)
 Execute show capabilities immediately (for binary-level execution).
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 action_check_update (void)
 Check for updates and display results.
void action_check_update_immediate (void)
 Execute update check immediately (for binary-level execution).
option_action_fn options_action_callback (const char *name, bool immediate)

Detailed Description

Action option callbacks for ascii-chat.

Definition in file actions.h.

Typedef Documentation

◆ option_action_fn

typedef void(* option_action_fn) (void)

Return the registered callback for a no-argument action, or NULL.

Definition at line 234 of file actions.h.

Enumeration Type Documentation

◆ deferred_action_t

action args is intentionally a small, concrete record. Fields such as output_path, shell_name give callers the identity and current value they need. It is normally borrowed from, or owned by, the surrounding subsystem—not independently managed.

Action type enumeration

Defines all possible deferred actions that can be executed after options are fully parsed and initialized.

Enumerator
ACTION_NONE 
ACTION_LIST_WEBCAMS 
ACTION_LIST_MICROPHONES 
ACTION_LIST_SPEAKERS 
ACTION_SHOW_CAPABILITIES 
ACTION_CHECK_UPDATE 

Definition at line 25 of file actions.h.

25 {
26 ACTION_NONE = 0,
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

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 options/parsing/actions.c.

339 {
340 // Defer execution until after options are fully parsed
342}
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 binary-level execution).

Performs immediate update check and exits. Used when –check-update is specified before mode detection. Exits with code 0 on success, 1 on error.

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

Definition at line 321 of file 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]
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 556 of file options/parsing/actions.c.

556 {
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}
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:604
#define log_plain(...)
Plain logging - writes to both log file and stderr without timestamps or log levels.
Definition log/log.h:635
@ OPTION_MODE_ALL
All modes + binary.
Definition options.h:943
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:548
@ UI_NOTICE_WARNING
Definition notice.h:15
#define OPTIONS_PARSING_ACTIONS_QUESTION_BUFFER_SIZE
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 520 of file options/parsing/actions.c.

520 {
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}
#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:578

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 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 (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}
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 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 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 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 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 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 options/parsing/actions.c.

159 {
160 // Defer execution until after options are fully parsed
162}

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 options/parsing/actions.c.

197 {
198 // Defer execution until after options are fully parsed
200}

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 options/parsing/actions.c.

121 {
122 // Defer execution until after options are fully parsed
124}

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

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 binary-level execution).

Shows terminal capabilities before full options parsing. Uses detected terminal size (doesn't respect –width/–height). Exits with code 0.

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

Definition at line 242 of file 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 = (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}
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
unsigned int uint32_t
#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 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().

◆ 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 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:40

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

662 {
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}
#define log_warn(...)
Log a WARN message.
Definition log/log.h:591
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 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 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 696 of file options/parsing/actions.c.

696 {
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}
void(* option_action_fn)(void)
Definition actions.h:234
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().