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

Read ANSI ASCII frames from file descriptor, chunked by height. More...

Go to the source code of this file.

Typedefs

typedef struct terminal_fd_reader_s terminal_fd_reader_t
 

Functions

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.
 
asciichat_error_t terminal_fd_reader_next (terminal_fd_reader_t *reader, char **out_frame)
 Read next frame from file descriptor.
 
void terminal_fd_reader_destroy (terminal_fd_reader_t *reader)
 Destroy terminal FD reader.
 

Detailed Description

Read ANSI ASCII frames from file descriptor, chunked by height.

Reads ASCII frames from any file descriptor (stdin, file, pipe) and chunks them by height (number of lines) as specified. Supports reading ANSI-colored ASCII art frames in batches.

Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
February 2026

Definition in file reader.h.

Typedef Documentation

◆ terminal_fd_reader_t

Definition at line 20 of file reader.h.

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, terminal_fd_reader_s::eof_reached, ERROR_INVALID_PARAM, terminal_fd_reader_s::first_frame_processed, terminal_fd_reader_s::fp, terminal_fd_reader_s::frame_height, terminal_fd_reader_s::frame_width, terminal_fd_reader_s::line_buffer, terminal_fd_reader_s::line_buffer_size, LINE_BUFFER_SIZE, log_debug, platform_fdopen(), SAFE_CALLOC, SAFE_MALLOC, SET_ERRNO, and SET_ERRNO_SYS.

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}

References terminal_fd_reader_s::fp, terminal_fd_reader_s::line_buffer, and SAFE_FREE.

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, display_width(), terminal_fd_reader_s::eof_reached, ERROR_INVALID_PARAM, terminal_fd_reader_s::first_frame_processed, terminal_fd_reader_s::fp, terminal_fd_reader_s::frame_height, terminal_fd_reader_s::frame_width, terminal_fd_reader_s::line_buffer, terminal_fd_reader_s::line_buffer_size, LINE_BUFFER_SIZE, log_debug, log_debug_every, log_info, log_warn, NS_PER_SEC_INT, SAFE_FREE, SAFE_MALLOC, and SET_ERRNO.