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

No usable output or panic when not outputting to a terminal #13

Closed
yannleretaille opened this issue Dec 5, 2018 · 1 comment
Closed
Labels
kind/bug Something isn't working

Comments

@yannleretaille
Copy link
Contributor

Example 1

#~> lsd -a | wc
thread 'main' panicked at 'failed to retrieve terminal size', /home/yann/.cargo/registry/src/github.com-1ecc6299db9ec823/lsd-0.6.1/src/display.rs:29:21

Expected behavior: properly pipe contents to next program, expecting infinite width (e.g. "0")

Example 2

#~> lsd -al > test

Test now contains a lot of unprintable characters, e.g. it looks like this:

�[38;5;33md�[0m�[38;5;40mr�[38;5;192mw�[38;5;124mx�[38;5;40mr�[38;5;168m-�[38;5;124mx�[38;5;40mr�[38;5;168m-�[38;5;124mx�[0m  �[38;5;230myann�[0m  �[38;5;187musers�[0m  �[38;5;229m    4 KB�[0m  �[38;5;40mWed Dec  5 04:44:57 2018�[0m  �[38;5;33m  .git/�[0m
�[38;5;33md�[0m�[38;5;40mr�[38;5;192mw�[38;5;124mx�[38;5;40mr�[38;5;168m-�[38;5;124mx�[38;5;40mr�[38;5;168m-�[38;5;124mx�[0m  �[38;5;230myann�[0m  �[38;5;187musers�[0m  �[38;5;229m    4 KB�[0m  �[38;5;40mWed Dec  5 04:23:13 2018�[0m  �[38;5;33m  src/�[0m
�[38;5;33md�[0m�[38;5;40mr�[38;5;192mw�[38;5;124mx�[38;5;40mr�[38;5;168m-�[38;5;124mx�[38;5;40mr�[38;5;168m-�[38;5;124mx�[0m  �[38;5;230myann�[0m  �[38;5;187musers�[0m  �[38;5;229m    4 KB�[0m  �[38;5;40mWed Dec  5 04:24:43 2018�[0m  �[38;5;33m  target/�[0m
�[38;5;184m.�[0m�[38;5;40mr�[38;5;192mw�[38;5;168m-�[38;5;40mr�[38;5;168m--�[38;5;40mr�[38;5;168m--�[0m  �[38;5;230myann�[0m  �[38;5;187musers�[0m  �[38;5;229m   26 B �[0m  �[38;5;40mWed Dec  5 04:23:13 2018�[0m  �[38;5;184m  .gitignore�[0m
�[38;5;184m.�[0m�[38;5;40mr�[38;5;192mw�[38;5;168m-�[38;5;40mr�[38;5;168m--�[38;5;40mr�[38;5;168m--�[0m  �[38;5;230myann�[0m  �[38;5;187musers�[0m  �[38;5;229m  119 B �[0m  �[38;5;40mWed Dec  5 04:23:13 2018�[0m  �[38;5;184m  .travis.yml�[0m
...

Expected behavior: don't print escape/color codes when not outputting to a terminal

Proposed solution

  1. fetch terminal_size() at program startup and cache the result.
  2. If term_size is None, disable color formatting for all outputs
  3. If term_size is None, either set a reasonable default width for text files in print_grid or just default to print_one_per_line instead
@Peltoche Peltoche added the kind/bug Something isn't working label Dec 5, 2018
@Peltoche
Copy link
Collaborator

Peltoche commented Dec 5, 2018

Hello @yannleretaille,

Thanks for the report! The terminal_size trick seem a good idea. It think it will be easier to refactor the color package into a struct before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants