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

@ -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);
}