ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
lib/options/registry/display.c
Go to the documentation of this file.
1
12
13#include <options/registry/common.h>
14#include <options/registry/metadata.h>
16
17#include <options/parsers.h>
18#include <ascii-chat/common.h>
19#include <string.h>
20#include <stdlib.h>
21#include <math.h>
22
24static bool parse_zalgo(const char *arg, void *dest, char **error_msg) {
25 int level = 7;
26 if (arg) {
27 if (strlen(arg) == 1 && arg[0] >= '1' && arg[0] <= '9') {
28 level = arg[0] - '0';
29 } else if (strcmp(arg, "10") == 0) {
30 level = 10;
31 } else {
32 // Callback errors are released with SAFE_FREE() by the option parser.
33 *error_msg = platform_strdup("--zalgo requires an integer from 1 to 10 (bare --zalgo uses 7)");
34 return false;
35 }
36 }
37 *(int *)dest = level;
38 return true;
39}
40
41static const char *renderer_values[] = {"luminance", "glyph", NULL};
42static const int renderer_integers[] = {ASCII_RENDERER_LUMINANCE, ASCII_RENDERER_GLYPH};
43static const char *renderer_descriptions[] = {"Map brightness to the selected palette", "Experimental glyph shape matching", NULL};
44static const ascii_renderer_t default_renderer = ASCII_RENDERER_DEFAULT;
45
46static bool parse_explicit_palette(const char *arg, void *dest, char **error_msg) {
47 if (!parse_palette_type(arg, dest, error_msg))
48 return false;
49 options_t *opts = (options_t *)((char *)dest - offsetof(options_t, palette_type));
50 opts->palette_explicit = true;
51 return true;
52}
53
54static bool parse_ascii_renderer(const char *arg, void *dest, char **error_msg) {
55 if (arg && dest && strcmp(arg, "luminance") == 0) {
57 return true;
58 }
59 if (arg && dest && strcmp(arg, "glyph") == 0) {
61 return true;
62 }
63 if (error_msg)
64 *error_msg = platform_strdup("--renderer requires luminance or glyph");
65 return false;
66}
67
68static bool parse_fft_scale(const char *arg, void *dest, char **error_msg) {
69 fft_scale_t parsed = {.mode = FFT_SCALE_DB, .min_db = -62.0f, .max_db = -6.0f};
70 if (!arg || !*arg) {
71 *error_msg = platform_strdup("--fft-scale requires linear, log, or MIN:MAX dB");
72 return false;
73 }
74 if (!strcmp(arg, "linear")) {
75 parsed.mode = FFT_SCALE_LINEAR;
76 } else if (!strcmp(arg, "log")) {
77 parsed.mode = FFT_SCALE_LOG;
78 } else {
79 char *end = NULL;
80 parsed.min_db = strtof(arg, &end);
81 if (end == arg || *end != ':')
82 goto invalid;
83 char *max_end = NULL;
84 parsed.max_db = strtof(end + 1, &max_end);
85 if (max_end == end + 1 || *max_end != '\0' || !isfinite(parsed.min_db) || !isfinite(parsed.max_db) || parsed.min_db < -120.0f || parsed.max_db > 0.0f || parsed.max_db - parsed.min_db < 12.0f ||
86 parsed.max_db <= parsed.min_db)
87 goto invalid;
88 parsed.mode = FFT_SCALE_DB;
89 }
90 SAFE_STRNCPY((char *)dest, arg, 32);
91 return true;
92invalid:
93 *error_msg = platform_strdup("--fft-scale dB range must be MIN:MAX with -120 <= MIN < MAX <= 0 and at least 12 dB span");
94 return false;
95}
96
97static const char default_fft_scale[] = "-62:-6";
98
99// ============================================================================
100// DISPLAY CATEGORY - Display layout options
101// ============================================================================
102static const bool default_face_follow_value = false;
103static const bool default_stabilize_value = true;
104
106 {.long_name = "zalgo",
107 .type = OPTION_TYPE_CALLBACK,
108 .offset = offsetof(options_t, zalgo),
109 .default_value_size = sizeof(int),
110 .help_text = "Add combining marks at intensity 1-10 (default when enabled: 7). Omit to disable. Terminal/text output only.",
111 .group = "DISPLAY",
112 .arg_placeholder = "LEVEL",
113 .env_var_name = "ASCII_CHAT_ZALGO",
114 .parse_fn = parse_zalgo,
115 .optional_arg = true,
117 .metadata = {.numeric_range = {1, 10, 1}, .input_type = OPTION_INPUT_NUMERIC}},
118 {"waveform",
119 '\0',
121 offsetof(options_t, waveform),
122 &default_waveform_value,
123 sizeof(bool),
124 "Replace the video image with a live waveform of the source selected by --audio-source.",
125 "DISPLAY",
126 NULL,
127 false,
128 "ASCII_CHAT_WAVEFORM",
129 NULL,
130 NULL,
131 false,
132 false,
134 {0},
135 NULL},
136 {"fft",
137 '\0',
139 offsetof(options_t, fft),
140 &default_fft_value,
141 sizeof(bool),
142 "Replace the video image with a live scrolling frequency display for the source selected by --audio-source.",
143 "DISPLAY",
144 NULL,
145 false,
146 "ASCII_CHAT_FFT",
147 NULL,
148 NULL,
149 false,
150 false,
152 {0},
153 NULL},
154 {"fft-scale",
155 '\0',
157 offsetof(options_t, fft_scale),
158 &default_fft_scale,
159 sizeof(((options_t *)0)->fft_scale),
160 "FFT amplitude scale: linear, log, or MIN:MAX dB (default -62:-6).",
161 "DISPLAY",
162 "SCALE",
163 false,
164 "ASCII_CHAT_FFT_SCALE",
165 NULL,
166 parse_fft_scale,
167 false,
168 false,
170 {.input_type = OPTION_INPUT_STRING},
171 NULL},
172 // DISPLAY GROUP (client, mirror, discovery)
173 {"color-filter",
174 '\0',
176 offsetof(options_t, color_filter),
177 &default_color_filter_value,
178 sizeof(color_filter_t),
179 "Apply a monochromatic color tint to grayscale video. Values: none, black, white, green, magenta, fuchsia, "
180 "orange, teal, cyan, pink, red, yellow, rainbow. Using --color-filter automatically sets --color-mode to mono.",
181 "DISPLAY",
182 NULL,
183 false,
184 "ASCII_CHAT_COLOR_FILTER",
185 NULL,
187 false,
188 false,
190 {.enum_values = g_color_filter_values, .enum_descriptions = g_color_filter_descs, .enum_integer_values = g_color_filter_integers, .input_type = OPTION_INPUT_ENUM},
191 NULL},
192 {"render-mode",
193 'M',
195 offsetof(options_t, render_mode),
196 &default_render_mode_value,
197 sizeof(terminal_render_mode_t),
198 "Render mode of text for your client to display. Values: foreground, background, half-block. Press 'r' during "
199 "rendering to cycle.",
200 "DISPLAY",
201 NULL,
202 false,
203 "ASCII_CHAT_RENDER_MODE",
204 NULL,
206 false,
207 false,
209 {.enum_values = g_render_values, .enum_descriptions = g_render_descs, .enum_integer_values = g_render_integers, .input_type = OPTION_INPUT_ENUM},
210 NULL},
211 {"palette",
212 'P',
214 offsetof(options_t, palette_type),
215 &default_palette_type_value,
216 sizeof(palette_type_t),
217 "Palette type with which to render images to text art. Values: standard, blocks, digital, minimal, cool, "
218 "custom. All but 'custom' are built-in presets that all look different and nice. Try them out.",
219 "DISPLAY",
220 NULL,
221 false,
222 "ASCII_CHAT_PALETTE",
223 NULL,
224 parse_explicit_palette,
225 false,
226 false,
228 {.enum_values = g_palette_values, .enum_descriptions = g_palette_descs, .enum_integer_values = g_palette_integers, .input_type = OPTION_INPUT_ENUM},
229 NULL},
230 {"palette-chars",
231 'C',
233 offsetof(options_t, palette_custom),
234 "",
235 0,
236 "Ordered sequence of characters from darkest to brightest to use with custom palette (--palette=custom) for "
237 "rendering images to text art for your client. These characters only will be used to create the rendered output. "
238 "Can be UTF-8 content (see --utf8).",
239 "DISPLAY",
240 "STRING",
241 false,
242 "ASCII_CHAT_PALETTE_CHARS",
243 NULL,
245 false,
246 false,
248 {0},
249 NULL},
250 {.long_name = "renderer",
251 .type = OPTION_TYPE_CALLBACK,
252 .offset = offsetof(options_t, renderer),
253 .default_value = &default_renderer,
254 .default_value_size = sizeof(ascii_renderer_t),
255 .help_text = "Character selection: glyph (default) or luminance matching. Glyph supports printable "
256 "ASCII and Unicode block elements; unsupported palette characters are rejected.",
257 .group = "DISPLAY",
258 .arg_placeholder = "luminance|glyph",
259 .env_var_name = "ASCII_CHAT_RENDERER",
260 .parse_fn = parse_ascii_renderer,
262 .metadata = {.enum_values = renderer_values, .enum_descriptions = renderer_descriptions, .enum_integer_values = renderer_integers, .input_type = OPTION_INPUT_ENUM}},
263 {.long_name = "stabilize",
264 .type = OPTION_TYPE_BOOL,
265 .offset = offsetof(options_t, stabilize),
266 .default_value = &default_stabilize_value,
267 .default_value_size = sizeof(bool),
268 .help_text = "Reduce character and color flicker between video frames in all render modes.",
269 .group = "DISPLAY",
270 .env_var_name = "ASCII_CHAT_STABILIZE",
272 {"stretch",
273 '\0',
275 offsetof(options_t, stretch),
276 &default_stretch_value,
277 sizeof(bool),
278 "Allow aspect ratio distortion of image for rendering ascii output. This can allow the rendered ascii to fill "
279 "your terminal.",
280 "DISPLAY",
281 NULL,
282 false,
283 "ASCII_CHAT_STRETCH",
284 NULL,
285 NULL,
286 false,
287 false,
289 {0},
290 NULL},
291 {"fps",
292 '\0',
294 offsetof(options_t, fps),
295 &default_fps_value,
296 sizeof(int),
297 "Target framerate for rendering (0 = auto, 1-144).",
298 "DISPLAY",
299 NULL,
300 false,
301 "ASCII_CHAT_FPS",
302 NULL,
303 NULL,
304 false,
305 false,
307 {.numeric_range = {0, 144, 1}, .examples = g_fps_examples, .input_type = OPTION_INPUT_NUMERIC},
308 NULL},
309 {"fps-counter",
310 '\0',
312 offsetof(options_t, fps_counter),
313 &default_fps_counter_value,
314 sizeof(bool),
315 "Show FPS counter overlay in top-right corner. Press '-' to toggle.",
316 "DISPLAY",
317 NULL,
318 false,
319 "ASCII_CHAT_FPS_COUNTER",
320 NULL,
321 NULL,
322 false,
323 false,
325 {0},
326 NULL},
327 {"snapshot",
328 'S',
330 offsetof(options_t, snapshot_mode),
331 &default_snapshot_mode_value,
332 sizeof(bool),
333 "Snapshot mode (one frame and exit).",
334 "DISPLAY",
335 NULL,
336 false,
337 "ASCII_CHAT_SNAPSHOT",
338 NULL,
339 NULL,
340 false,
341 false,
343 {0},
344 NULL},
345 {"snapshot-delay",
346 'D',
348 offsetof(options_t, snapshot_delay),
349 &default_snapshot_delay_value,
350 sizeof(double),
351 "Snapshot delay in seconds. The timer starts right before the client-side program prints the first frame. "
352 "--snapshot --snapshot-delay=0 will print the first frame and exit.",
353 "DISPLAY",
354 "SECONDS",
355 false,
356 "ASCII_CHAT_SNAPSHOT_DELAY",
357 NULL,
358 NULL,
359 false,
360 false,
362 {.numeric_range = {0, 3600, 0}, .input_type = OPTION_INPUT_NUMERIC},
363 NULL},
364 {"matrix",
365 '\0',
367 offsetof(options_t, matrix_rain),
368 &default_matrix_rain_value,
369 sizeof(bool),
370 "Enable Matrix-style digital rain effect. Works with --render-mode truecolor|256 and --color-filter [color].",
371 "DISPLAY",
372 NULL,
373 false,
374 "ASCII_CHAT_MATRIX",
375 NULL,
376 NULL,
377 false,
378 false,
380 {0},
381 NULL},
382 {"face-follow",
383 '\0',
385 offsetof(options_t, face_follow),
386 &default_face_follow_value,
387 sizeof(bool),
388 "Automatically zoom and pan to follow your face, with smooth full-frame fallback.",
389 "DISPLAY",
390 NULL,
391 false,
392 "ASCII_CHAT_FACE_FOLLOW",
393 NULL,
394 NULL,
395 false,
396 false,
398 {0},
399 NULL},
400 {"flip-x",
401 '\0',
403 offsetof(options_t, flip_x),
404 &default_flip_x_value,
405 sizeof(bool),
406 "Flip video horizontally (X-axis). Webcam defaults to mirrored; media and audio animations do not. Explicit "
407 "choices apply to all sources until exit.",
408 "DISPLAY",
409 NULL,
410 false,
411 "ASCII_CHAT_FLIP_X",
412 NULL,
413 NULL,
414 false,
415 false,
417 {0},
418 NULL},
419 {"flip-y",
420 '\0',
422 offsetof(options_t, flip_y),
423 &default_flip_y_value,
424 sizeof(bool),
425 "Flip video vertically (Y-axis). Works with webcam, files, and streams.",
426 "DISPLAY",
427 NULL,
428 false,
429 "ASCII_CHAT_FLIP_Y",
430 NULL,
431 NULL,
432 false,
433 false,
435 {0},
436 NULL},
437
@ OPTION_INPUT_STRING
Free-form text input.
Definition builder.h:189
@ OPTION_INPUT_NUMERIC
Numeric value with optional min/max/step.
Definition builder.h:188
@ OPTION_INPUT_ENUM
Choose from fixed set of enum values.
Definition builder.h:187
@ OPTION_TYPE_INT
Integer value (–count 42).
Definition builder.h:172
@ OPTION_TYPE_DOUBLE
Floating point (–ratio 1.5).
Definition builder.h:174
@ OPTION_TYPE_STRING
String value (–name foo).
Definition builder.h:173
@ OPTION_TYPE_CALLBACK
Custom parser function.
Definition builder.h:175
@ OPTION_TYPE_BOOL
Boolean flag (–flag, no value).
Definition builder.h:171
terminal_render_mode_t render_mode
Definition fft.c:27
@ FFT_SCALE_LOG
Definition fft.h:12
@ FFT_SCALE_LINEAR
Definition fft.h:12
@ FFT_SCALE_DB
Definition fft.h:12
#define SAFE_STRNCPY(dst, src, size)
struct options_state options_t
Immutable, RCU-published snapshot of the application's runtime configuration.
#define ASCII_RENDERER_DEFAULT
Consolidated options structure.
Definition options.h:962
@ OPTION_MODE_CLIENT
Client mode (bit 1).
Definition options.h:936
@ OPTION_MODE_DISCOVERY
Discovery mode (bit 4).
Definition options.h:939
@ OPTION_MODE_MIRROR
Mirror mode (bit 2).
Definition options.h:937
palette_type_t
Built-in palette type enumeration.
Definition palette.h:96
⚙️ Common definitions, error codes, macros, and types shared throughout the application
const registry_entry_t g_display_entries[]
#define REGISTRY_TERMINATOR()
Initialize a terminator entry (sentinel value for array end) Uses designated initializers to properly...
🔢 Mathematical Utility Functions
const int g_palette_integers[]
Definition metadata.c:87
const char * g_color_filter_descs[]
Definition metadata.c:67
const char * g_palette_descs[]
Definition metadata.c:88
const char * g_color_filter_values[]
Definition metadata.c:62
const char * g_render_descs[]
Definition metadata.c:104
const int g_render_integers[]
Definition metadata.c:101
const char * g_fps_examples[]
Definition metadata.c:143
const char * g_palette_values[]
Definition metadata.c:86
const int g_color_filter_integers[]
Definition metadata.c:65
const char * g_render_values[]
Definition metadata.c:100
bool parse_render_mode(const char *arg, void *dest, char **error_msg)
Parse render mode option.
Definition parsers.c:238
bool parse_palette_type(const char *arg, void *dest, char **error_msg)
Parse palette type option.
Definition parsers.c:321
bool parse_color_filter(const char *arg, void *dest, char **error_msg)
Parse color filter option.
Definition parsers.c:207
bool parse_palette_chars(const char *arg, void *dest, char **error_msg)
Parse custom palette characters option.
Definition parsers.c:856
Custom option parsers for enum types.
char * platform_strdup(const char *s)
🔤 String Manipulation and Shell Escaping Utilities
fft_scale_mode_t mode
Definition fft.h:15
float max_db
Definition fft.h:17
float min_db
Definition fft.h:16
bool palette_explicit
Palette explicitly selected.
Definition options.h:1223
Registry entry - stores option definition with mode bitmask and metadata.