Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversed background/foreground for the sticky bit #77

Open
sylvestre opened this issue Dec 12, 2023 · 3 comments
Open

Reversed background/foreground for the sticky bit #77

sylvestre opened this issue Dec 12, 2023 · 3 comments

Comments

@sylvestre
Copy link
Contributor

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
Copy link
Contributor

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

@sylvestre
Copy link
Contributor Author

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
Copy link
Contributor

tavianator commented Dec 12, 2023

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants