vtcode_core/ui/
terminal.rs

1//! Terminal utilities and helpers
2
3use is_terminal::IsTerminal;
4use std::io::Write;
5
6/// Get the terminal width, fallback to 80 if unable to determine
7pub fn get_terminal_width() -> usize {
8    terminal_size::terminal_size()
9        .map(|(terminal_size::Width(w), _)| w as usize)
10        .unwrap_or(80)
11}
12
13/// Flush stdout to ensure output is displayed immediately
14pub fn flush_stdout() {
15    std::io::stdout().flush().ok();
16}
17
18/// Read a line from stdin with proper error handling
19pub fn read_line() -> std::io::Result<String> {
20    let mut buffer = String::new();
21    std::io::stdin().read_line(&mut buffer)?;
22    Ok(buffer.trim().to_string())
23}
24
25/// Check if output is being piped (not a terminal)
26pub fn is_piped_output() -> bool {
27    !std::io::stdout().is_terminal()
28}
29
30/// Check if input is being piped (not a terminal)
31pub fn is_piped_input() -> bool {
32    !std::io::stdin().is_terminal()
33}