ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
enums.h File Reference

Option enum value definitions - single source of truth. More...

Go to the source code of this file.

Data Structures

struct  enum_to_string_entry_t
 Enum value mapping with description for shell completions. More...
 
struct  enum_descriptor_t
 Enum value mapping for an option. More...
 

Macros

#define OPT_LOG_LEVEL_DEV   "dev"
 
#define OPT_LOG_LEVEL_DEBUG   "debug"
 
#define OPT_LOG_LEVEL_INFO   "info"
 
#define OPT_LOG_LEVEL_WARN   "warn"
 
#define OPT_LOG_LEVEL_ERROR   "error"
 
#define OPT_LOG_LEVEL_FATAL   "fatal"
 
#define OPT_COLOR_MODE_AUTO   "auto"
 
#define OPT_COLOR_MODE_NONE   "none"
 
#define OPT_COLOR_MODE_16   "16"
 
#define OPT_COLOR_MODE_256   "256"
 
#define OPT_COLOR_MODE_TRUECOLOR   "truecolor"
 
#define OPT_COLOR_FILTER_NONE   "none"
 
#define OPT_COLOR_FILTER_BLACK   "black"
 
#define OPT_COLOR_FILTER_WHITE   "white"
 
#define OPT_COLOR_FILTER_GREEN   "green"
 
#define OPT_COLOR_FILTER_MAGENTA   "magenta"
 
#define OPT_COLOR_FILTER_FUCHSIA   "fuchsia"
 
#define OPT_COLOR_FILTER_ORANGE   "orange"
 
#define OPT_COLOR_FILTER_TEAL   "teal"
 
#define OPT_COLOR_FILTER_CYAN   "cyan"
 
#define OPT_COLOR_FILTER_PINK   "pink"
 
#define OPT_COLOR_FILTER_RED   "red"
 
#define OPT_COLOR_FILTER_YELLOW   "yellow"
 
#define OPT_COLOR_FILTER_RAINBOW   "rainbow"
 
#define OPT_PALETTE_STANDARD   "standard"
 
#define OPT_PALETTE_BLOCKS   "blocks"
 
#define OPT_PALETTE_DIGITAL   "digital"
 
#define OPT_PALETTE_MINIMAL   "minimal"
 
#define OPT_PALETTE_COOL   "cool"
 
#define OPT_PALETTE_CUSTOM   "custom"
 
#define OPT_RENDER_MODE_FOREGROUND   "foreground"
 
#define OPT_RENDER_MODE_FG   "fg"
 
#define OPT_RENDER_MODE_BACKGROUND   "background"
 
#define OPT_RENDER_MODE_BG   "bg"
 
#define OPT_RENDER_MODE_HALF_BLOCK   "half-block"
 
#define OPT_RECONNECT_OFF   "off"
 
#define OPT_RECONNECT_AUTO   "auto"
 
#define OPT_AUDIO_SOURCE_ALL   "all"
 
#define OPT_AUDIO_SOURCE_CALL   "call"
 
#define OPT_AUDIO_SOURCE_MIC   "mic"
 
#define OPT_AUDIO_SOURCE_MEDIA   "media"
 
#define OPT_AUDIO_SOURCE_AUTO   "auto"
 
#define OPT_AUDIO_CAPTURE_SOURCE_AUTO   "auto"
 
#define OPT_AUDIO_CAPTURE_SOURCE_MIC   "mic"
 
#define OPT_AUDIO_CAPTURE_SOURCE_MEDIA   "media"
 
#define OPT_AUDIO_CAPTURE_SOURCE_BOTH   "both"
 
#define OPT_AUDIO_CAPTURE_SOURCE_REMOTE   "remote"
 

Functions

const enum_to_string_entry_t * options_get_enum_entries (const char *option_name, size_t *entry_count)
 Get enum entries with descriptions for an option.
 
const char ** options_get_enum_values (const char *option_name, size_t *value_count)
 Get enum values for an option.
 
bool options_is_enum_option (const char *option_name)
 Check if an option has enum values.
 

Detailed Description

Option enum value definitions - single source of truth.

Defines all enum values for options in one place so they can be used by:

  • Option parsers
  • Help text generation
  • Shell completions (bash/fish/zsh/powershell)
  • Configuration file validation

This ensures consistency across all parts of the application.

Definition in file enums.h.

Macro Definition Documentation

◆ OPT_AUDIO_CAPTURE_SOURCE_AUTO

#define OPT_AUDIO_CAPTURE_SOURCE_AUTO   "auto"

Definition at line 131 of file enums.h.

◆ OPT_AUDIO_CAPTURE_SOURCE_BOTH

#define OPT_AUDIO_CAPTURE_SOURCE_BOTH   "both"

Definition at line 134 of file enums.h.

◆ OPT_AUDIO_CAPTURE_SOURCE_MEDIA

#define OPT_AUDIO_CAPTURE_SOURCE_MEDIA   "media"

Definition at line 133 of file enums.h.

◆ OPT_AUDIO_CAPTURE_SOURCE_MIC

#define OPT_AUDIO_CAPTURE_SOURCE_MIC   "mic"

Definition at line 132 of file enums.h.

◆ OPT_AUDIO_CAPTURE_SOURCE_REMOTE

#define OPT_AUDIO_CAPTURE_SOURCE_REMOTE   "remote"

Definition at line 135 of file enums.h.

◆ OPT_AUDIO_SOURCE_ALL

#define OPT_AUDIO_SOURCE_ALL   "all"

Definition at line 124 of file enums.h.

◆ OPT_AUDIO_SOURCE_AUTO

#define OPT_AUDIO_SOURCE_AUTO   "auto"

Definition at line 128 of file enums.h.

◆ OPT_AUDIO_SOURCE_CALL

#define OPT_AUDIO_SOURCE_CALL   "call"

Definition at line 125 of file enums.h.

◆ OPT_AUDIO_SOURCE_MEDIA

#define OPT_AUDIO_SOURCE_MEDIA   "media"

Definition at line 127 of file enums.h.

◆ OPT_AUDIO_SOURCE_MIC

#define OPT_AUDIO_SOURCE_MIC   "mic"

Definition at line 126 of file enums.h.

◆ OPT_COLOR_FILTER_BLACK

#define OPT_COLOR_FILTER_BLACK   "black"

Definition at line 91 of file enums.h.

◆ OPT_COLOR_FILTER_CYAN

#define OPT_COLOR_FILTER_CYAN   "cyan"

Definition at line 98 of file enums.h.

◆ OPT_COLOR_FILTER_FUCHSIA

#define OPT_COLOR_FILTER_FUCHSIA   "fuchsia"

Definition at line 95 of file enums.h.

◆ OPT_COLOR_FILTER_GREEN

#define OPT_COLOR_FILTER_GREEN   "green"

Definition at line 93 of file enums.h.

◆ OPT_COLOR_FILTER_MAGENTA

#define OPT_COLOR_FILTER_MAGENTA   "magenta"

Definition at line 94 of file enums.h.

◆ OPT_COLOR_FILTER_NONE

#define OPT_COLOR_FILTER_NONE   "none"

Definition at line 90 of file enums.h.

◆ OPT_COLOR_FILTER_ORANGE

#define OPT_COLOR_FILTER_ORANGE   "orange"

Definition at line 96 of file enums.h.

◆ OPT_COLOR_FILTER_PINK

#define OPT_COLOR_FILTER_PINK   "pink"

Definition at line 99 of file enums.h.

◆ OPT_COLOR_FILTER_RAINBOW

#define OPT_COLOR_FILTER_RAINBOW   "rainbow"

Definition at line 102 of file enums.h.

◆ OPT_COLOR_FILTER_RED

#define OPT_COLOR_FILTER_RED   "red"

Definition at line 100 of file enums.h.

◆ OPT_COLOR_FILTER_TEAL

#define OPT_COLOR_FILTER_TEAL   "teal"

Definition at line 97 of file enums.h.

◆ OPT_COLOR_FILTER_WHITE

#define OPT_COLOR_FILTER_WHITE   "white"

Definition at line 92 of file enums.h.

◆ OPT_COLOR_FILTER_YELLOW

#define OPT_COLOR_FILTER_YELLOW   "yellow"

Definition at line 101 of file enums.h.

◆ OPT_COLOR_MODE_16

#define OPT_COLOR_MODE_16   "16"

Definition at line 85 of file enums.h.

◆ OPT_COLOR_MODE_256

#define OPT_COLOR_MODE_256   "256"

Definition at line 86 of file enums.h.

◆ OPT_COLOR_MODE_AUTO

#define OPT_COLOR_MODE_AUTO   "auto"

Definition at line 83 of file enums.h.

◆ OPT_COLOR_MODE_NONE

#define OPT_COLOR_MODE_NONE   "none"

Definition at line 84 of file enums.h.

◆ OPT_COLOR_MODE_TRUECOLOR

#define OPT_COLOR_MODE_TRUECOLOR   "truecolor"

Definition at line 87 of file enums.h.

◆ OPT_LOG_LEVEL_DEBUG

#define OPT_LOG_LEVEL_DEBUG   "debug"

Definition at line 76 of file enums.h.

◆ OPT_LOG_LEVEL_DEV

#define OPT_LOG_LEVEL_DEV   "dev"

Definition at line 75 of file enums.h.

◆ OPT_LOG_LEVEL_ERROR

#define OPT_LOG_LEVEL_ERROR   "error"

Definition at line 79 of file enums.h.

◆ OPT_LOG_LEVEL_FATAL

#define OPT_LOG_LEVEL_FATAL   "fatal"

Definition at line 80 of file enums.h.

◆ OPT_LOG_LEVEL_INFO

#define OPT_LOG_LEVEL_INFO   "info"

Definition at line 77 of file enums.h.

◆ OPT_LOG_LEVEL_WARN

#define OPT_LOG_LEVEL_WARN   "warn"

Definition at line 78 of file enums.h.

◆ OPT_PALETTE_BLOCKS

#define OPT_PALETTE_BLOCKS   "blocks"

Definition at line 106 of file enums.h.

◆ OPT_PALETTE_COOL

#define OPT_PALETTE_COOL   "cool"

Definition at line 109 of file enums.h.

◆ OPT_PALETTE_CUSTOM

#define OPT_PALETTE_CUSTOM   "custom"

Definition at line 110 of file enums.h.

◆ OPT_PALETTE_DIGITAL

#define OPT_PALETTE_DIGITAL   "digital"

Definition at line 107 of file enums.h.

◆ OPT_PALETTE_MINIMAL

#define OPT_PALETTE_MINIMAL   "minimal"

Definition at line 108 of file enums.h.

◆ OPT_PALETTE_STANDARD

#define OPT_PALETTE_STANDARD   "standard"

Definition at line 105 of file enums.h.

◆ OPT_RECONNECT_AUTO

#define OPT_RECONNECT_AUTO   "auto"

Definition at line 121 of file enums.h.

◆ OPT_RECONNECT_OFF

#define OPT_RECONNECT_OFF   "off"

Definition at line 120 of file enums.h.

◆ OPT_RENDER_MODE_BACKGROUND

#define OPT_RENDER_MODE_BACKGROUND   "background"

Definition at line 115 of file enums.h.

◆ OPT_RENDER_MODE_BG

#define OPT_RENDER_MODE_BG   "bg"

Definition at line 116 of file enums.h.

◆ OPT_RENDER_MODE_FG

#define OPT_RENDER_MODE_FG   "fg"

Definition at line 114 of file enums.h.

◆ OPT_RENDER_MODE_FOREGROUND

#define OPT_RENDER_MODE_FOREGROUND   "foreground"

Definition at line 113 of file enums.h.

◆ OPT_RENDER_MODE_HALF_BLOCK

#define OPT_RENDER_MODE_HALF_BLOCK   "half-block"

Definition at line 117 of file enums.h.

Function Documentation

◆ options_get_enum_entries()

const enum_to_string_entry_t * options_get_enum_entries ( const char *  option_name,
size_t *  entry_count 
)

Get enum entries with descriptions for an option.

Returns entries containing both string values and descriptions for shell completion.

Parameters
option_nameOption long name (e.g., "log-level")
entry_countOUTPUT: Number of entries returned
Returns
Array of enum entries, or NULL if not an enum option

Get enum entries with descriptions for an option.

Returns entries containing both string values and descriptions for shell completion. Used by zsh completion to show descriptions alongside values.

Parameters
option_nameOption long name (e.g., "log-level")
entry_countOUTPUT: Number of entries returned
Returns
Array of enum entries, or NULL if not an enum option

Definition at line 134 of file enums.c.

134 {
135 if (!option_name || !entry_count) {
136 return NULL;
137 }
138
139 for (size_t i = 0; enum_registry[i].option_name != NULL; i++) {
140 if (strcmp(enum_registry[i].option_name, option_name) == 0) {
141 /* Count entries up to terminator */
142 size_t count = 0;
143 for (size_t j = 0; enum_registry[i].map[j].enum_value != -1; j++) {
144 count++;
145 }
146 *entry_count = count;
147 return enum_registry[i].map;
148 }
149 }
150
151 *entry_count = 0;
152 return NULL;
153}
const char * option_name
Option long name (e.g., "log-level")
Definition enums.c:107
const enum_to_string_entry_t * map
Mapping array from enum values to strings.
Definition enums.c:108
int enum_value
The numeric enum value.
Definition enums.h:28

References enum_to_string_entry_t::enum_value, enum_map_descriptor_t::map, and enum_map_descriptor_t::option_name.

◆ options_get_enum_values()

const char ** options_get_enum_values ( const char *  option_name,
size_t *  value_count 
)

Get enum values for an option.

Parameters
option_nameOption long name (e.g., "log-level")
value_countOUTPUT: Number of values returned
Returns
Array of valid string values, or NULL if not an enum option

Get enum values for an option.

Extracts the list of valid string values for an enum option. For options with aliases (like render-mode which has "foreground" and "fg"), both values are included.

Parameters
option_nameOption long name (e.g., "log-level")
value_countOUTPUT: Number of values returned
Returns
Array of valid string values, or NULL if not an enum option

Definition at line 166 of file enums.c.

166 {
167 if (!option_name || !value_count) {
168 return NULL;
169 }
170
171 /* Find the option's mapping in the registry */
172 const enum_map_descriptor_t *descriptor = NULL;
173 for (size_t i = 0; enum_registry[i].option_name != NULL; i++) {
174 if (strcmp(enum_registry[i].option_name, option_name) == 0) {
175 descriptor = &enum_registry[i];
176 break;
177 }
178 }
179
180 if (!descriptor || !descriptor->map) {
181 *value_count = 0;
182 return NULL;
183 }
184
185 /* Count non-terminator entries */
186 size_t count = 0;
187 for (size_t i = 0; descriptor->map[i].enum_value != -1; i++) {
188 count++;
189 }
190
191 /* Build array of unique strings (skip duplicates from aliases) */
192 const char **values = SAFE_MALLOC(count * sizeof(const char *), const char **);
193 size_t unique_count = 0;
194
195 for (size_t i = 0; descriptor->map[i].enum_value != -1; i++) {
196 const char *str = descriptor->map[i].string;
197
198 /* Check if we already have this string (for aliases) */
199 bool already_added = false;
200 for (size_t j = 0; j < unique_count; j++) {
201 if (strcmp(values[j], str) == 0) {
202 already_added = true;
203 break;
204 }
205 }
206
207 if (!already_added) {
208 values[unique_count++] = str;
209 }
210 }
211
212 *value_count = unique_count;
213 return values;
214}
#define SAFE_MALLOC(size, cast)
Definition common.h:264
Descriptor for an enum option with its string value mapping.
Definition enums.c:106
const char * string
The string representation of that enum value.
Definition enums.h:29

References enum_to_string_entry_t::enum_value, enum_map_descriptor_t::map, enum_map_descriptor_t::option_name, SAFE_MALLOC, and enum_to_string_entry_t::string.

Referenced by asciichat_suggest_enum_value().

◆ options_is_enum_option()

bool options_is_enum_option ( const char *  option_name)

Check if an option has enum values.

Parameters
option_nameOption long name
Returns
true if option has enum values, false otherwise

Definition at line 222 of file enums.c.

222 {
223 if (!option_name) {
224 return false;
225 }
226
227 for (size_t i = 0; enum_registry[i].option_name != NULL; i++) {
228 if (strcmp(enum_registry[i].option_name, option_name) == 0) {
229 return true;
230 }
231 }
232
233 return false;
234}

References enum_map_descriptor_t::option_name.