mbucc / shmig

Database migration tool written in BASH.
BSD 3-Clause "New" or "Revised" License
461 stars 50 forks source link

color auto doesn't really work #8

Closed mbucc closed 7 years ago

mbucc commented 9 years ago

at least on zsh.

mark@marks-mbp:~/src/events/db% echo $0
-zsh
mark@marks-mbp:~/src/events/db% shmig -C auto
Usage: shmig [options] <action> [arguments...]
Where options include are:
  -h
      show a more detailed usage

  -C COLOR
      set color policy. possible options:
          auto - default. will use colors if possible
          never - do not use colors
          always - always use colors

and action is one of create, up, down, rollback, redo, and pending

shmig: \e[1m\e[93maction\e[0m \e[31mrequired\e[0m
dtanner commented 8 years ago

I have the same issue (OS X, zsh, iterm2). I noticed that if I swap \e with \033 in the color definitions, it works properly for me. I'm not an ascii artisan though, so not sure if this change would be a good permanent swap in the code.?

mbucc commented 8 years ago

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html says: "It is not possible to use echo portably across all POSIX systems unless both -n (as the first argument) and escape sequences are omitted."

Per that same page, they suggest using printf for portability.

Another option is to simply delete the code that colors the output. My favorite kind of commit. ;)

mbucc commented 8 years ago

I'd like to remove the coloring. It seems difficult to do correctly across all shells. I'd like to make this as portable as possible, and the benefit of coloring prompt output doesn't seem worth complexity.

Quoting from http://www.linuxjournal.com/article/8603?page=0,1:

So, if you want a portable program that can run on various terminals with the same or reduced functionalities, you should use curses. Curses uses terminfo to find the correct codes to accomplish these types of tasks across various terminals. Terminfo is a large database that contains information about the various functionalities of different terminals

If anyone has other suggestions or knows how to do this in a portable way, please comment. I'll leave this ticket open for a while.

mbucc commented 7 years ago

Closing as won't fix. Can revisit later if need be.