Skip to content

Commit

Permalink
ls: enable ANSI support on Windows for --hyperlink
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Dec 6, 2023
1 parent de0a19d commit c947608
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/uu/ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ once_cell = { workspace = true }
selinux = { workspace = true, optional = true }
hostname = "0.3"

[target.'cfg(windows)'.dependencies]
nu-ansi-term = "0.49.0"

[[bin]]
name = "ls"
path = "src/main.rs"
Expand Down
3 changes: 3 additions & 0 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,9 @@ fn display_file_name(
let mut width = name.width();

if config.hyperlink {
#[cfg(windows)]
let _enabled = nu_ansi_term::enable_ansi_support();

let hostname = hostname::get().unwrap_or(OsString::from(""));
let hostname = hostname.to_string_lossy();

Expand Down
1 change: 1 addition & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3840,6 +3840,7 @@ fn test_ls_hyperlink() {
let path = at.root_dir_resolved();

let result = scene.ucmd().arg("--hyperlink").succeeds();
println!("stdout: {}", result.stdout_str());
assert!(result.stdout_str().contains("\x1b]8;;file://"));
assert!(result
.stdout_str()
Expand Down

0 comments on commit c947608

Please sign in to comment.