respect lscolors env var; measure width minus ansi

This commit is contained in:
Darren Schroeder
2021-10-08 09:40:20 -05:00
parent 1a3a837f3e
commit 5ddf0d209d
5 changed files with 78 additions and 7 deletions

View File

@ -17,5 +17,6 @@ nu-term-grid = { path = "../nu-term-grid" }
glob = "0.3.0"
thiserror = "1.0.29"
sysinfo = "0.20.4"
chrono = { version="0.4.19", features=["serde"] }
chrono = { version = "0.4.19", features = ["serde"] }
terminal_size = "0.1.17"
lscolors = { version = "0.8.0", features = ["crossterm"] }

View File

@ -1,3 +1,4 @@
use lscolors::{LsColors, Style};
use nu_engine::CallExt;
use nu_protocol::{
ast::{Call, PathMember},
@ -88,6 +89,7 @@ fn create_grid_output2(
call: &Call,
columns_param: Option<String>,
) -> Value {
let ls_colors = LsColors::from_env().unwrap_or_default();
let mut grid = Grid::new(GridOptions {
direction: Direction::TopToBottom,
filling: Filling::Text(" | ".into()),
@ -96,7 +98,9 @@ fn create_grid_output2(
for (_row_index, header, value) in items {
// only output value if the header name is 'name'
if header == "name" {
let mut cell = Cell::from(value);
let style = ls_colors.style_for_path(value.clone());
let ansi_style = style.map(Style::to_crossterm_style).unwrap_or_default();
let mut cell = Cell::from(ansi_style.apply(value).to_string());
cell.alignment = Alignment::Right;
grid.add(cell);
}