Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ use term_grid::{Cell, Direction, Filling, Grid, GridOptions};
use terminal_size::terminal_size;
use unicode_width::UnicodeWidthStr;

#[cfg(not(target_os = "windows"))]
use std::io;
#[cfg(not(target_os = "windows"))]
use std::os::unix::io::AsRawFd;

const EDGE: &str = "\u{251c}\u{2500}\u{2500}"; // "├──"
const LINE: &str = "\u{2502} "; // "│ "
const CORNER: &str = "\u{2514}\u{2500}\u{2500}"; // "└──"
Expand Down Expand Up @@ -177,13 +182,22 @@ fn add_header(flags: &Flags, cells: &[Cell], grid: &mut Grid) {
widths[index] = std::cmp::max(widths[index], cell.width);
}

#[cfg(not(target_os = "windows"))]
let tty_available = unsafe { libc::isatty(io::stdout().as_raw_fd()) == 1 };

#[cfg(target_os = "windows")]
let tty_available = terminal_size().is_some();

for (idx, block) in flags.blocks.0.iter().enumerate() {
// center and underline header
let underlined_header = crossterm::style::Stylize::attribute(
format!("{: ^1$}", block.get_header(), widths[idx]),
crossterm::style::Attribute::Underlined,
)
.to_string();
let underlined_header = if tty_available {
crossterm::style::Stylize::attribute(
format!("{: ^1$}", block.get_header(), widths[idx]),
crossterm::style::Attribute::Underlined,
)
.to_string()
} else {
format!("{: ^1$}", block.get_header(), widths[idx])
};

grid.add(Cell {
width: widths[idx],
Expand Down