srsudar / eg

Useful examples at the command line.
MIT License
1.8k stars 99 forks source link

Formatting is wrong in Msysgit's bash on Windows #16

Closed cool-RR closed 9 years ago

cool-RR commented 9 years ago

Shows like this:

The system cannot find the path specified.
?[30m?[1m#?[0m?[31m?[1m tar?[0m

extract .tar file

    ?[36m?[1m?[0m?[32m?[1mtar vfx archive.tar?[0m

unzip and extract .tar.gz or .tgz file

    ?[36m?[1m?[0m?[32m?[1mtar vfxz g_zipped_archive.tar.gz?[0m

turn directory into a .tar file

    ?[36m?[1m?[0m?[32m?[1mtar vfc tarred_directory.tar directory?[0m

turn directory into g-zipped directory

    ?[36m?[1m?[0m?[32m?[1mtar vfcz z_zipped_directory.tar.gz directory?[0m
srsudar commented 9 years ago

Hmm, I'm not sure what "the system cannot find the path specified" is about. Maybe we're not doing appropriate handling of paths for Windows?

The ?[36m sequences are ANSI escape sequences for coloring prompt output on *nix machines. Color is known not to work on windows, as it uses its own methods to colorize prompt output. Try running this, which will turn off color:

eg --no-color tar

Does that make output look normal? If so, try adding a color = false line to your egrc, as shown in the README:

[eg-config]
color = false

It's a bummer to not support color in Windows, as I think the color is nice, but it's a greatly simplifying assumption, keeps us dependency free, and I expect the majority of interested users will be on a *nix-style terminal. If this is wrong, and many Windows users are frustrated, I'd be curious to know.

Are there any terminals on Windows that respect ANSI escape sequences? That might be another thing to look for.

cool-RR commented 9 years ago

That solved it, thank you!

Though it seems like I'm getting double spacing on this shell. See this screenshot: http://i.imgur.com/3vOl6qC.jpg

Any idea what to do about this?

On Sat, May 2, 2015 at 7:45 PM, Sam Sudar notifications@github.com wrote:

Hmm, I'm not sure what "the system cannot find the path specified" is about. Maybe we're not doing appropriate handling of paths for Windows?

The ?[36m sequences are ANSI escape sequences for coloring prompt output on *nix machines. Color is known not to work on windows, as it uses its own methods to colorize prompt output. Try running this, which will turn off color:

eg --no-color tar

Does that make output look normal? If so, try adding a color = false line to your egrc, as shown in the README:

[eg-config] color = false

It's a bummer to not support color in Windows, as I think the color is nice, but it's a greatly simplifying assumption, keeps us dependency free, and I expect the majority of interested users will be on a *nix-style terminal. If this is wrong, and many Windows users are frustrated, I'd be curious to know.

Are there any terminals on Windows that respect ANSI escape sequences? That might be another thing to look for.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-98377373.

srsudar commented 9 years ago

Odd that "The system cannot find the specified path" is still hanging around.... I need to get ahold of a Windows machine and mess around to see what's causing that.

Haha, that spacing is supposed to be a feature! When I was writing the examples I found that the increased spacing made it easier to visually parse, especially without color. Without it all the text blurred together.

It might be interesting to consider a --squeeze option to remove the extra spacing if people don't like it.

cool-RR commented 9 years ago

Agreed regarding squeeze. If that gets implemented, I appreciated if you could let me know at ram@rachum.com . Also, I noticed eg uses more to paginate, at least on my machine. Why not use less ?

On Sat, May 2, 2015 at 9:19 PM, Sam Sudar notifications@github.com wrote:

Odd that "The system cannot find the specified path" is still hanging around.... I need to get ahold of a Windows machine and mess around to see what's causing that.

Haha, that spacing is supposed to be a feature! When I was writing the examples I found that the increased spacing made it easier to visually parse, especially without color. Without it all the text blurred together.

It might be interesting to consider a --squeeze option to remove the extra spacing if people don't like it.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-98384013.

srsudar commented 9 years ago

eg tries to avoid making any decisions about which pager to use. We're currently using pydoc.pager and pydoc.pipepager, depending on some inputs, and relying on pydoc to resolve the pager. You can look at their resolution algorithm in the source. It tries to do some smart checking.

Is it possible that you have $PAGER set to more or anything like that?

Check out the Paging section of the README as well. You can try setting a command like less -R, which will use less AND will try to escape colors correctly.

Come to think of it, that might explain why you aren't getting colors. I'd be curious to if a paging via less -R gives you color on Windows:

eg --pager-cmd 'less -R' tar

cool-RR commented 9 years ago

Holy shit that worked! I put export PAGER=less in my .bashrc and now I have less and color and everything.

As long as you're being a magical fairy who's sprinkling magic dust over all of my shell-related problems, can you tell me how to customize the colors? Because my background is black, and the dark blue is barely legible.

On Sat, May 2, 2015 at 9:32 PM, Sam Sudar notifications@github.com wrote:

eg tries to avoid making any decisions about which pager to use. We're currently using pydoc.pager and pydoc.pipepager, depending on some inputs, and relying on pydoc to resolve the pager. You can look at their resolution algorithm in the source https://hg.python.org/cpython/file/2.7/Lib/pydoc.py#l1377. It tries to do some smart checking.

Is it possible that you have $PAGER set to more or anything like that?

Check out the Paging section https://github.com/srsudar/eg#paging of the README as well. You can try setting a command like less -R, which will use less AND will try to escape colors correctly.

Come to think of it, that might explain why you aren't getting colors. I'd be curious to if a paging via less -R gives you color on Windows:

eg --pager-cmd 'less -R' tar

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-98384533.

srsudar commented 9 years ago

Haha sure. First, do you know if eg can find your .egrc file? Part of me worries that the "cannot find the specified file" message is because the home directory resolution isn't working on windows or something like that. If you haven't already, I would first try creating a file called .egrc in your home directory (wherever cd ~ takes you), and putting this as the contents:

[eg-config]
color = false

When you run eg tar now, is the color off? If so, eg can find the config file, and you'll be able to set the colors there. It that doesn't work, try passing the file in directly with:

eg --config-file='/absolute/path/to/egrc' tar

and see if the color is turned off there. If so, you can still use the config file, but you'll have to alias eg to eg --config-file='whatever.

cool-RR commented 9 years ago

I know that eg is able to find the .egrc, I successfully canceled colors before (and then reenabled when we got the pager thing.)

So how exactly can I make the dark blue be lighter so it'll be visible?

On Sat, May 2, 2015 at 9:52 PM, Sam Sudar notifications@github.com wrote:

Haha sure. First, do you know if eg can find your .egrc file? Part of me worries that the "cannot find the specified file" message is because the home directory resolution isn't working on windows or something like that. If you haven't already, I would first try creating a file called .egrc in your home directory (wherever cd ~ takes you), and putting this as the contents:

[eg-config] color = false

When you run eg tar now, is the color off? If so, eg can find the config file, and you'll be able to set the colors there. It that doesn't work, try passing the file in directly with:

eg --config-file='/absolute/path/to/egrc' tar

and see if the color is turned off there. If so, you can still use the config file, but you'll have to alias eg to eg --config-file='whatever.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-98386152.

srsudar commented 9 years ago

Ah ok, good.

First pick a color you like. I forget where I saw these listed clearly...hmm. I use this function, which I stole from somewhere online, to see examples of what colors are possible:

spectrum_ls () {
        for code in {000..255}
        do
                print -P -- "$code: %F{$code}fancy FANCY text%f"
        done
}

Paste that into terminal to define the function, then type spectrum_ls to see your options.

At that point you'll have to figure out how to replicate that color as a standard ANSI escape sequence, which I'm afraid I forget how to do. If you find a good way to convert them, I'd love to know. Once you've got it, check out the color section of the README. If it's the dark blue that you're having trouble seeing, overwrite the backticks example. Adding this to your .egrc would change the backticks to the burnt orange I use for my headings:

[color]
backticks = '\x1b[38;5;172m'
cool-RR commented 9 years ago

That function didn't work. I ended up making do with '\033[0;36m'. It's not bright enough, but I tried several things I found online and this was the most legible, so I'll use that. And at least I got another question answered today: What is the absolute worst color specification format known to mankind.

Thank you for all your help Sam!

On Sat, May 2, 2015 at 10:36 PM, Sam Sudar notifications@github.com wrote:

Ah ok, good.

First pick a color you like. I forget where I saw these listed clearly...hmm. I use this function, which I stole from somewhere online, to see examples of what colors are possible:

spectrum_ls () { for code in {000..255} do print -P -- "$code: %F{$code}fancy FANCY text%f" done }

Paste that into terminal to define the function, then type spectrum_ls to see your options.

At that point you'll have to figure out how to replicate that color as a standard ANSI escape sequence, which I'm afraid I forget how to do. If you find a good way to convert them, I'd love to know. Once you've got it, check out the color section of the README https://github.com/srsudar/eg#color. If it's the dark blue that you're having trouble seeing, overwrite the backticks example. Adding this to your .egrc would change the backticks to the burnt orange I use for my headings:

[color] backticks = '\x1b[38;5;172m'

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-98390484.

cool-RR commented 9 years ago

Update: I upgrade my Msys to Msys2, and now colors don't work again. I've been trying to solve it for an hour now but couldn't. I see escape sequences in the output. Note that the except eg there is color in the shell, for example when I use ls. I tries using both less and less -R as pagers but still I'm seeing escape sequences in the output instead of colors.

On Sat, May 2, 2015 at 10:49 PM, Ram Rachum ram@rachum.com wrote:

That function didn't work. I ended up making do with '\033[0;36m'. It's not bright enough, but I tried several things I found online and this was the most legible, so I'll use that. And at least I got another question answered today: What is the absolute worst color specification format known to mankind.

Thank you for all your help Sam!

On Sat, May 2, 2015 at 10:36 PM, Sam Sudar notifications@github.com wrote:

Ah ok, good.

First pick a color you like. I forget where I saw these listed clearly...hmm. I use this function, which I stole from somewhere online, to see examples of what colors are possible:

spectrum_ls () { for code in {000..255} do print -P -- "$code: %F{$code}fancy FANCY text%f" done }

Paste that into terminal to define the function, then type spectrum_ls to see your options.

At that point you'll have to figure out how to replicate that color as a standard ANSI escape sequence, which I'm afraid I forget how to do. If you find a good way to convert them, I'd love to know. Once you've got it, check out the color section of the README https://github.com/srsudar/eg#color. If it's the dark blue that you're having trouble seeing, overwrite the backticks example. Adding this to your .egrc would change the backticks to the burnt orange I use for my headings:

[color] backticks = '\x1b[38;5;172m'

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-98390484.

srsudar commented 9 years ago

Interesting. What do you get if you do which less? It's for sure installed? If you do man less does it show -R as a supported flag for interpreting escape sequences in whatever version of less you now have on your machine?

cool-RR commented 9 years ago

I get /usr/bin/less

Not sure about your question whether it's installed. It's working. I have no reason to think it's not installed.

Unfortunately there is no man in Msys.

I did less --version and I got 471.

On Wed, May 13, 2015 at 6:20 PM, Sam Sudar notifications@github.com wrote:

Interesting. What do you get if you do which less? It's for sure installed? If you do man less does it show -R as a supported flag for interpreting escape sequences in whatever version of less you now have on your machine?

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-101713160.

srsudar commented 9 years ago

Let's create a file that should have color output and then see if less -R displays it correctly. This will let us know if the problem is with less or if eg somehow isn't invoking the correct pager. If your ls output is colorized, do ls >coloredLs. This will put the output of ls into a file called coloredLs.

Now do more coloredLs. Do you see escape sequences? This is just to make sure that redirecting stdout to a file is capturing the escape sequences like it should. Assuming you see them, then try less -R coloredLs. Does it colorize or do you still see escape sequences?

cool-RR commented 9 years ago

The problem with your plan is that when you pipe ls output, it comes out without color. Try ls | less in Linux and you'll see.

On Wed, May 13, 2015 at 7:21 PM, Sam Sudar notifications@github.com wrote:

Let's create a file that should have color output and then see if less -R displays it correctly. This will let us know if the problem is with less or if eg somehow isn't invoking the correct pager. If your ls output is colorized, do ls >coloredLs. This will put the output of ls into a file called coloredLs.

Now do more coloredLs. Do you see escape sequences? This is just to make sure that redirecting stdout to a file is capturing the escape sequences like it should. Assuming you see them, then try less -R coloredLs. Does it colorize or do you still see escape sequences?

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-101734025.

srsudar commented 9 years ago

Well that is surprising. I wonder where ls output is colorized, then. Hmm.

In that case, try downloading this file and doing the same thing. This is a custom cp file I keep around that should be green.

cool-RR commented 9 years ago

Thanks. Now with less -R it does colorize, while with just less it shows control characters.

But when I use eg --pager-cmd "less -R", I still see control characters.

On Wed, May 13, 2015 at 7:28 PM, Sam Sudar notifications@github.com wrote:

Well that is surprising. I wonder where ls output is colorized, then. Hmm.

In that case, try downloading this file https://github.com/srsudar/dotfiles/blob/master/eg/custom_files/cp.md and doing the same thing. This is a custom cp file I keep around that should be green.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-101737328.

srsudar commented 9 years ago

It's possible that some of the "make sure less is installed before invoking it" logic I stole from the pydoc source is failing. If this is happening, your instruction to use less is being overridden.

When you do something like eg --pager-cmd 'less -R' find, and you see control characters, are you sure it's actually using less to page? If you type h when seeing the output you should see a "SUMMARY OF LESS COMMANDS" page. Do you?

cool-RR commented 9 years ago

Yes, it's using less, and showing that help screen when I press h.

On Wed, May 13, 2015 at 8:00 PM, Sam Sudar notifications@github.com wrote:

It's possible that some of the "make sure less is installed before invoking it" logic I stole from the pydoc source is failing. If this is happening, your instruction to use less is being overridden.

When you do something like eg --pager-cmd 'less -R' find, and you see control characters, are you sure it's actually using less to page? If you type h when seeing the output you should see a "SUMMARY OF LESS COMMANDS" page. Do you?

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-101747109.

srsudar commented 9 years ago

But you're still seeing the escape sequences not the color?

What about if you run eg --pager-cmd 'cat' find and eg --pager-cmd 'more' find? Does it use cat and more? Maybe somehow it's not respecting the command at all?

What about eg --pager-cmd 'less -Z' find? -Z isn't a legal option (at least on my install) and less should complain.

cool-RR commented 9 years ago

Oh hey, eg --pager-cmd 'cat' showed color! With more it didn't, just showed control characters. So it does use the pager.

And yet, when I did eg --pager-cmd 'less -Z' it didn't complain. (P.S. you're smart :)

If I do cat whatever | less -Z it does complain. So it looks like eg isn't really using less... But then it is, because the correct help menu showed. So I'm baffled.

On Wed, May 13, 2015 at 8:15 PM, Sam Sudar notifications@github.com wrote:

But you're still seeing the escape sequences not the color?

What about if you run eg --pager-cmd 'cat' find and eg --pager-cmd 'more' find? Does it use cat and more? Maybe somehow it's not respecting the command at all?

What about eg --pager-cmd 'less -Z' find? -Z isn't a legal option (at least on my install) and less should complain.

— Reply to this email directly or view it on GitHub https://github.com/srsudar/eg/issues/16#issuecomment-101750224.

srsudar commented 9 years ago

I don't get credit for being smart, I'm afraid. I wrote it so I know where to look for bugs. My guess is that the problem is here. I copied that code from pydoc when it was trying to resolve if you had less installed. My guess is that the 2>/dev/null bit is failing on Windows, causing it to use the default pager, which in this case is just less but without the flags.

Can you open an issue referencing this issue? I'm going to do away with that somehow.