ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
completions.c
Go to the documentation of this file.
1
7#include <string.h>
8#include <ctype.h>
11#include <ascii-chat/common.h>
12#include <ascii-chat/log/log.h>
13
14/* Forward declarations for format-specific generators */
19
21 if (!output) {
22 return SET_ERRNO(ERROR_INVALID_PARAM, "Output stream cannot be NULL");
23 }
24
25 switch (format) {
27 return completions_generate_bash(output);
29 return completions_generate_fish(output);
31 return completions_generate_zsh(output);
34 default:
35 return SET_ERRNO(ERROR_INVALID_PARAM, "Unknown completion format: %d", format);
36 }
37}
38
40 switch (format) {
42 return "bash";
44 return "fish";
46 return "zsh";
48 return "powershell";
49 default:
50 return "unknown";
51 }
52}
53
55 if (!shell_name) {
57 }
58
59 /* Convert to lowercase for case-insensitive matching */
60 char lower[32] = {0};
61 size_t len = strlen(shell_name);
62 if (len >= sizeof(lower)) {
64 }
65
66 for (size_t i = 0; i < len; i++) {
67 lower[i] = tolower((unsigned char)shell_name[i]);
68 }
69
70 if (strcmp(lower, "bash") == 0) {
72 } else if (strcmp(lower, "fish") == 0) {
74 } else if (strcmp(lower, "zsh") == 0) {
76 } else if (strcmp(lower, "powershell") == 0 || strcmp(lower, "ps") == 0) {
78 }
79
81}
82
97 if (!count) {
98 return NULL;
99 }
100
101 option_descriptor_t *combined_opts = NULL;
102 size_t combined_count = 0;
103
104 /* All completion modes to iterate through */
106 const size_t modes_len = sizeof(modes) / sizeof(modes[0]);
107
108 for (size_t m = 0; m < modes_len; m++) {
109 size_t mode_count = 0;
110 const option_descriptor_t *mode_opts = options_registry_get_for_mode(modes[m], &mode_count);
111 if (mode_opts) {
112 /* Collect unique options by long_name */
113 for (size_t i = 0; i < mode_count; i++) {
114 bool already_has = false;
115 for (size_t j = 0; j < combined_count; j++) {
116 if (strcmp(combined_opts[j].long_name, mode_opts[i].long_name) == 0) {
117 already_has = true;
118 break;
119 }
120 }
121 if (!already_has) {
122 combined_count++;
124 combined_opts, combined_count * sizeof(option_descriptor_t), option_descriptor_t *);
125 if (temp) {
126 combined_opts = temp;
127 combined_opts[combined_count - 1] = mode_opts[i];
128 }
129 }
130 }
131 SAFE_FREE(mode_opts);
132 }
133 }
134
135 *count = combined_count;
136 return combined_opts;
137}
⚙️ Common definitions, error codes, macros, and types shared throughout the application
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_bash(FILE *output)
Definition bash.c:367
asciichat_error_t completions_generate_powershell(FILE *output)
Definition powershell.c:130
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
asciichat_error_t completions_generate_fish(FILE *output)
Definition fish.c:130
asciichat_error_t completions_generate_zsh(FILE *output)
Definition zsh.c:210
const char * completions_get_shell_name(completion_format_t format)
Get human-readable shell name for format.
Definition completions.c:39
option_descriptor_t * completions_collect_all_modes_unique(size_t *count)
Collect options from all modes with deduplication.
Definition completions.c:96
Auto-generated shell completions from options registry.
completion_format_t
Supported shell completion formats.
Definition completions.h:66
@ COMPLETION_FORMAT_BASH
Definition completions.h:67
@ COMPLETION_FORMAT_UNKNOWN
Definition completions.h:71
@ COMPLETION_FORMAT_ZSH
Definition completions.h:69
@ COMPLETION_FORMAT_POWERSHELL
Definition completions.h:70
@ COMPLETION_FORMAT_FISH
Definition completions.h:68
#define SAFE_REALLOC(ptr, size, cast)
Definition common.h:284
#define SAFE_FREE(ptr)
Definition common.h:376
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it, returning the error code.
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
@ ERROR_INVALID_PARAM
asciichat_mode_t
Mode type for options parsing.
@ MODE_CLIENT
Client mode - network client options.
@ MODE_DISCOVERY_SERVICE
Discovery server mode - session management and WebRTC signaling.
@ MODE_SERVER
Server mode - network server options.
@ MODE_MIRROR
Mirror mode - local webcam viewing (no network)
@ MODE_DISCOVERY
Discovery mode - participant that can dynamically become host.
📝 Logging API with multiple log levels and terminal output control
const option_descriptor_t * options_registry_get_for_mode(asciichat_mode_t mode, size_t *num_options)
Get all options for a specific mode.
Definition public_api.c:218
Central registry of all command-line options with mode applicability.
Option descriptor.
Definition builder.h:241