mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 11:35:43 +02:00
Move to latest stable crossterm, with fix (#4684)
This commit is contained in:
@ -2,8 +2,8 @@ use std::borrow::Cow;
|
||||
|
||||
// use super::icons::{icon_for_file, iconify_style_ansi_to_nu};
|
||||
use super::icons::icon_for_file;
|
||||
use super::lscolor_ansiterm::ToNuAnsiStyle;
|
||||
use lscolors::LsColors;
|
||||
use lscolors::Style;
|
||||
use nu_engine::env_to_string;
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::{
|
||||
@ -241,25 +241,24 @@ fn create_grid_output(
|
||||
let icon = icon_for_file(path, call.head)?;
|
||||
let ls_colors_style = ls_colors.style_for_path(path);
|
||||
|
||||
let icon_style = match ls_colors_style {
|
||||
Some(c) => c.to_crossterm_style(),
|
||||
None => crossterm::style::ContentStyle::default(),
|
||||
};
|
||||
|
||||
let ansi_style = ls_colors_style
|
||||
.map(ToNuAnsiStyle::to_nu_ansi_style)
|
||||
.map(Style::to_crossterm_style)
|
||||
.unwrap_or_default();
|
||||
|
||||
let item = format!(
|
||||
"{} {}",
|
||||
ansi_style.paint(icon.to_string()),
|
||||
ansi_style.paint(value)
|
||||
);
|
||||
let item = format!("{} {}", icon_style.apply(icon), ansi_style.apply(value));
|
||||
|
||||
let mut cell = Cell::from(item);
|
||||
cell.alignment = Alignment::Left;
|
||||
grid.add(cell);
|
||||
} else {
|
||||
let style = ls_colors.style_for_path(value.clone());
|
||||
let ansi_style = style
|
||||
.map(ToNuAnsiStyle::to_nu_ansi_style)
|
||||
.unwrap_or_default();
|
||||
let mut cell = Cell::from(ansi_style.paint(value).to_string());
|
||||
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::Left;
|
||||
grid.add(cell);
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
//! Hotpatch to use lscolors without depending on the unmaintained `ansi-term` crate or crossterm
|
||||
|
||||
pub trait ToNuAnsiStyle {
|
||||
fn to_nu_ansi_style(&self) -> nu_ansi_term::Style;
|
||||
}
|
||||
|
||||
pub trait ToNuAnsiColor {
|
||||
fn to_nu_ansi_color(&self) -> nu_ansi_term::Color;
|
||||
}
|
||||
|
||||
impl ToNuAnsiStyle for lscolors::Style {
|
||||
fn to_nu_ansi_style(&self) -> nu_ansi_term::Style {
|
||||
nu_ansi_term::Style {
|
||||
foreground: self
|
||||
.foreground
|
||||
.as_ref()
|
||||
.map(ToNuAnsiColor::to_nu_ansi_color),
|
||||
background: self
|
||||
.background
|
||||
.as_ref()
|
||||
.map(ToNuAnsiColor::to_nu_ansi_color),
|
||||
is_bold: self.font_style.bold,
|
||||
is_dimmed: self.font_style.dimmed,
|
||||
is_italic: self.font_style.italic,
|
||||
is_underline: self.font_style.underline,
|
||||
is_blink: self.font_style.rapid_blink || self.font_style.slow_blink,
|
||||
is_reverse: self.font_style.reverse,
|
||||
is_hidden: self.font_style.hidden,
|
||||
is_strikethrough: self.font_style.strikethrough,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToNuAnsiColor for lscolors::Color {
|
||||
fn to_nu_ansi_color(&self) -> nu_ansi_term::Color {
|
||||
match self {
|
||||
lscolors::Color::RGB(r, g, b) => nu_ansi_term::Color::Rgb(*r, *g, *b),
|
||||
lscolors::Color::Fixed(n) => nu_ansi_term::Color::Fixed(*n),
|
||||
lscolors::Color::Black => nu_ansi_term::Color::Black,
|
||||
lscolors::Color::Red => nu_ansi_term::Color::Red,
|
||||
lscolors::Color::Green => nu_ansi_term::Color::Green,
|
||||
lscolors::Color::Yellow => nu_ansi_term::Color::Yellow,
|
||||
lscolors::Color::Blue => nu_ansi_term::Color::Blue,
|
||||
lscolors::Color::Magenta => nu_ansi_term::Color::Purple,
|
||||
lscolors::Color::Cyan => nu_ansi_term::Color::Cyan,
|
||||
lscolors::Color::White => nu_ansi_term::Color::White,
|
||||
|
||||
// Below items are a rough translations to 256 colors as
|
||||
// we do not have bright varients available on ansi-term
|
||||
lscolors::Color::BrightBlack => nu_ansi_term::Color::Fixed(8),
|
||||
lscolors::Color::BrightRed => nu_ansi_term::Color::Fixed(9),
|
||||
lscolors::Color::BrightGreen => nu_ansi_term::Color::Fixed(10),
|
||||
lscolors::Color::BrightYellow => nu_ansi_term::Color::Fixed(11),
|
||||
lscolors::Color::BrightBlue => nu_ansi_term::Color::Fixed(12),
|
||||
lscolors::Color::BrightMagenta => nu_ansi_term::Color::Fixed(13),
|
||||
lscolors::Color::BrightCyan => nu_ansi_term::Color::Fixed(14),
|
||||
lscolors::Color::BrightWhite => nu_ansi_term::Color::Fixed(15),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
mod griddle;
|
||||
mod icons;
|
||||
mod lscolor_ansiterm;
|
||||
mod table;
|
||||
|
||||
pub use griddle::Griddle;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use lscolors::LsColors;
|
||||
use lscolors::{LsColors, Style};
|
||||
use nu_color_config::{get_color_config, style_primitive};
|
||||
use nu_engine::column::get_columns;
|
||||
use nu_engine::{env_to_string, CallExt};
|
||||
@ -14,7 +14,7 @@ use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use terminal_size::{Height, Width};
|
||||
|
||||
use super::lscolor_ansiterm::ToNuAnsiStyle;
|
||||
//use super::lscolor_ansiterm::ToNuAnsiStyle;
|
||||
|
||||
const STREAM_PAGE_SIZE: usize = 1000;
|
||||
const STREAM_TIMEOUT_CHECK_INTERVAL: usize = 100;
|
||||
@ -222,13 +222,14 @@ fn handle_row_stream(
|
||||
Some(&metadata),
|
||||
);
|
||||
let ansi_style = style
|
||||
.map(ToNuAnsiStyle::to_nu_ansi_style)
|
||||
.map(Style::to_crossterm_style)
|
||||
// .map(ToNuAnsiStyle::to_nu_ansi_style)
|
||||
.unwrap_or_default();
|
||||
let use_ls_colors = config.use_ls_colors;
|
||||
|
||||
if use_ls_colors {
|
||||
vals[idx] = Value::String {
|
||||
val: ansi_style.paint(path).to_string(),
|
||||
val: ansi_style.apply(path).to_string(),
|
||||
span: *span,
|
||||
};
|
||||
}
|
||||
@ -236,13 +237,14 @@ fn handle_row_stream(
|
||||
Err(_) => {
|
||||
let style = ls_colors.style_for_path(path.clone());
|
||||
let ansi_style = style
|
||||
.map(ToNuAnsiStyle::to_nu_ansi_style)
|
||||
.map(Style::to_crossterm_style)
|
||||
// .map(ToNuAnsiStyle::to_nu_ansi_style)
|
||||
.unwrap_or_default();
|
||||
let use_ls_colors = config.use_ls_colors;
|
||||
|
||||
if use_ls_colors {
|
||||
vals[idx] = Value::String {
|
||||
val: ansi_style.paint(path).to_string(),
|
||||
val: ansi_style.apply(path).to_string(),
|
||||
span: *span,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user