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

Terminal function stubs for WASM (functions not needed for mirror mode) More...

Go to the source code of this file.

Functions

asciichat_error_t terminal_get_size (terminal_size_t *size)
 Get terminal size.
 
asciichat_error_t terminal_cursor_hide (void)
 Hide terminal cursor.
 
asciichat_error_t terminal_cursor_show (void)
 Show terminal cursor.
 
unsigned short int terminal_get_effective_width (void)
 Get effective terminal width with fallback priority.
 
unsigned short int terminal_get_effective_height (void)
 Get effective terminal height with fallback priority.
 
asciichat_error_t terminal_fd_reader_create (int fd, int frame_height, terminal_fd_reader_t **out)
 Create a terminal FD reader from a file descriptor.
 
void terminal_fd_reader_destroy (terminal_fd_reader_t *reader)
 Destroy terminal FD reader.
 
asciichat_error_t terminal_fd_reader_next (terminal_fd_reader_t *reader, char **out_frame)
 Read next frame from file descriptor.
 

Detailed Description

Terminal function stubs for WASM (functions not needed for mirror mode)

Terminal control and cursor movement functions are implemented in wasm/terminal.c via ANSI escape sequences. This file contains only the stubs that return errors or no-ops for operations not supported in the browser environment.

Definition in file platform/wasm/stubs/terminal.c.

Function Documentation

◆ terminal_fd_reader_create()

asciichat_error_t terminal_fd_reader_create ( int  fd,
int  frame_height,
terminal_fd_reader_t **  out 
)

Create a terminal FD reader from a file descriptor.

Parameters
fdFile descriptor to read from (e.g., STDIN_FILENO, open file)
frame_heightNumber of lines per frame (required - used for frame boundaries)
outPointer to store reader context
Returns
ASCIICHAT_OK on success

Width is auto-detected from the first frame's line length.

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

51 {
52 (void)fd;
53 (void)frame_height;
54 if (out)
55 *out = NULL;
56 return ASCIICHAT_OK; // Stub - no stdin available in WASM
57}
@ ASCIICHAT_OK
Definition error_codes.h:51

References ASCIICHAT_OK.

Referenced by session_client_like_run().

◆ terminal_fd_reader_destroy()

void terminal_fd_reader_destroy ( terminal_fd_reader_t *  reader)

Destroy terminal FD reader.

Parameters
readerReader context to destroy

Definition at line 59 of file platform/wasm/stubs/terminal.c.

59 {
60 (void)reader;
61 // No-op
62}

Referenced by session_client_like_run().

◆ terminal_fd_reader_next()

asciichat_error_t terminal_fd_reader_next ( terminal_fd_reader_t *  reader,
char **  out_frame 
)

Read next frame from file descriptor.

Reads frame_height lines from the FD and returns them as a single frame string. Returns NULL in out_frame when EOF is reached.

Parameters
readerReader context
out_framePointer to store frame data (NULL when EOF, must free with SAFE_FREE)
Returns
ASCIICHAT_OK on success (including EOF)

Definition at line 64 of file platform/wasm/stubs/terminal.c.

64 {
65 (void)reader;
66 if (out_frame)
67 *out_frame = NULL; // Signal EOF immediately
68 return ASCIICHAT_OK;
69}

References ASCIICHAT_OK.

◆ terminal_get_effective_height()

unsigned short int terminal_get_effective_height ( void  )

Get effective terminal height with fallback priority.

Returns
Terminal height in characters with priority: option → detected → default

Returns the effective terminal height to use, checking in priority order:

  1. Option value: If --height was set to a non-zero value, return it
  2. Detected size: Try to detect actual terminal height via terminal_get_size()
  3. Default: Return OPT_HEIGHT_DEFAULT (70) as final fallback

This function simplifies the common pattern of "use option if set, else detect, else use default" that appears throughout the codebase for terminal dimension handling.

Note
Safe to call from any thread (uses lock-free option access)
Detection may fail on non-TTY output (piped/redirected), falls back gracefully
Height option defaults to 0, so non-zero means it was explicitly set

Usage Example:

// Old pattern (scattered throughout code):
unsigned short int height = GET_OPTION(height);
if (height == 0) {
height = size.rows;
} else {
}
}
// New pattern (unified):
unsigned short int height = terminal_get_effective_height();
#define GET_OPTION(field)
Safely get a specific option field (lock-free read)
#define OPT_HEIGHT_DEFAULT
Default terminal height in characters.
asciichat_error_t terminal_get_size(terminal_size_t *size)
Get terminal size.
unsigned short int terminal_get_effective_height(void)
Get effective terminal height with fallback priority.
Terminal size structure.
Definition terminal.h:163
int rows
Number of rows (height) in terminal.
Definition terminal.h:164

Returns height in priority order:

  1. Option height if set to non-zero value
  2. Detected terminal height
  3. OPT_HEIGHT_DEFAULT fallback

Definition at line 39 of file platform/wasm/stubs/terminal.c.

39 {
40 int height = GET_OPTION(height);
41 if (height > 0) {
42 return (unsigned short int)height;
43 }
44 // For WASM, use default since terminal detection is stubbed
45 return OPT_HEIGHT_DEFAULT;
46}

References GET_OPTION, and OPT_HEIGHT_DEFAULT.

◆ terminal_get_effective_width()

unsigned short int terminal_get_effective_width ( void  )

Get effective terminal width with fallback priority.

Returns
Terminal width in characters with priority: option → detected → default

Returns the effective terminal width to use, checking in priority order:

  1. Option value: If --width was set to a non-zero value, return it
  2. Detected size: Try to detect actual terminal width via terminal_get_size()
  3. Default: Return OPT_WIDTH_DEFAULT (110) as final fallback

This function simplifies the common pattern of "use option if set, else detect, else use default" that appears throughout the codebase for terminal dimension handling.

Note
Safe to call from any thread (uses lock-free option access)
Detection may fail on non-TTY output (piped/redirected), falls back gracefully
Width option defaults to 0, so non-zero means it was explicitly set

Usage Example:

// Old pattern (scattered throughout code):
unsigned short int width = GET_OPTION(width);
if (width == 0) {
width = size.cols;
} else {
}
}
// New pattern (unified):
unsigned short int width = terminal_get_effective_width();
#define OPT_WIDTH_DEFAULT
Default terminal width in characters.
unsigned short int terminal_get_effective_width(void)
Get effective terminal width with fallback priority.
int cols
Number of columns (width) in terminal.
Definition terminal.h:165

Returns width in priority order:

  1. Option width if set to non-zero value
  2. Detected terminal width
  3. OPT_WIDTH_DEFAULT fallback

Definition at line 29 of file platform/wasm/stubs/terminal.c.

29 {
30 int width = GET_OPTION(width);
31 if (width > 0) {
32 return (unsigned short int)width;
33 }
34 // For WASM, use default since terminal detection is stubbed
35 return OPT_WIDTH_DEFAULT;
36}

References GET_OPTION, and OPT_WIDTH_DEFAULT.