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

Cross-platform unified color detection and terminal capabilities. More...

Go to the source code of this file.

Functions

bool terminal_should_color_output (int fd)
 Determine if color output should be used.
 
terminal_color_mode_t terminal_get_effective_color_mode (void)
 Get current color mode considering all overrides.
 
bool terminal_is_stdin_tty (void)
 Check if stdin is connected to a TTY.
 
bool terminal_is_stdout_tty (void)
 Check if stdout is connected to a TTY.
 
bool terminal_is_stderr_tty (void)
 Check if stderr is connected to a TTY.
 
bool terminal_is_interactive (void)
 Check if the session is fully interactive.
 
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.
 
bool terminal_is_piped_output (void)
 Check if stdout is piped or redirected.
 
bool terminal_should_force_stderr (void)
 Determine if logs should be forced to stderr.
 
bool terminal_can_prompt_user (void)
 Determine if interactive user prompts are appropriate.
 
int terminal_choose_log_fd (log_level_t level)
 Choose output file descriptor for logging based on level and interactivity.
 
void terminal_get_default_foreground_color (int theme, uint8_t *out_r, uint8_t *out_g, uint8_t *out_b)
 Get theme-aware default foreground color for the renderer.
 
void terminal_get_default_background_color (int theme, uint8_t *out_r, uint8_t *out_g, uint8_t *out_b)
 Get theme-aware default background color for the renderer.
 
bool terminal_should_use_control_sequences (int fd)
 Check if terminal control sequences should be used for the given fd.
 

Detailed Description

Cross-platform unified color detection and terminal capabilities.

Definition in file platform/terminal.c.

Function Documentation

◆ terminal_can_prompt_user()

bool terminal_can_prompt_user ( void  )

Determine if interactive user prompts are appropriate.

Returns
true if prompts can be shown, false if non-interactive/automated

Determines whether interactive user prompts (yes/no, passwords, confirmations) should be displayed. Returns false in non-interactive or automated contexts.

Use this to decide whether:

  • Password prompts should be shown (or auto-cancel)
  • Yes/No confirmations should wait for input (or use defaults)
  • Known hosts prompts should be interactive (or auto-deny)

Logic:

  1. If not fully interactive (stdin or stdout not TTY) → false
  2. If in snapshot mode (–snapshot) → false
  3. If ASCII_CHAT_QUESTION_PROMPT_RESPONSE set → false (automated responses)
  4. Otherwise → true (interactive prompts OK)

Examples:

  • ascii-chat client in terminal → true (can prompt)
  • ascii-chat client --snapshot → false (non-interactive mode)
  • echo data | ascii-chat client → false (stdin piped)
  • ‘ASCII_CHAT_QUESTION_PROMPT_RESPONSE='y’ ascii-chat client→ false (automated) -ascii-chat client > output.txt` → false (stdout redirected)
Note
Combines checks for: TTY status, snapshot mode, automation env vars
Used by password prompts, known_hosts verification, user confirmations
When false, password prompts should auto-cancel with error
When false, yes/no prompts should use default value or deny

Definition at line 215 of file platform/terminal.c.

215 {
216 // Must be fully interactive (stdin and stdout are TTYs)
218 return false;
219 }
220
221 // Must not be in snapshot mode (non-interactive capture)
222 if (GET_OPTION(snapshot_mode)) {
223 return false;
224 }
225
226 // Must not have automated prompt responses configured
227 const char *auto_response = SAFE_GETENV("ASCII_CHAT_QUESTION_PROMPT_RESPONSE");
228 if (auto_response && *auto_response != '\0') {
229 // NOLINTNEXTLINE(readability-simplify-boolean-expr) - Intentional check for configured automated responses
230 return false;
231 }
232
233 // All checks passed, interactive prompts are appropriate
234 return true;
235}
#define SAFE_GETENV(name)
Definition common.h:434
#define GET_OPTION(field)
Safely get a specific option field (lock-free read)
bool terminal_is_interactive(void)
Check if the session is fully interactive.

References GET_OPTION, SAFE_GETENV, and terminal_is_interactive().

Referenced by prompt_unknown_host().

◆ terminal_choose_log_fd()

int terminal_choose_log_fd ( log_level_t  level)

Choose output file descriptor for logging based on level and interactivity.

Parameters
levelLog level (determines default routing: WARN+ to stderr, others to stdout)
Returns
STDERR_FILENO or STDOUT_FILENO based on log level and terminal state

Routes logs appropriately:

  • When terminal is NOT interactive (piped): ALL logs to stderr
  • When force_stderr enabled: ALL logs to stderr
  • Otherwise: WARN/ERROR/FATAL to stderr, others to stdout

This consolidates log routing logic used throughout the codebase.

Note
Use: int fd = terminal_choose_log_fd(LOG_INFO);
Common usage: platform_write_all(terminal_choose_log_fd(level), data, len);

Definition at line 237 of file platform/terminal.c.

237 {
238 // When force_stderr is enabled (client mode), send ALL logs to stderr
239 // When terminal is NOT interactive (piped/redirected), send ALL logs to stderr
240 // to keep stdout clean for piped data (JSON, frames, etc.)
242 return STDERR_FILENO;
243 }
244
245 // In interactive mode, route based on level:
246 // WARN and above (ERROR, FATAL) go to stderr
247 // Others (DEV, DEBUG, INFO) go to stdout
248 if (level >= LOG_WARN) {
249 return STDERR_FILENO;
250 }
251
252 return STDOUT_FILENO;
253}
bool log_get_force_stderr(void)
Get current force_stderr setting.
Definition log/log.c:725
#define LOG_WARN
Definition types.h:41

References log_get_force_stderr(), LOG_WARN, and terminal_is_interactive().

Referenced by log_console_impl(), log_msg(), and log_plain_msg().

◆ terminal_get_default_background_color()

void terminal_get_default_background_color ( int  theme,
uint8_t *  out_r,
uint8_t *  out_g,
uint8_t *  out_b 
)

Get theme-aware default background color for the renderer.

Get theme-aware default background color for pixel renderers.

Parameters
themeTerminal theme (dark or light)
out_rPointer to store red component (0-255)
out_gPointer to store green component (0-255)
out_bPointer to store blue component (0-255)

Returns appropriate default background color based on terminal theme. Light theme uses white background, dark theme uses black background.

Definition at line 291 of file platform/terminal.c.

291 {
292 if (theme == 1) { // TERM_RENDERER_THEME_LIGHT
296 } else { // TERM_RENDERER_THEME_DARK or TERM_RENDERER_THEME_AUTO
300 }
301}
#define TERMINAL_COLOR_THEME_LIGHT_BG_R
Default background color for light theme (RGB)
Definition terminal.h:135
#define TERMINAL_COLOR_THEME_DARK_BG_G
Definition terminal.h:145
#define TERMINAL_COLOR_THEME_LIGHT_BG_B
Definition terminal.h:137
#define TERMINAL_COLOR_THEME_DARK_BG_B
Definition terminal.h:146
#define TERMINAL_COLOR_THEME_DARK_BG_R
Default background color for dark theme (RGB)
Definition terminal.h:144
#define TERMINAL_COLOR_THEME_LIGHT_BG_G
Definition terminal.h:136

References TERMINAL_COLOR_THEME_DARK_BG_B, TERMINAL_COLOR_THEME_DARK_BG_G, TERMINAL_COLOR_THEME_DARK_BG_R, TERMINAL_COLOR_THEME_LIGHT_BG_B, TERMINAL_COLOR_THEME_LIGHT_BG_G, and TERMINAL_COLOR_THEME_LIGHT_BG_R.

Referenced by term_renderer_feed().

◆ terminal_get_default_foreground_color()

void terminal_get_default_foreground_color ( int  theme,
uint8_t *  out_r,
uint8_t *  out_g,
uint8_t *  out_b 
)

Get theme-aware default foreground color for the renderer.

Get theme-aware default foreground color for pixel renderers.

Parameters
themeTerminal theme (dark or light)
out_rPointer to store red component (0-255)
out_gPointer to store green component (0-255)
out_bPointer to store blue component (0-255)

Returns appropriate default text color based on terminal theme. Both Linux and macOS renderers use this for consistent color selection.

Definition at line 269 of file platform/terminal.c.

269 {
270 if (theme == 1) { // TERM_RENDERER_THEME_LIGHT
274 } else { // TERM_RENDERER_THEME_DARK or TERM_RENDERER_THEME_AUTO
278 }
279}
#define TERMINAL_COLOR_THEME_DARK_FG_B
Definition terminal.h:128
#define TERMINAL_COLOR_THEME_LIGHT_FG_G
Definition terminal.h:117
#define TERMINAL_COLOR_THEME_DARK_FG_R
Default text color for dark theme (RGB)
Definition terminal.h:126
#define TERMINAL_COLOR_THEME_DARK_FG_G
Definition terminal.h:127
#define TERMINAL_COLOR_THEME_LIGHT_FG_B
Definition terminal.h:118
#define TERMINAL_COLOR_THEME_LIGHT_FG_R
Platform-specific getopt include.
Definition terminal.h:116

References TERMINAL_COLOR_THEME_DARK_FG_B, TERMINAL_COLOR_THEME_DARK_FG_G, TERMINAL_COLOR_THEME_DARK_FG_R, TERMINAL_COLOR_THEME_LIGHT_FG_B, TERMINAL_COLOR_THEME_LIGHT_FG_G, and TERMINAL_COLOR_THEME_LIGHT_FG_R.

Referenced by term_renderer_feed().

◆ terminal_get_effective_color_mode()

terminal_color_mode_t terminal_get_effective_color_mode ( void  )

Get current color mode considering all overrides.

Determines effective color mode by checking:

  1. –color flag (force enable)
  2. –color-mode option (none/16/256/truecolor)
  3. Terminal capability detection
Returns
Effective terminal_color_mode_t to use

Definition at line 107 of file platform/terminal.c.

107 {
108 // If colors are disabled entirely by terminal_should_color_output(), return NONE
109 if (!terminal_should_color_output(STDOUT_FILENO)) {
110 return TERM_COLOR_NONE;
111 }
112
113 // If --color-mode is set to specific value, use it
114 terminal_color_mode_t color_mode = GET_OPTION(color_mode);
115 if (color_mode != TERM_COLOR_AUTO) {
116 return color_mode;
117 }
118
119 // Otherwise auto-detect from terminal capabilities
120 // For now, return the detected color mode from terminal capabilities
121 // This will be used by apply_color_mode_override() if needed
122 return TERM_COLOR_AUTO; // Let the calling code handle auto-detection
123}
bool terminal_should_color_output(int fd)
Determine if color output should be used.
terminal_color_mode_t
Terminal color support levels.
Definition terminal.h:578
@ TERM_COLOR_NONE
No color support (monochrome terminal)
Definition terminal.h:582
@ TERM_COLOR_AUTO
Auto-detect color support from terminal capabilities.
Definition terminal.h:580

References GET_OPTION, TERM_COLOR_AUTO, TERM_COLOR_NONE, and terminal_should_color_output().

◆ terminal_get_effective_height()

unsigned short int terminal_get_effective_height ( void  )

Get effective terminal height with fallback priority.

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 179 of file platform/terminal.c.

179 {
180 int height = GET_OPTION(height);
181
182 // If height option is explicitly set to non-zero, use it
183 if (height > 0) {
184 return (unsigned short int)height;
185 }
186
187 // Try to detect actual terminal height
188 terminal_size_t size;
189 if (terminal_get_size(&size) == ASCIICHAT_OK && size.rows > 0) {
190 return (unsigned short int)size.rows;
191 }
192
193 // Fallback to default
194 return OPT_HEIGHT_DEFAULT;
195}
@ ASCIICHAT_OK
Definition error_codes.h:51
#define OPT_HEIGHT_DEFAULT
Default terminal height in characters.
asciichat_error_t terminal_get_size(terminal_size_t *size)
Get terminal size.
Terminal size structure.
Definition terminal.h:163
int rows
Number of rows (height) in terminal.
Definition terminal.h:164

References ASCIICHAT_OK, GET_OPTION, OPT_HEIGHT_DEFAULT, terminal_size_t::rows, and terminal_get_size().

Referenced by keyboard_help_render(), mirror_convert_frame(), protocol_start_connection(), server_connection_establish(), session_display_convert_to_ascii(), session_display_create(), session_render_loop(), session_settings_init(), splash_intro_start(), and update_banner_show_prompt().

◆ terminal_get_effective_width()

unsigned short int terminal_get_effective_width ( void  )

Get effective terminal width with fallback priority.

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 153 of file platform/terminal.c.

153 {
154 int width = GET_OPTION(width);
155
156 // If width option is explicitly set to non-zero, use it
157 if (width > 0) {
158 return (unsigned short int)width;
159 }
160
161 // Try to detect actual terminal width
162 terminal_size_t size;
163 if (terminal_get_size(&size) == ASCIICHAT_OK && size.cols > 0) {
164 return (unsigned short int)size.cols;
165 }
166
167 // Fallback to default
168 return OPT_WIDTH_DEFAULT;
169}
#define OPT_WIDTH_DEFAULT
Default terminal width in characters.
int cols
Number of columns (width) in terminal.
Definition terminal.h:165

References ASCIICHAT_OK, terminal_size_t::cols, GET_OPTION, OPT_WIDTH_DEFAULT, and terminal_get_size().

Referenced by keyboard_help_render(), mirror_convert_frame(), protocol_start_connection(), server_connection_establish(), session_display_convert_to_ascii(), session_display_create(), session_display_render_fps_overlay(), session_render_loop(), session_settings_init(), splash_intro_start(), and update_banner_show_prompt().

◆ terminal_is_interactive()

bool terminal_is_interactive ( void  )

Check if the session is fully interactive.

Returns
true if BOTH stdin AND stdout are TTYs, false otherwise

Determines whether the session is fully interactive (user at terminal). Returns true only when BOTH stdin and stdout are connected to TTYs.

Use this to decide whether:

  • User prompts and interactive input should be shown
  • Splash screens and animations should be displayed
  • Frame padding should be enabled
  • Password prompts are appropriate

Examples:

  • ascii-chat mirror in terminal → true (interactive)
  • ascii-chat mirror | less → false (stdout piped)
  • cat file | ascii-chat client → false (stdin piped)
  • ascii-chat client < input.txt > output.txt → false (both piped)
Note
Equivalent to: terminal_is_stdin_tty() && terminal_is_stdout_tty()
Used for enabling interactive features (prompts, padding, splash)
Snapshot mode is checked separately via GET_OPTION(snapshot_mode)

Definition at line 141 of file platform/terminal.c.

141 {
143}
bool terminal_is_stdin_tty(void)
Check if stdin is connected to a TTY.
bool terminal_is_stdout_tty(void)
Check if stdout is connected to a TTY.

References terminal_is_stdin_tty(), and terminal_is_stdout_tty().

Referenced by main(), options_init(), session_display_write_ascii(), session_render_loop(), session_server_like_run(), terminal_can_prompt_user(), terminal_choose_log_fd(), threaded_send_terminal_size_with_auto_detect(), ui_status_display(), and ui_status_display_interactive().

◆ terminal_is_piped_output()

bool terminal_is_piped_output ( void  )

Check if stdout is piped or redirected.

Returns
true if stdout is piped/redirected, false if connected to TTY

Determines whether standard output is being piped or redirected to a file. This is the logical inverse of terminal_is_stdout_tty().

Use this to decide whether:

  • Logs should be forced to stderr (to avoid corrupting piped output)
  • Frame padding should be disabled
  • Clean, parseable output should be preferred

Examples:

  • ascii-chat mirror > output.txt → true (redirected)
  • ascii-chat client | grep pattern → true (piped)
  • ascii-chat mirror in terminal → false (TTY)
Note
Equivalent to: !terminal_is_stdout_tty()
Common pattern: force stderr when piped to prevent data corruption

Definition at line 197 of file platform/terminal.c.

197 {
198 return !terminal_is_stdout_tty();
199}

References terminal_is_stdout_tty().

Referenced by asciichat_shared_init(), log_init(), and terminal_should_force_stderr().

◆ terminal_is_stderr_tty()

bool terminal_is_stderr_tty ( void  )

Check if stderr is connected to a TTY.

Returns
true if stderr is a TTY, false otherwise

Determines whether standard error is connected to a terminal device. Returns false when stderr is piped or redirected to a file.

Use this to decide whether diagnostic messages should include colors.

Note
Wrapper around platform_isatty(STDERR_FILENO) for clarity
stderr is often a TTY even when stdout is piped

Definition at line 137 of file platform/terminal.c.

137 {
138 return platform_isatty(STDERR_FILENO) != 0;
139}
int platform_isatty(int fd)
Check if a file descriptor is a terminal.
Definition util.c:63

References platform_isatty().

◆ terminal_is_stdin_tty()

bool terminal_is_stdin_tty ( void  )

Check if stdin is connected to a TTY.

Returns
true if stdin is a TTY (can read interactive input), false otherwise

Determines whether standard input is connected to a terminal device. Returns false when stdin is piped or redirected from a file.

Use this to decide whether interactive input (prompts, keyboard events) is possible.

Note
Wrapper around platform_isatty(STDIN_FILENO) for clarity
Returns false in non-interactive environments (CI, scripts, pipes)

Definition at line 129 of file platform/terminal.c.

129 {
130 return platform_isatty(STDIN_FILENO) != 0;
131}

References platform_isatty().

Referenced by display_init(), session_client_like_run(), session_display_create(), session_render_loop(), terminal_is_interactive(), and threaded_send_terminal_size_with_auto_detect().

◆ terminal_is_stdout_tty()

bool terminal_is_stdout_tty ( void  )

Check if stdout is connected to a TTY.

Returns
true if stdout is a TTY (not piped/redirected), false otherwise

Determines whether standard output is connected to a terminal device. Returns false when stdout is piped or redirected to a file.

Use this to decide whether:

  • Terminal control sequences (colors, cursor movement) should be used
  • Output padding/formatting should be applied
  • Progress bars or animations should be shown
Note
Wrapper around platform_isatty(STDOUT_FILENO) for clarity
Returns false in piped contexts (e.g., ascii-chat client | less)

Definition at line 133 of file platform/terminal.c.

133 {
134 return platform_isatty(STDOUT_FILENO) != 0;
135}

References platform_isatty().

Referenced by session_client_like_run(), session_display_create(), session_render_loop(), terminal_is_interactive(), terminal_is_piped_output(), and threaded_send_terminal_size_with_auto_detect().

◆ terminal_should_color_output()

bool terminal_should_color_output ( int  fd)

Determine if color output should be used.

Priority order:

  1. If –color flag is set → ALWAYS use colors (force override)
  2. If CLAUDECODE env var is set → NEVER use colors (LLM automation)
  3. If output is not a TTY (piping) → NO colors
  4. If –color-mode=none → NO colors (user choice)
  5. Otherwise → Use colors
Parameters
fdFile descriptor to check (STDOUT_FILENO or STDERR_FILENO)
Returns
true if colors should be used, false otherwise

Definition at line 31 of file platform/terminal.c.

31 {
32 // Check color_mode setting - if explicitly set to NONE, disable colors
33 int color_mode = GET_OPTION(color_mode);
34 if (color_mode == COLOR_MODE_NONE) {
35 return false; // Color mode explicitly disabled
36 }
37
38 // Get current color setting (auto/true/false)
39 int color_setting = GET_OPTION(color);
40
41 // Priority 1: --color=true - Force colors ON (overrides everything)
42 if (color_setting == COLOR_SETTING_TRUE) {
43 return true; // ALWAYS colorize
44 }
45
46 // Priority 2: --color=false - Force colors OFF (overrides everything)
47 if (color_setting == COLOR_SETTING_FALSE) {
48 return false; // NEVER colorize
49 }
50
51 // Priority 3: --color=auto (default) - Smart detection
52 // Special case: Show colors for --help and --version even if not a TTY
53 // Check for help/version in global argv (set by main.c early)
54 if (g_argc > 1 && g_argv) {
55 for (int i = 1; i < g_argc; i++) {
56 if (strcmp(g_argv[i], "--help") == 0 || strcmp(g_argv[i], "-h") == 0 || strcmp(g_argv[i], "--version") == 0 ||
57 strcmp(g_argv[i], "-v") == 0 || strcmp(g_argv[i], "--show-capabilities") == 0) {
58 // For help/version/show-capabilities, use colors only if output is a TTY
59 // (respect piping convention: no colors unless --color=true)
60 int is_tty = platform_isatty(fd);
61 if (!is_tty) {
62 // Piping detected - fall through to check environment overrides
63 break;
64 }
65
66 // It's a TTY - show colors for help. Check environment overrides.
67 if (SAFE_GETENV("ASCII_CHAT_COLOR")) {
68 return true; // ASCII_CHAT_COLOR env var forces colors
69 }
70
71 // CLAUDECODE environment variable (LLM automation) - disable colors
72 if (SAFE_GETENV("CLAUDECODE")) {
73 return false; // NO colors in Claude Code environment
74 }
75
76 // For help output to TTY, show colors by default
77 return true;
78 }
79 }
80 }
81
82 // Check environment variable overrides
83 if (SAFE_GETENV("ASCII_CHAT_COLOR")) {
84 return true; // ASCII_CHAT_COLOR env var forces colors
85 }
86
87 // CLAUDECODE environment variable (LLM automation) - disable colors
88 if (SAFE_GETENV("CLAUDECODE")) {
89 return false; // NO colors in Claude Code environment
90 }
91
92 // Check if output is a TTY (pipe detection)
93 // Default: Use colors only if we have TTY and no environment overrides
94 return platform_isatty(fd);
95}
char ** g_argv
Global argv for early argument inspection (e.g., –color flag detection) Set by main() for access from...
Definition common.c:54
int g_argc
Global argc for early argument inspection (e.g., –color flag detection) Set by main() for access from...
Definition common.c:53
#define COLOR_MODE_NONE
Monochrome mode.
@ COLOR_SETTING_TRUE
Force colors ON: always colorize regardless of TTY/piping/CLAUDECODE.
@ COLOR_SETTING_FALSE
Force colors OFF: disable all colors and logging colors.

References COLOR_MODE_NONE, COLOR_SETTING_FALSE, COLOR_SETTING_TRUE, g_argc, g_argv, GET_OPTION, platform_isatty(), and SAFE_GETENV.

Referenced by action_show_capabilities_immediate(), action_show_version(), colored_string(), colorize_log_message(), log_plain_msg(), and terminal_get_effective_color_mode().

◆ terminal_should_force_stderr()

bool terminal_should_force_stderr ( void  )

Determine if logs should be forced to stderr.

Returns
true if logs should go to stderr only, false if stdout is acceptable

Determines whether logging output should be forced to stderr instead of stdout. Returns true when stdout is piped/redirected (to avoid corrupting output data).

Use this to decide whether to call log_set_force_stderr(true).

Logic:

  1. If stdout is piped/redirected → force stderr (true)
  2. If in TESTING environment → allow stdout (false)
  3. Otherwise → allow stdout (false)

Examples:

  • ascii-chat mirror > frames.txt → true (don't corrupt frame data)
  • ascii-chat mirror in terminal → false (stdout is fine)
  • TESTING=1 ascii-chat mirror → false (tests may capture stdout)
Note
This prevents logs from corrupting piped ASCII frame data
TESTING environment variable bypasses this for test environments
Typical usage: if (terminal_should_force_stderr()) log_set_force_stderr(true);

Definition at line 201 of file platform/terminal.c.

201 {
202 // If stdout is piped/redirected, force logs to stderr to avoid corruption
204 // Unless in TESTING environment where test framework may capture stdout
205 const char *testing = SAFE_GETENV("TESTING");
206 if (testing && strcmp(testing, "1") == 0) {
207 // NOLINTNEXTLINE(readability-simplify-boolean-expr) - Intentional logic for test environment override
208 return false;
209 }
210 return true; // Force stderr when piped
211 }
212 return false; // stdout is TTY, no need to force stderr
213}
bool terminal_is_piped_output(void)
Check if stdout is piped or redirected.

References SAFE_GETENV, and terminal_is_piped_output().

Referenced by main(), session_client_like_run(), and session_display_create().

◆ terminal_should_use_control_sequences()

bool terminal_should_use_control_sequences ( int  fd)

Check if terminal control sequences should be used for the given fd.

Parameters
fdFile descriptor to check
Returns
true if terminal control sequences should be used, false otherwise

This function determines whether to send terminal POSITIONING and CONTROL sequences (cursor home, clear screen, hide cursor, etc.) which should only be sent to TTY and never to pipes/redirected output.

Note: This does NOT control ANSI COLOR CODES, which are controlled by –color-mode option and may be sent to pipes if explicitly requested.

Definition at line 315 of file platform/terminal.c.

315 {
316 if (fd < 0) {
317 return false;
318 }
319 if (GET_OPTION(snapshot_mode)) {
320 return false;
321 }
322 const char *testing_env = SAFE_GETENV("TESTING");
323 if (testing_env != NULL) {
324 return false;
325 }
326 return platform_isatty(fd) != 0;
327}

References GET_OPTION, platform_isatty(), and SAFE_GETENV.

Referenced by ascii_write(), ascii_write_destroy(), and ascii_write_init().