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

Go to the source code of this file.

Functions

ui_session_action_t ui_session_key (keyboard_key_t key, double *saved_volume)

Function Documentation

◆ ui_session_key()

ui_session_action_t ui_session_key ( keyboard_key_t key,
double * saved_volume )

Mutates shared options for settings keys; returns an action for the host.

Definition at line 111 of file session_input.c.

111 {
112 switch ((int)key) {
113 case 3: // Ctrl-C from the terminal input stream
114 log_info("Ctrl-C key received from terminal input");
115 return UI_ACTION_QUIT;
116 case 'q':
117 return UI_ACTION_QUIT;
118 case 'Q':
120 case KEY_QUESTION:
121 return UI_ACTION_HELP;
122 case '[':
124 case ']':
125 return UI_ACTION_LOGS;
126 case KEY_ESCAPE:
127 return UI_ACTION_CLOSE;
128 case KEY_SHIFT_ESCAPE:
130 case KEY_LEFT:
131 return UI_ACTION_SEEK_BACK;
132 case KEY_RIGHT:
134 case KEY_SPACE:
135 return UI_ACTION_PAUSE;
136 case KEY_BACKTICK:
137 return UI_ACTION_DEBUG;
138 // ===== VOLUME CONTROLS =====
139 case KEY_DOWN: { // Decrease volume 10%
140 double current_volume = GET_OPTION(speakers_volume);
141 double new_volume = clamp_volume(current_volume - 0.1);
142 options_adjust("speakers_volume", key == KEY_DOWN ? -0.1 : 0.1);
143
144 double verify_volume = GET_OPTION(speakers_volume);
145 log_info("Volume DOWN: %.0f%% → %.0f%% (verified: %.0f%%)",
146 current_volume * 100.0, new_volume * 100.0, verify_volume * 100.0);
147 return UI_ACTION_VOLUME;
148 }
149
150 case KEY_UP: { // Increase volume 10%
151 double current_volume = GET_OPTION(speakers_volume);
152 double new_volume = clamp_volume(current_volume + 0.1);
153 options_adjust("speakers_volume", key == KEY_DOWN ? -0.1 : 0.1);
154
155 double verify_volume = GET_OPTION(speakers_volume);
156 log_info("Volume UP: %.0f%% → %.0f%% (verified: %.0f%%)",
157 current_volume * 100.0, new_volume * 100.0, verify_volume * 100.0);
158 return UI_ACTION_SETTINGS;
159 }
160
161 // ===== COLOR MODE CONTROL =====
162 case KEY_C:
163 case 'C': {
164 int current_mode = (int)GET_OPTION(color_mode);
165 int next_mode = next_color_mode(current_mode);
166 options_cycle("color_mode", 4);
167
168 const char *mode_names[] = {"Mono", "16-color", "256-color", "Truecolor"};
169 if (next_mode >= 0 && next_mode <= 3) {
170 log_info("Color mode: %s", mode_names[next_mode]);
171 }
172 return UI_ACTION_SETTINGS;
173 }
174
175 // ===== MUTE CONTROL =====
176 case KEY_M:
177 case 'M': {
178 if (toggle_mute(saved_volume) != ASCIICHAT_OK)
179 log_warn("Could not toggle mute");
180
181 return UI_ACTION_SETTINGS;
182 }
183
184 // ===== RENDER MODE CONTROL =====
185 case 'r': {
186 int current_mode = (int)GET_OPTION(render_mode);
187 int next_mode = next_render_mode(current_mode);
188 options_cycle("render_mode", 3);
189
190 const char *mode_names[] = {"Foreground", "Background", "Half-block"};
191 if (next_mode >= 0 && next_mode <= 2) {
192 log_info("Render mode: %s", mode_names[next_mode]);
193 }
194 return UI_ACTION_SETTINGS;
195 }
196
197 // ===== TEXT RENDERER CONTROL =====
198 case 'R': {
199 if (options_cycle("renderer", 2) != ASCIICHAT_OK) {
200 log_warn("Could not change text renderer");
201 return UI_ACTION_SETTINGS;
202 }
203 log_info("Text renderer: %s", GET_OPTION(renderer) == ASCII_RENDERER_GLYPH
204 ? "Glyph"
205 : "Luminance");
206 return UI_ACTION_SETTINGS;
207 }
208
209 // ===== FRAME STABILIZATION CONTROL =====
210 case 'S': {
211 if (options_toggle("stabilize") != ASCIICHAT_OK)
212 log_warn("Could not toggle frame stabilization");
213 else
214 log_info("Frame stabilization: %s",
215 GET_OPTION(stabilize) ? "enabled" : "disabled");
216 return UI_ACTION_SETTINGS;
217 }
218
219 // ===== COLOR FILTER CONTROL =====
220 case KEY_F:
221 case 'F': {
222 int current_filter = (int)GET_OPTION(color_filter);
223 int next_filter = next_color_filter(current_filter);
224 options_cycle("color_filter", 13);
225
226 if (next_filter >= 0 && next_filter < (int)COLOR_FILTER_COUNT) {
227 log_info("Color filter: %s", COLOR_FILTER_NAMES[next_filter]);
228 }
229 return UI_ACTION_SETTINGS;
230 }
231
232 // ===== HORIZONTAL FLIP CONTROL =====
233 case 'X':
234 case 'x': {
235 log_info("✓ X KEY PRESSED - handling horizontal flip");
236 bool current_flip_x = (bool)GET_OPTION(flip_x);
237 options_toggle("flip_x");
238 log_info("Horizontal flip: %s (was: %s)",
239 !current_flip_x ? "enabled" : "disabled",
240 current_flip_x ? "enabled" : "disabled");
241 return UI_ACTION_SETTINGS;
242 }
243
244 // ===== VERTICAL FLIP CONTROL =====
245 case 'Y':
246 case 'y': {
247 bool current_flip_y = (bool)GET_OPTION(flip_y);
248 options_toggle("flip_y");
249 log_info("Vertical flip: %s", !current_flip_y ? "enabled" : "disabled");
250 return UI_ACTION_SETTINGS;
251 }
252
253 // ===== MATRIX RAIN EFFECT CONTROL =====
254 case KEY_1: {
255 bool current_matrix = (bool)GET_OPTION(matrix_rain);
256 if (options_toggle("matrix_rain") != ASCIICHAT_OK)
257 return UI_ACTION_SETTINGS;
258 log_info("Matrix rain effect: %s",
259 !current_matrix ? "enabled" : "disabled");
260 return UI_ACTION_SETTINGS;
261 }
262
263 case KEY_2: {
264 if (!GET_OPTION(audio_enabled)) {
265 log_info("Audio waveform requires audio to be enabled");
266 return UI_ACTION_SETTINGS;
267 }
268 bool enabled = !GET_OPTION(waveform);
269 if (options_toggle("waveform") != ASCIICHAT_OK)
270 return UI_ACTION_SETTINGS;
271 log_info("Audio waveform: %s", enabled ? "enabled" : "disabled");
272 return UI_ACTION_SETTINGS;
273 }
274
275 case KEY_3: {
276 if (!GET_OPTION(audio_enabled)) {
277 log_info("Audio frequency display requires audio to be enabled");
278 return UI_ACTION_SETTINGS;
279 }
280 bool enabled = !GET_OPTION(fft);
282 log_error("Unable to initialize FFTW frequency display");
283 return UI_ACTION_SETTINGS;
284 }
285 if (options_toggle("fft") != ASCIICHAT_OK)
286 return UI_ACTION_SETTINGS;
287 log_info("Audio frequency display: %s", enabled ? "enabled" : "disabled");
288 return UI_ACTION_SETTINGS;
289 }
290
291 case 'w':
292 case 'W': {
293 if (options_toggle("face_follow") == ASCIICHAT_OK)
294 log_info("Face follow: %s",
295 GET_OPTION(face_follow) ? "enabled" : "disabled");
296 return UI_ACTION_SETTINGS;
297 }
298
299 case 'z':
300 case 'Z': {
301 if (options_set_int("zalgo", GET_OPTION(zalgo) ? 0 : 8) == ASCIICHAT_OK)
302 log_info("Zalgo intensity: %d", GET_OPTION(zalgo));
303 return UI_ACTION_SETTINGS;
304 }
305
306 // ===== FPS COUNTER TOGGLE =====
307 case KEY_MINUS: {
308 bool current = (bool)GET_OPTION(fps_counter);
309 options_toggle("fps_counter");
310 log_info("FPS counter: %s", !current ? "enabled" : "disabled");
311 return UI_ACTION_SETTINGS;
312 }
313
314 default:
315 return UI_ACTION_NONE;
316 }
317}
int color_mode
Definition fft.c:26
asciichat_error_t audio_visualization_fft_init(void)
Definition fft.c:82
terminal_render_mode_t render_mode
Definition fft.c:27
bool enabled
Is filtering active?
Definition grep.c:63
@ ASCIICHAT_OK
Definition error_codes.h:50
#define log_warn(...)
Log a WARN message.
Definition log/log.h:591
#define log_error(...)
Log an ERROR message.
Definition log/log.h:604
#define log_info(...)
Log an INFO message.
Definition log/log.h:578
#define GET_OPTION(field)
Definition options.h:1339
asciichat_error_t options_set_int(const char *name, int value)
Check if an option was explicitly set via command-line.
Definition rcu.c:964
asciichat_error_t options_adjust(const char *name, double amount)
Definition rcu.c:989
asciichat_error_t options_toggle(const char *name)
Definition rcu.c:985
asciichat_error_t options_cycle(const char *name, int count)
Definition rcu.c:995
@ ASCII_RENDERER_GLYPH

References ASCII_RENDERER_GLYPH, ASCIICHAT_OK, audio_visualization_fft_init(), color_mode, enabled, GET_OPTION, log_error, log_info, log_warn, options_adjust(), options_cycle(), options_set_int(), options_toggle(), render_mode, UI_ACTION_CLOSE, UI_ACTION_DEBUG, UI_ACTION_FORCE_QUIT, UI_ACTION_HELP, UI_ACTION_LOGS, UI_ACTION_NONE, UI_ACTION_PAUSE, UI_ACTION_QUIT, UI_ACTION_SEEK_BACK, UI_ACTION_SEEK_FORWARD, UI_ACTION_SETTINGS, UI_ACTION_TOGGLE_MEDIA, and UI_ACTION_VOLUME.

Referenced by ui_session_input().