Repository: nushell/nushell
File: crates/nu-command/src/viewers/table.rs (Rust)

Code before:
        && config.shell_integration.osc8;

    let ansi_style = style.map(Style::to_nu_ansi_term_style).unwrap_or_default();
    let ansi_style = if ansi_style.is_plain() {
        // If there is no style at all (that's what is_plain() is checking),
        // set it to use 'default' foreground and background colors
        // This prevents it being colored in tabled as string colors
        // to test this, set $env.LS_COLORS = 'fi=0' and $env.config.color_config.string = 'red'
        // if a regular file without an extension is the color 'default' then it's working
        // if a regular file without an extension is the color 'red' then it's not working
        nu_ansi_term::Style {
            foreground: Some(nu_ansi_term::Color::Default),
            background: Some(nu_ansi_term::Color::Default),
            is_bold: false,
            is_dimmed: false,
            is_italic: false,
            is_underline: false,
            is_blink: false,
            is_reverse: false,
            is_hidden: false,
            is_strikethrough: false,
            prefix_with_reset: false,
        }
    } else {
        ansi_style
    };

    let full_path = PathBuf::from(stripped_path.as_ref())
        .canonicalize()
        .unwrap_or_else(|_| PathBuf::from(stripped_path.as_ref()));

    let full_path_link = make_clickable_link(
        full_path.display().to_string(),
        Some(path),
        show_clickable_links,
    );

    let val = ansi_style.paint(full_path_link).to_string();
    Some(Value::string(val, span))
}

fn maybe_strip_color(output: String, use_ansi_coloring: bool) -> String {
    // only use `use_ansi_coloring` here, it already includes `std::io::stdout().is_terminal()`
    // when set to "auto"
    if !use_ansi_coloring {
        // Draw the table without ansi colors
        nu_utils::strip_ansi_string_likely(output)
    } else {
        // Draw the table with ansi colors
        output
    }

Review comment (suggestion):
This `.unwrap_or_default()` and then checking if it's the default value, we can directly create the style we need in `.unwrap_or()`
```suggestion
    // If there is no style at all set it to use 'default' foreground and background
    // colors. This prevents it being colored in tabled as string colors.
    // To test this:
    //   $env.LS_COLORS = 'fi=0'
    //   $env.config.color_config.string = 'red'
    // if a regular file without an extension is the color 'default' then it's working
    // if a regular file without an extension is the color 'red' then it's not working
    let ansi_style = style
        .map(Style::to_nu_ansi_term_style)
        .unwrap_or(nu_ansi_term::Style {
            foreground: Some(nu_ansi_term::Color::Default),
            background: Some(nu_ansi_term::Color::Default),
            is_bold: false,
            is_dimmed: false,
            is_italic: false,
            is_underline: false,
            is_blink: false,
            is_reverse: false,
            is_hidden: false,
            is_strikethrough: false,
            prefix_with_reset: false,
        });
```

Code after:
        && config.shell_integration.osc8;

    // If there is no style at all set it to use 'default' foreground and background
    // colors. This prevents it being colored in tabled as string colors.
    // To test this:
    //   $env.LS_COLORS = 'fi=0'
    //   $env.config.color_config.string = 'red'
    // if a regular file without an extension is the color 'default' then it's working
    // if a regular file without an extension is the color 'red' then it's not working
    let ansi_style = style
        .map(Style::to_nu_ansi_term_style)
        .unwrap_or(nu_ansi_term::Style {
            foreground: Some(nu_ansi_term::Color::Default),
            background: Some(nu_ansi_term::Color::Default),
            is_bold: false,
            is_dimmed: false,
            is_italic: false,
            is_underline: false,
            is_blink: false,
            is_reverse: false,
            is_hidden: false,
            is_strikethrough: false,
            prefix_with_reset: false,
        });

    let full_path = PathBuf::from(stripped_path.as_ref())
        .canonicalize()
        .unwrap_or_else(|_| PathBuf::from(stripped_path.as_ref()));

    let full_path_link = make_clickable_link(
        full_path.display().to_string(),
        Some(path),
        show_clickable_links,
    );

    let val = ansi_style.paint(full_path_link).to_string();
    Some(Value::string(val, span))
}

fn maybe_strip_color(output: String, use_ansi_coloring: bool) -> String {
    // only use `use_ansi_coloring` here, it already includes `std::io::stdout().is_terminal()`
    // when set to "auto"
    if !use_ansi_coloring {
        // Draw the table without ansi colors
        nu_utils::strip_ansi_string_likely(output)
    } else {
        // Draw the table with ansi colors
        output
    }
}