ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
terminal.c File Reference

Terminal abstraction for WASM/Emscripten via EM_JS bridge to xterm.js. More...

Go to the source code of this file.

Functions

 EM_JS (int, js_get_terminal_cols,(), { return Module.xterm ? Module.xterm.cols :80;})
 
 EM_JS (int, js_get_terminal_rows,(), { return Module.xterm ? Module.xterm.rows :24;})
 
 EM_JS (void, js_terminal_write,(const char *data, int len), { if(Module.xterm) { Module.xterm.write(UTF8ToString(data, len));} })
 
int platform_get_terminal_size (int *cols, int *rows)
 
int platform_write_terminal (const char *data, size_t len)
 
int platform_set_terminal_raw_mode (bool enable)
 
int platform_read_keyboard (char *buffer, size_t len)
 
bool platform_is_terminal (int fd)
 
int platform_get_cursor_position (int *row, int *col)
 
int platform_set_cursor_position (int row, int col)
 
asciichat_error_t get_terminal_size (unsigned short int *width, unsigned short int *height)
 
bool terminal_supports_utf8 (void)
 
bool terminal_is_piped_output (void)
 
bool terminal_should_color_output (int fd)
 
bool terminal_is_stdin_tty (void)
 
bool terminal_is_stdout_tty (void)
 
bool terminal_is_stderr_tty (void)
 
bool terminal_is_interactive (void)
 
bool terminal_should_force_stderr (void)
 
bool terminal_can_prompt_user (void)
 
bool terminal_has_dark_background (void)
 
asciichat_error_t terminal_flush (int fd)
 
terminal_capabilities_t detect_terminal_capabilities (void)
 
bool terminal_query_background_color (uint8_t *bg_r, uint8_t *bg_g, uint8_t *bg_b)
 

Detailed Description

Terminal abstraction for WASM/Emscripten via EM_JS bridge to xterm.js.

Definition in file platform/wasm/terminal.c.

Function Documentation

◆ detect_terminal_capabilities()

terminal_capabilities_t detect_terminal_capabilities ( void  )

Definition at line 146 of file platform/wasm/terminal.c.

146 {
147 terminal_capabilities_t caps = {0};
148 caps.color_level = TERM_COLOR_256; // xterm.js supports 256 colors
149 caps.capabilities = 0;
150 caps.color_count = 256;
151 caps.utf8_support = true; // xterm.js supports UTF-8
152 caps.detection_reliable = true;
153 caps.render_mode = RENDER_MODE_FOREGROUND; // Default to foreground mode
154 platform_strlcpy(caps.term_type, "xterm-256color", sizeof(caps.term_type));
155 platform_strlcpy(caps.colorterm, "truecolor", sizeof(caps.colorterm));
156 caps.wants_background = true;
157 caps.palette_type = 0; // Default palette
158 caps.desired_fps = 30;
159 caps.color_filter = COLOR_FILTER_NONE;
160 return caps;
161}
size_t platform_strlcpy(char *dst, const char *src, size_t size)

References platform_strlcpy().

Referenced by action_show_capabilities_immediate(), log_redetect_terminal_capabilities(), main(), session_display_create(), and threaded_send_terminal_size_with_auto_detect().

◆ EM_JS() [1/3]

EM_JS ( int  ,
js_get_terminal_cols  ,
()  ,
{ return Module.xterm ? Module.xterm.cols :80;}   
)

◆ EM_JS() [2/3]

EM_JS ( int  ,
js_get_terminal_rows  ,
()  ,
{ return Module.xterm ? Module.xterm.rows :24;}   
)

◆ EM_JS() [3/3]

EM_JS ( void  ,
js_terminal_write  ,
(const char *data, int len)  ,
{ if(Module.xterm) { Module.xterm.write(UTF8ToString(data, len));} }   
)

◆ get_terminal_size()

asciichat_error_t get_terminal_size ( unsigned short int *  width,
unsigned short int *  height 
)

Definition at line 80 of file platform/wasm/terminal.c.

80 {
81 if (!width || !height) {
82 return ERROR_INVALID_PARAM;
83 }
84 int cols, rows;
85 if (platform_get_terminal_size(&cols, &rows) != 0) {
86 return ERROR_PLATFORM_INIT;
87 }
88 *width = (unsigned short int)cols;
89 *height = (unsigned short int)rows;
90 return ASCIICHAT_OK;
91}
int platform_get_terminal_size(int *cols, int *rows)

References platform_get_terminal_size().

Referenced by session_display_create(), update_dimensions_for_full_height(), and update_dimensions_to_terminal_size().

◆ platform_get_cursor_position()

int platform_get_cursor_position ( int *  row,
int *  col 
)

Definition at line 67 of file platform/wasm/terminal.c.

67 {
68 (void)row;
69 (void)col;
70 return -1; // Not supported in WASM
71}

◆ platform_get_terminal_size()

int platform_get_terminal_size ( int *  cols,
int *  rows 
)

Definition at line 33 of file platform/wasm/terminal.c.

33 {
34 if (!cols || !rows) {
35 return -1;
36 }
37 *cols = js_get_terminal_cols();
38 *rows = js_get_terminal_rows();
39 return 0;
40}

Referenced by get_terminal_size().

◆ platform_is_terminal()

bool platform_is_terminal ( int  fd)

Definition at line 62 of file platform/wasm/terminal.c.

62 {
63 (void)fd;
64 return true; // Always true for WASM terminal
65}

◆ platform_read_keyboard()

int platform_read_keyboard ( char *  buffer,
size_t  len 
)

Definition at line 56 of file platform/wasm/terminal.c.

56 {
57 (void)buffer;
58 (void)len;
59 return -1; // Not supported: use JavaScript event listeners
60}

◆ platform_set_cursor_position()

int platform_set_cursor_position ( int  row,
int  col 
)

Definition at line 73 of file platform/wasm/terminal.c.

73 {
74 (void)row;
75 (void)col;
76 return -1; // Not supported in WASM
77}

◆ platform_set_terminal_raw_mode()

int platform_set_terminal_raw_mode ( bool  enable)

Definition at line 51 of file platform/wasm/terminal.c.

51 {
52 (void)enable;
53 return 0; // No-op: xterm.js handles this
54}

◆ platform_write_terminal()

int platform_write_terminal ( const char *  data,
size_t  len 
)

Definition at line 45 of file platform/wasm/terminal.c.

45 {
46 js_terminal_write(data, (int)len);
47 return (int)len;
48}

◆ terminal_can_prompt_user()

bool terminal_can_prompt_user ( void  )

Definition at line 130 of file platform/wasm/terminal.c.

130 {
131 return false; // Cannot prompt in WASM
132}

◆ terminal_flush()

asciichat_error_t terminal_flush ( int  fd)

Definition at line 140 of file platform/wasm/terminal.c.

140 {
141 (void)fd;
142 return ASCIICHAT_OK; // No-op - xterm.js handles flushing
143}

Referenced by ascii_write(), config_create_default(), session_display_render_frame(), session_display_render_help(), session_display_reset(), and session_display_write_raw().

◆ terminal_has_dark_background()

bool terminal_has_dark_background ( void  )

Definition at line 135 of file platform/wasm/terminal.c.

135 {
136 return true; // Default to dark background for xterm.js
137}

Referenced by detect_terminal_background().

◆ terminal_is_interactive()

bool terminal_is_interactive ( void  )

Definition at line 122 of file platform/wasm/terminal.c.

122 {
123 return false; // WASM mirror mode is not interactive
124}

◆ terminal_is_piped_output()

bool terminal_is_piped_output ( void  )

Definition at line 99 of file platform/wasm/terminal.c.

99 {
100 return false; // WASM mirror mode is not piped
101}

◆ terminal_is_stderr_tty()

bool terminal_is_stderr_tty ( void  )

Definition at line 118 of file platform/wasm/terminal.c.

118 {
119 return true; // xterm.js output is a TTY
120}

◆ terminal_is_stdin_tty()

bool terminal_is_stdin_tty ( void  )

Definition at line 110 of file platform/wasm/terminal.c.

110 {
111 return false; // No stdin in WASM
112}

◆ terminal_is_stdout_tty()

bool terminal_is_stdout_tty ( void  )

Definition at line 114 of file platform/wasm/terminal.c.

114 {
115 return true; // xterm.js output is a TTY
116}

◆ terminal_query_background_color()

bool terminal_query_background_color ( uint8_t *  bg_r,
uint8_t *  bg_g,
uint8_t *  bg_b 
)

Definition at line 164 of file platform/wasm/terminal.c.

164 {
165 // Return dark background (black) for xterm.js
166 if (bg_r)
167 *bg_r = 0;
168 if (bg_g)
169 *bg_g = 0;
170 if (bg_b)
171 *bg_b = 0;
172 return true;
173}

◆ terminal_should_color_output()

bool terminal_should_color_output ( int  fd)

Definition at line 104 of file platform/wasm/terminal.c.

104 {
105 (void)fd;
106 return true; // WASM mirror mode supports color
107}

◆ terminal_should_force_stderr()

bool terminal_should_force_stderr ( void  )

Definition at line 126 of file platform/wasm/terminal.c.

126 {
127 return false; // Don't force stderr in WASM
128}

◆ terminal_supports_utf8()

bool terminal_supports_utf8 ( void  )

Definition at line 94 of file platform/wasm/terminal.c.

94 {
95 return true; // xterm.js supports UTF-8
96}

Referenced by detect_client_utf8_support(), and options_init().