ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
terminal.h
Go to the documentation of this file.
1#pragma once
2
26#include <stdbool.h>
27#include <stdint.h>
28#include "../common.h"
29
30// ============================================================================
31// Platform-Specific Signal Definitions
32// ============================================================================
33
34#ifdef _WIN32
35// Windows doesn't have these signals natively
36#define SIGWINCH 28 // Window size change (not supported on Windows)
37#define SIGTERM 15 // Termination signal (limited support on Windows)
38#endif
39
40/* ============================================================================
41 * Terminal Data Structures
42 * ============================================================================
43 */
44
55typedef struct {
56 int rows;
57 int cols;
59
60/* ============================================================================
61 * Terminal Control Functions
62 * @{
63 */
64
79
99
115
130
144
158
174
192
207
227
242
259
274
288
304
318
335
354
374
390
407
410/* ============================================================================
411 * Terminal Detection and Capabilities
412 * @{
413 */
414
436
458
475
511
523typedef struct {
525 int fd;
527 const char *path;
530} tty_info_t;
531
532/* ============================================================================
533 * Terminal Capability Detection Functions
534 * @{
535 */
536
560
575
589bool is_valid_tty_path(const char *path);
590
608asciichat_error_t get_terminal_size(unsigned short int *width, unsigned short int *height);
609
624
640
658
672
691
694/* ============================================================================
695 * Windows Console Resize Detection
696 * @{
697 *
698 * Windows-specific functionality for detecting console window resize events.
699 * Unix systems use SIGWINCH signal, but Windows requires polling or event
700 * monitoring, so a background thread is used.
701 */
702
703#ifdef _WIN32
718typedef void (*terminal_resize_callback_t)(int cols, int rows);
719
738int terminal_start_resize_detection(terminal_resize_callback_t callback);
739
751void terminal_stop_resize_detection(void);
752
754#endif
unsigned int uint32_t
Definition common.h:58
unsigned char uint8_t
Definition common.h:56
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:46
asciichat_error_t terminal_reset(int fd)
Reset terminal to default state.
asciichat_error_t terminal_clear_scrollback(int fd)
Clear terminal scrollback buffer.
bool is_valid_tty_path(const char *path)
Check if a TTY path is valid.
terminal_capabilities_t apply_color_mode_override(terminal_capabilities_t caps)
Apply command-line overrides to detected capabilities.
asciichat_error_t terminal_get_cursor_position(int *row, int *col)
Get current cursor position.
asciichat_error_t terminal_cursor_home(int fd)
Move cursor to home position (top-left)
const char * terminal_color_level_name(terminal_color_mode_t level)
Get name of color level.
tty_info_t get_current_tty(void)
Get current TTY information.
bool terminal_supports_unicode(void)
Check if terminal supports unicode.
bool terminal_supports_utf8(void)
Check if terminal supports UTF-8.
asciichat_error_t terminal_set_title(const char *title)
Set terminal window title.
asciichat_error_t terminal_clear_screen(void)
Clear the terminal screen.
terminal_capability_flags_t
Terminal capability flags (bitmask)
Definition terminal.h:446
asciichat_error_t terminal_set_raw_mode(bool enable)
Set terminal to raw mode.
asciichat_error_t terminal_save_cursor(void)
Save cursor position.
asciichat_error_t terminal_get_size(terminal_size_t *size)
Get terminal size.
asciichat_error_t terminal_move_cursor(int row, int col)
Move cursor to specified position.
asciichat_error_t terminal_restore_cursor(void)
Restore saved cursor position.
void test_terminal_output_modes(void)
Test terminal output modes.
asciichat_error_t terminal_set_scroll_region(int top, int bottom)
Set scroll region.
void terminal_enable_ansi(void)
Enable ANSI escape sequences.
asciichat_error_t terminal_ring_bell(void)
Ring terminal bell.
void print_terminal_capabilities(const terminal_capabilities_t *caps)
Print terminal capabilities to stdout.
terminal_capabilities_t detect_terminal_capabilities(void)
Detect terminal capabilities.
asciichat_error_t terminal_flush(int fd)
Flush terminal output.
render_mode_t
Render mode preferences.
Definition terminal.h:467
terminal_color_mode_t
Terminal color support levels.
Definition terminal.h:424
asciichat_error_t terminal_set_buffering(bool line_buffered)
Set terminal buffering mode.
bool terminal_supports_color(void)
Check if terminal supports color.
const char * terminal_capabilities_summary(const terminal_capabilities_t *caps)
Get summary string of terminal capabilities.
asciichat_error_t get_terminal_size(unsigned short int *width, unsigned short int *height)
Get terminal size with multiple fallback methods.
asciichat_error_t terminal_set_echo(bool enable)
Set terminal echo mode.
asciichat_error_t terminal_hide_cursor(int fd, bool hide)
Hide or show cursor.
@ TERM_CAP_COLOR_256
256-color support (TERM_CAP_COLOR_256)
Definition terminal.h:450
@ TERM_CAP_COLOR_16
16-color support (TERM_CAP_COLOR_16)
Definition terminal.h:448
@ TERM_CAP_UTF8
UTF-8 encoding support (TERM_CAP_UTF8)
Definition terminal.h:454
@ TERM_CAP_BACKGROUND
Background color support (TERM_CAP_BACKGROUND)
Definition terminal.h:456
@ TERM_CAP_COLOR_TRUE
Truecolor support (TERM_CAP_COLOR_TRUE)
Definition terminal.h:452
@ RENDER_MODE_FOREGROUND
Foreground colors only (text color)
Definition terminal.h:469
@ RENDER_MODE_BACKGROUND
Background colors (block colors)
Definition terminal.h:471
@ RENDER_MODE_HALF_BLOCK
Unicode half-block characters (mixed foreground/background)
Definition terminal.h:473
@ TERM_COLOR_NONE
No color support (monochrome terminal)
Definition terminal.h:428
@ TERM_COLOR_16
16-color support (standard ANSI colors)
Definition terminal.h:430
@ TERM_COLOR_256
256-color support (extended ANSI palette)
Definition terminal.h:432
@ TERM_COLOR_AUTO
Auto-detect color support from terminal capabilities.
Definition terminal.h:426
@ TERM_COLOR_TRUECOLOR
24-bit truecolor support (RGB colors)
Definition terminal.h:434
Complete terminal capabilities structure.
Definition terminal.h:485
int palette_type
Palette type enum value (palette_type_t)
Definition terminal.h:505
terminal_color_mode_t color_level
Detected color support level (terminal_color_mode_t)
Definition terminal.h:487
uint8_t desired_fps
Client's desired frame rate (1-144 FPS)
Definition terminal.h:509
render_mode_t render_mode
Preferred rendering mode (render_mode_t)
Definition terminal.h:497
bool utf8_support
True if terminal supports UTF-8 encoding.
Definition terminal.h:493
uint32_t capabilities
Capability flags bitmask (terminal_capability_flags_t)
Definition terminal.h:489
uint32_t color_count
Maximum number of colors (16, 256, or 16777216)
Definition terminal.h:491
bool detection_reliable
True if detection is confident (reliable detection)
Definition terminal.h:495
bool wants_background
True if background colors are preferred.
Definition terminal.h:503
Terminal size structure.
Definition terminal.h:55
int cols
Number of columns (width) in terminal.
Definition terminal.h:57
int rows
Number of rows (height) in terminal.
Definition terminal.h:56
TTY detection and management structure.
Definition terminal.h:523
bool owns_fd
True if we opened the FD and should close it, false otherwise.
Definition terminal.h:529
int fd
File descriptor for TTY access.
Definition terminal.h:525
const char * path
Path to TTY device (e.g., "/dev/tty", "CON", etc.)
Definition terminal.h:527