sharkdp / lscolors

A Rust library and tool to colorize paths using LS_COLORS
Apache License 2.0
258 stars 17 forks source link

Reversed background/foreground for the sticky bit #77

Open sylvestre opened 9 months ago

sylvestre commented 9 months ago

With

mkdir sticky
chmod o+t sticky
use lscolors::LsColors;

fn main() {
    let tmp_file = "sticky";

    let lscolors = LsColors::from_env().unwrap_or_default();

    let style = lscolors.style_for_path(tmp_file).unwrap();
    let style = style.to_nu_ansi_term_style();
    println!("result = {}", style.paint("foo").to_string().escape_default());   
}

it returns result = \u{1b}[44;37mfoo\u{1b}[0m

while GNU ls returns:

^[[0m^[[37;44msticky^[[0m

44 & 37 aren't in the same order.

with:

/usr/bin/ls -d --color=always sticky > a.txt
cat -v a.txt
tavianator commented 9 months ago

Is this with the gnu_legacy feature? It may need to be fixed in nu-ansi-term itself

sylvestre commented 9 months ago

with nu-ansi-term

[package]
name = "test-lscolors"
version = "0.1.0"
edition = "2021"

[dependencies]
lscolors = { version = "0.16.0", features = ["nu-ansi-term"] }
tavianator commented 9 months ago

So presumably these could be swapped to print the foreground first: https://github.com/nushell/nu-ansi-term/blob/f1c83ff2923d94bc1f85dca476e58fb557d44f5f/src/ansi.rs#L67-L80

This happens to work for the default GNU styles because they always put the foreground first. But really for 100% compatibility, there should be a mode that just gives you the verbatim bytes to print to the terminal without attempting to parse the escape sequences. That could be added as a separate Style-like thing maybe something like Style::to_bytes().