ascii-chat 0.11.33
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...
 

Enumerations

enum  deferred_action_t {
  ACTION_NONE = 0 , ACTION_LIST_WEBCAMS , ACTION_LIST_MICROPHONES , ACTION_LIST_SPEAKERS ,
  ACTION_SHOW_CAPABILITIES , ACTION_CHECK_UPDATE
}
 Action type enumeration. 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)
 

Detailed Description

Action option callbacks for ascii-chat.

Definition in file actions.h.

Enumeration Type Documentation

◆ deferred_action_t

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 17 of file actions.h.

17 {
18 ACTION_NONE = 0,
deferred_action_t
Action type enumeration.
Definition actions.h:17
@ ACTION_CHECK_UPDATE
Definition actions.h:23
@ ACTION_LIST_SPEAKERS
Definition actions.h:21
@ ACTION_LIST_MICROPHONES
Definition actions.h:20
@ ACTION_NONE
Definition actions.h:18
@ ACTION_LIST_WEBCAMS
Definition actions.h:19
@ ACTION_SHOW_CAPABILITIES
Definition actions.h:22

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

329 {
330 // Defer execution until after options are fully parsed
332}
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_registry_add_all_to_builder().

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

311 {
312 printf("Checking for updates...\n");
315 if (err != ASCIICHAT_OK) {
316 printf("\nFailed to check for updates.\n\n");
317 action_exit(1);
318 }
319 if (result.update_available) {
320 char notification[1024];
321 update_check_format_notification(&result, notification, sizeof(notification));
322 printf("\n%s\n\n", notification);
323 } else {
324 printf("\nYou are already on the latest version: %s (%.8s)\n\n", result.current_version, result.current_sha);
325 }
326 action_exit(0);
327}
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
@ ASCIICHAT_OK
Definition error_codes.h:51
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 data.
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, update_check_result_t::update_available, update_check_format_notification(), and update_check_perform().

Referenced by options_init().

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

571 {
572 if (!shell_name || strlen(shell_name) == 0) {
573 log_error("--completions requires shell name (bash, fish, zsh, powershell)");
574 action_exit(ERROR_USAGE);
575 }
576
578 if (format == COMPLETION_FORMAT_UNKNOWN) {
579 log_error("Unknown shell '%s' (supported: bash, fish, zsh, powershell)", shell_name);
580 action_exit(ERROR_USAGE);
581 }
582
583 FILE *output = stdout;
584 bool should_close = false;
585
586 // Determine output: use provided path if given and not "-", otherwise stdout
587 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
588 // Check if file already exists and prompt for confirmation
589 struct stat st;
590 if (stat(output_path, &st) == 0) {
591 // File exists - ask user if they want to overwrite
592 log_plain("Completions file already exists: %s", output_path);
593
594 bool overwrite = platform_prompt_yes_no("Overwrite", false); // Default to No
595 if (!overwrite) {
596 log_plain("Completions generation cancelled.");
597 action_exit(0);
598 }
599
600 log_plain("Overwriting existing completions file...");
601 }
602
603 output = platform_fopen("file_stream", output_path, "w");
604 if (!output) {
605 log_error("Failed to open %s for writing", output_path);
606 action_exit(ERROR_FILE_OPERATION);
607 }
608 should_close = true;
609 }
610
611 asciichat_error_t result = completions_generate_for_shell(format, output);
612
613 if (should_close) {
614 fclose(output);
615 }
616
617 if (result != ASCIICHAT_OK) {
618 log_error("Failed to generate %s completions", completions_get_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}
completion_format_t completions_parse_shell_name(const char *shell_name)
Parse shell name string to completion format.
Definition completions.c:54
asciichat_error_t completions_generate_for_shell(completion_format_t format, FILE *output)
Generate shell completions and write to output stream.
Definition completions.c:20
const char * completions_get_shell_name(completion_format_t format)
Get human-readable shell name for format.
Definition completions.c:39
completion_format_t
Supported shell completion formats.
Definition completions.h:66
@ COMPLETION_FORMAT_UNKNOWN
Definition completions.h:71
@ ERROR_FILE_OPERATION
@ ERROR_USAGE
Definition error_codes.h:53
#define log_error(...)
Log an ERROR message.
Definition log/log.h:587
#define log_plain(...)
Plain logging - writes to both log file and stderr without timestamps or log levels.
Definition log/log.h:618
bool platform_prompt_yes_no(const char *question, bool default_yes)
Prompt the user for a yes/no answer.
Definition util.c:83
FILE * platform_fopen(const char *name, const char *filename, const char *mode)
Safe file open stream (fopen replacement)

References ASCIICHAT_OK, COMPLETION_FORMAT_UNKNOWN, completions_generate_for_shell(), completions_get_shell_name(), completions_parse_shell_name(), ERROR_FILE_OPERATION, ERROR_USAGE, log_error, log_plain, platform_fopen(), and platform_prompt_yes_no().

Referenced by options_init().

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

524 {
525 // Build the schema first so config_create_default can generate options from it
526 const options_config_t *unified_config = options_preset_unified(NULL, NULL);
527 if (unified_config) {
528 asciichat_error_t schema_build_result = config_schema_build_from_configs(&unified_config, 1);
529 if (schema_build_result != ASCIICHAT_OK) {
530 // Schema build failed, but continue anyway
531 (void)schema_build_result;
532 }
533 // options_config_destroy(unified_config);
534 }
535
536 const char *config_path = NULL;
537
538 // Determine output path: use provided path, or NULL for stdout
539 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
540 // User provided explicit path - use it as-is
541 config_path = output_path;
542 } else {
543 // No path or "-" means stdout
544 config_path = NULL;
545 }
546
547 // Create config with default options
548 asciichat_error_t result = config_create_default(config_path);
549 if (result != ASCIICHAT_OK) {
551 if (HAS_ERRNO(&err_ctx)) {
552 log_error("Error creating config: %s", err_ctx.context_message);
553 } else {
554 log_error("Failed to create config file");
555 }
556 action_exit(ERROR_CONFIG);
557 }
558
559 if (config_path) {
560 log_info("Created default config file at: %s", config_path);
561 } else {
562 log_info("Config written to stdout");
563 }
564 action_exit(0);
565}
asciichat_error_t config_create_default(const char *config_path)
Create default configuration file with all default values.
Definition config.c:1254
#define HAS_ERRNO(var)
Check if an error occurred and get full context.
@ ERROR_CONFIG
Definition error_codes.h:57
#define log_info(...)
Log an INFO message.
Definition log/log.h:561
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:51
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:240
Error context structure.
char * context_message
Optional custom message (dynamically allocated, owned by system)
Options configuration.
Definition builder.h:401

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

Referenced by options_init().

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

475 {
476 // Get binary-level config
477 const options_config_t *config = options_preset_unified(NULL, NULL);
478
479 if (!config) {
480 log_error("Failed to get binary options config");
481 action_exit(ERROR_FILE_OPERATION);
482 }
483
484 // Determine output path: use provided path, or NULL for stdout
485 const char *path_to_use = NULL;
486 if (output_path && strlen(output_path) > 0 && strcmp(output_path, "-") != 0) {
487 // User provided explicit path - use it
488 path_to_use = output_path;
489 } else {
490 // No path or "-" means stdout
491 path_to_use = NULL;
492 }
493
494 // Generate merged man page from embedded or filesystem resources
495 // Resources are loaded automatically based on build type:
496 // - Production (Release): From embedded binary data
497 // - Development (Debug): From filesystem files
499 options_config_generate_manpage_merged(config, "ascii-chat", NULL, path_to_use, "Video chat in your terminal");
500
501 if (err != ASCIICHAT_OK) {
503 if (HAS_ERRNO(&err_ctx)) {
504 log_error("%s", err_ctx.context_message);
505 } else {
506 log_error("Failed to generate man page");
507 }
508 action_exit(ERROR_FILE_OPERATION);
509 }
510
511 if (path_to_use) {
512 log_info("Man page written to: %s", path_to_use);
513 } else {
514 log_info("Man page written to stdout");
515 }
516
517 action_exit(0);
518}
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.

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

Referenced by options_init().

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

461 {
463 action_exit(0);
464}
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.

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

451 {
452 usage(stdout, MODE_CLIENT);
453 action_exit(0);
454}
@ MODE_CLIENT
Client mode - network client options.

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

466 {
467 usage(stdout, MODE_DISCOVERY);
468 action_exit(0);
469}
@ MODE_DISCOVERY
Discovery mode - participant that can dynamically become host.

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

456 {
457 usage(stdout, MODE_MIRROR);
458 action_exit(0);
459}
@ MODE_MIRROR
Mirror mode - local webcam viewing (no network)

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

446 {
447 usage(stdout, MODE_SERVER);
448 action_exit(0);
449}
@ MODE_SERVER
Server mode - network server options.

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

145 {
146 // Defer execution until after options are fully parsed
148}

References ACTION_LIST_MICROPHONES, and actions_defer().

Referenced by options_init(), and options_registry_add_all_to_builder().

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

183 {
184 // Defer execution until after options are fully parsed
186}

References ACTION_LIST_SPEAKERS, and actions_defer().

Referenced by options_init(), and options_registry_add_all_to_builder().

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

107 {
108 // Defer execution until after options are fully parsed
110}

References ACTION_LIST_WEBCAMS, and actions_defer().

Referenced by options_init(), and options_registry_add_all_to_builder().

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

298 {
299 // Defer execution until after options are fully parsed and dimensions updated
300 // This ensures --width and --height flags are properly reflected in the output
302}

References ACTION_SHOW_CAPABILITIES, and actions_defer().

Referenced by options_registry_add_all_to_builder().

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

228 {
230
231 // Determine if we should use colored output
232 bool use_colors = terminal_should_color_output(STDOUT_FILENO);
233
234 // Override color level if colors should not be shown
235 if (!use_colors) {
237 caps.color_count = 0;
239 }
240
241 // Use detected terminal size (immediate execution doesn't have parsed options yet)
242 terminal_size_t size;
243 terminal_get_size(&size);
244 unsigned short width = size.cols;
245 unsigned short height = size.rows;
246
247 log_color_t label_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
248 log_color_t string_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
249 log_color_t good_color = use_colors ? LOG_COLOR_INFO : LOG_COLOR_GREY;
250 log_color_t bad_color = use_colors ? LOG_COLOR_ERROR : LOG_COLOR_GREY;
251 log_color_t number_color = use_colors ? LOG_COLOR_DEBUG : LOG_COLOR_GREY;
252
253 printf("%s\n", colored_string(LOG_COLOR_WARN, "Terminal Capabilities:"));
254
255 char size_buf[64];
256 snprintf(size_buf, sizeof(size_buf), "%ux%u", width, height);
257 printf(" %s: %s\n", colored_string(label_color, "Terminal Size"), colored_string(number_color, size_buf));
258
259 const char *color_level_name = terminal_color_level_name(caps.color_level);
260 log_color_t color_level_color = (caps.color_level == TERM_COLOR_NONE) ? bad_color : string_color;
261 printf(" %s: %s\n", colored_string(label_color, "Color Level"),
262 colored_string(color_level_color, (char *)color_level_name));
263
264 char colors_buf[64];
265 snprintf(colors_buf, sizeof(colors_buf), "%u", caps.color_count);
266 printf(" %s: %s\n", colored_string(label_color, "Max Colors"), colored_string(number_color, colors_buf));
267
268 log_color_t utf8_color = caps.utf8_support ? good_color : bad_color;
269 printf(" %s: %s\n", colored_string(label_color, "UTF-8 Support"),
270 colored_string(utf8_color, (char *)(caps.utf8_support ? "Yes" : "No")));
271
272 const char *render_mode_str = "unknown";
274 render_mode_str = "foreground";
275 } else if (caps.render_mode == RENDER_MODE_BACKGROUND) {
276 render_mode_str = "background";
277 } else if (caps.render_mode == RENDER_MODE_HALF_BLOCK) {
278 render_mode_str = "half-block";
279 }
280 printf(" %s: %s\n", colored_string(label_color, "Render Mode"),
281 colored_string(string_color, (char *)render_mode_str));
282 printf(" %s: %s\n", colored_string(label_color, "TERM"), colored_string(string_color, (char *)caps.term_type));
283 printf(" %s: %s\n", colored_string(label_color, "COLORTERM"),
284 colored_string(string_color, (char *)(strlen(caps.colorterm) ? caps.colorterm : "(not set)")));
285
286 log_color_t reliable_color = caps.detection_reliable ? good_color : bad_color;
287 printf(" %s: %s\n", colored_string(label_color, "Detection Reliable"),
288 colored_string(reliable_color, (char *)(caps.detection_reliable ? "Yes" : "No")));
289
290 char bitmask_buf[64];
291 snprintf(bitmask_buf, sizeof(bitmask_buf), "0x%08x", caps.capabilities);
292 printf(" %s: %s\n", colored_string(label_color, "Capabilities Bitmask"), colored_string(number_color, bitmask_buf));
293
294 fflush(stdout);
295 action_exit(0);
296}
unsigned int uint32_t
Definition common.h:58
log_color_t
Color enum for logging - indexes into color arrays.
Definition log/log.h:130
@ LOG_COLOR_GREY
Definition log/log.h:137
@ LOG_COLOR_ERROR
Definition log/log.h:135
@ LOG_COLOR_DEBUG
Definition log/log.h:132
@ LOG_COLOR_INFO
Definition log/log.h:133
@ LOG_COLOR_WARN
Definition log/log.h:134
asciichat_error_t terminal_get_size(terminal_size_t *size)
Get terminal size.
const char * colored_string(log_color_t color, const char *text)
Build a colored string for terminal output.
bool terminal_should_color_output(int fd)
Determine if color output should be used.
terminal_capabilities_t detect_terminal_capabilities(void)
Detect terminal capabilities.
Complete terminal capabilities structure.
Definition terminal.h:709
terminal_color_mode_t color_level
Detected color support level (terminal_color_mode_t)
Definition terminal.h:711
render_mode_t render_mode
Preferred rendering mode (render_mode_t)
Definition terminal.h:721
bool utf8_support
True if terminal supports UTF-8 encoding.
Definition terminal.h:717
uint32_t capabilities
Capability flags bitmask (terminal_capability_flags_t)
Definition terminal.h:713
uint32_t color_count
Maximum number of colors (2, 16, 256, or 16777216)
Definition terminal.h:715
char term_type[64]
$TERM environment variable value (for debugging)
Definition terminal.h:723
char colorterm[64]
$COLORTERM environment variable value (for debugging)
Definition terminal.h:725
bool detection_reliable
True if detection is confident (reliable detection)
Definition terminal.h:719
Terminal size structure.
Definition terminal.h:163
int cols
Number of columns (width) in terminal.
Definition terminal.h:165
int rows
Number of rows (height) in terminal.
Definition terminal.h:164
const char * terminal_color_level_name(terminal_color_mode_t level)
Get name of color level.
@ TERM_CAP_COLOR_256
256-color support (TERM_CAP_COLOR_256)
Definition terminal.h:643
@ TERM_CAP_COLOR_16
16-color support (TERM_CAP_COLOR_16)
Definition terminal.h:641
@ TERM_CAP_COLOR_TRUE
Truecolor support (TERM_CAP_COLOR_TRUE)
Definition terminal.h:645
@ RENDER_MODE_FOREGROUND
Foreground colors only (text color)
Definition terminal.h:664
@ RENDER_MODE_BACKGROUND
Background colors (block colors)
Definition terminal.h:666
@ RENDER_MODE_HALF_BLOCK
Unicode half-block characters (mixed foreground/background)
Definition terminal.h:668
@ TERM_COLOR_NONE
No color support (monochrome terminal)
Definition terminal.h:582

References terminal_capabilities_t::capabilities, terminal_capabilities_t::color_count, terminal_capabilities_t::color_level, colored_string(), terminal_capabilities_t::colorterm, terminal_size_t::cols, detect_terminal_capabilities(), terminal_capabilities_t::detection_reliable, LOG_COLOR_DEBUG, LOG_COLOR_ERROR, LOG_COLOR_GREY, LOG_COLOR_INFO, LOG_COLOR_WARN, terminal_capabilities_t::render_mode, RENDER_MODE_BACKGROUND, RENDER_MODE_FOREGROUND, RENDER_MODE_HALF_BLOCK, terminal_size_t::rows, TERM_CAP_COLOR_16, TERM_CAP_COLOR_256, TERM_CAP_COLOR_TRUE, TERM_COLOR_NONE, terminal_capabilities_t::term_type, terminal_color_level_name(), terminal_get_size(), terminal_should_color_output(), and terminal_capabilities_t::utf8_support.

Referenced by options_init().

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

428 {
429 bool use_colors = terminal_should_color_output(STDOUT_FILENO);
430 if (use_colors) {
431 printf("%s %s (%s, %s)\n", colored_string(LOG_COLOR_WARN, "ascii-chat"),
435 } else {
436 printf("ascii-chat %s (%s, %s)\n", ASCII_CHAT_VERSION_FULL, ASCII_CHAT_BUILD_TYPE, ASCII_CHAT_BUILD_DATE);
437 }
438
439 action_exit(0);
440}
#define ASCII_CHAT_VERSION_FULL
Definition version.h:21
#define ASCII_CHAT_BUILD_TYPE
Definition version.h:14
#define ASCII_CHAT_BUILD_DATE
Definition version.h:16

References ASCII_CHAT_BUILD_DATE, ASCII_CHAT_BUILD_TYPE, ASCII_CHAT_VERSION_FULL, colored_string(), LOG_COLOR_DEBUG, LOG_COLOR_GREY, LOG_COLOR_INFO, LOG_COLOR_WARN, 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 75 of file options/parsing/actions.c.

75 {
76 // Only remember the first action found
77 if (g_deferred_action_state.has_action) {
78 return; // Action already deferred, ignore subsequent actions
79 }
80
81 g_deferred_action_state.action = action;
82 g_deferred_action_state.has_action = true;
83
84 // Copy arguments if provided
85 if (args) {
86 memcpy(&g_deferred_action_state.args, args, sizeof(action_args_t));
87 } else {
88 memset(&g_deferred_action_state.args, 0, sizeof(action_args_t));
89 }
90}
action_args_t args
deferred_action_t action
Action argument structure.
Definition actions.h:31

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

96 {
97 if (!g_deferred_action_state.has_action) {
98 return NULL;
99 }
100 return &g_deferred_action_state.args;
101}

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

92 {
93 return g_deferred_action_state.action;
94}

Referenced by actions_execute_deferred().