From 7746e84199a51715df64d19d4ee5ef40ec05c78c Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:43:12 -0700 Subject: [PATCH] Make LS_COLORS functionality faster in `explore`, especially on Windows (#12984) Closes #12980. More context there, but basically `explore` was getting file metadata for every row every time the record view was rendered. The quick fix for now is to do the `LS_COLORS` colouring with a `&str` instead of a path and file metadata. --- crates/nu-explore/src/nu_common/lscolor.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/nu-explore/src/nu_common/lscolor.rs b/crates/nu-explore/src/nu_common/lscolor.rs index 31a5571ef5..491d2c3f3a 100644 --- a/crates/nu-explore/src/nu_common/lscolor.rs +++ b/crates/nu-explore/src/nu_common/lscolor.rs @@ -4,7 +4,6 @@ use nu_ansi_term::{Color, Style}; use nu_engine::env_to_string; use nu_protocol::engine::{EngineState, Stack}; use nu_utils::get_ls_colors; -use std::fs::symlink_metadata; pub fn create_lscolors(engine_state: &EngineState, stack: &Stack) -> LsColors { let colors = stack @@ -14,6 +13,7 @@ pub fn create_lscolors(engine_state: &EngineState, stack: &Stack) -> LsColors { get_ls_colors(colors) } +/// Colorizes any columns named "name" in the table using LS_COLORS pub fn lscolorize(header: &[String], data: &mut [Vec], lscolors: &LsColors) { for (col, col_name) in header.iter().enumerate() { if col_name != "name" { @@ -33,14 +33,7 @@ pub fn lscolorize(header: &[String], data: &mut [Vec], lscolors: &LsColo fn get_path_style(path: &str, ls_colors: &LsColors) -> Option