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

ls/rm/cd strip ansi escapes #6315

Open
panicbit opened this issue Aug 13, 2022 · 14 comments · May be fixed by #12567
Open

ls/rm/cd strip ansi escapes #6315

panicbit opened this issue Aug 13, 2022 · 14 comments · May be fixed by #12567
Labels
enhancement New feature or request file-system Related to commands and core nushell behavior around the file system inconsistent-behavior Behavior between different commands or types inconsistent/unexpected
Milestone

Comments

@panicbit
Copy link
Contributor

panicbit commented Aug 13, 2022

Describe the bug

ls, rm, cd and possibly other tools strip ansi escapes, rendering some file operations impossible or resulting in surprising and dangerous behaviour.

How to reproduce

  1. touch $"(ansi red)hello"
  2. rm touch $"(ansi red)hello"
  3. observe rm failing to find the file

Expected behavior

I expect core filesystem commands to do as I say.

Screenshots

grafik
grafik

Configuration

key value
version 0.66.4
branch
commit_hash 8783742
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.62.1 (e092d0b6b 2022-07-16)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.62.1 (a748cf5a3 2022-06-08)
pkg_version 0.66.4
build_time 2022-08-13 17:05:47 +02:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Additional context

No response

@fdncred
Copy link
Collaborator

fdncred commented Aug 13, 2022

seems like an edge case where people would actually name files using ansi escapes. we talked about this when we decided to strip them for file move operations. maybe there should be some string literal way to remove files when mistakes like this happen?

@fdncred fdncred added the enhancement New feature or request label Aug 13, 2022
@panicbit
Copy link
Contributor Author

panicbit commented Aug 13, 2022

What is the usecase for automatically stripping escapes from a path? It seems to me like that is more of an edgecase. Especially considering that there is already a mechanism to strip escapes explicitly if you really need to via ansi strip.
There will always be one or the other command that won't do the stripping and then someone will be surprised by it (in fact, touch and mkdir don't strip right now, already causing an inconsistent behaviour).
This stripping is simply causing much more issues than it solves IMO.

@panicbit
Copy link
Contributor Author

panicbit commented Aug 13, 2022

Ok, I see what the original reason in #6220 was regarding find.
IMO this is the wrong approach to solve it and more of an issue with how find works.

=> ls can colorize table rendering without modifying the content, why can't find?

@panicbit
Copy link
Contributor Author

Maybe we could extend the PipelineMetadata a bit for the find usecase?

#[derive(Debug, Clone)]
pub struct PipelineMetadata {
pub data_source: DataSource,
}
#[derive(Debug, Clone)]
pub enum DataSource {
Ls,
}

While I'd love to see a more generic approach to modify the rendering of the table without having to hardcode specific commands, adding find as another special case should work for now.

@kubouch
Copy link
Contributor

kubouch commented Aug 13, 2022

We could strip ansi sequences for touch and other "sink" commands that do not pass data further. But the metadata approach could be a good fit as well.

@kubouch
Copy link
Contributor

kubouch commented Aug 13, 2022

The use case for stripping ansi sequences is if you want to do something like ls | find blah | each {|it| rm $it.name }

@fdncred
Copy link
Collaborator

fdncred commented Aug 13, 2022

I'm always open to a PR with a better solution.

@panicbit
Copy link
Contributor Author

Already working on it!

@panicbit
Copy link
Contributor Author

panicbit commented Aug 14, 2022

Found a bug in find while digging through its code X)

grafik

I'll fix it along the way. We should be able to cherry-pick the fix if we don't end up accepting my full changeset.

@panicbit
Copy link
Contributor Author

panicbit commented Aug 14, 2022

Oh, looks like it's even worse; there's another bug that is independent from use_ls_colors:

grafik

(I'm so sorry 😅)

@fdncred
Copy link
Collaborator

fdncred commented Aug 14, 2022

No worries. I'm glad you're finding and fixing these. It was a real pain to make find highlight things.

@panicbit
Copy link
Contributor Author

panicbit commented Aug 14, 2022

I'm not gonna ask about what's happening here 😅 :
grafik

@panicbit
Copy link
Contributor Author

#6324 should lay the groundwork for fixing this issue.

@sholderbach sholderbach added file-system Related to commands and core nushell behavior around the file system inconsistent-behavior Behavior between different commands or types inconsistent/unexpected labels Oct 12, 2022
@github-actions github-actions bot added the Stale used for marking issues and prs as stale label Jan 18, 2023
@sholderbach sholderbach removed the Stale used for marking issues and prs as stale label Feb 21, 2024
@sholderbach
Copy link
Member

Boosting this one as something that we should probably resolve in a principled way before 1.0 .

The current behavior of manipulating the data to deal with how find or other commands work feels deeply unserious.

Nushell should allow you to compose data pipelines reliably. And if we partially made that work for ls that you can get highlighting that doesn't affect things downstream, we should have the same experience with find if possible. Undocumented stripping seems to cause more potential harm.

See also #6220 (comment)

@fdncred fdncred added this to the 1.0 milestone Feb 21, 2024
@sholderbach sholderbach linked a pull request Apr 18, 2024 that will close this issue
sholderbach added a commit to sholderbach/nushell that referenced this issue Apr 18, 2024
Previously all our file system operations tried to remove ANSI escape
codes from their input (as well as other characters like `\t`).
- This is bad if you want to deal with files that are allowed arbitrary
names in the bounds of the OS/FS
- This was done as we had `ls` inserting colors before we had the
working `PipelineMetadata` system.
- Currently `find` will still insert ANSI coloring into its result and
messing with downstream commands (see nushell#11899)

Closes nushell#6315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request file-system Related to commands and core nushell behavior around the file system inconsistent-behavior Behavior between different commands or types inconsistent/unexpected
Projects
Status: No status
4 participants