[MDEV-7552] Add colors in the shell Created: 2015-02-06 Updated: 2015-10-30 Resolved: 2015-10-30 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Scripts & Clients |
| Fix Version/s: | N/A |
| Type: | Epic | Priority: | Major |
| Reporter: | Fabio Alessandro Locati | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 1 |
| Labels: | None | ||
| Epic Name: | Colors in the shell |
| Description |
|
It would be great to have, at least optional, colors for the command line. The most critical one I think it's for the "prompt" variable to be able to easily recognise production and testing environment, while it would be a nice to have to be able to use it even for queries (as you write them) and for results, warnings and errors. |
| Comments |
| Comment by Jean Weisbuch [ 2015-02-07 ] | ||||||||||||||||
|
Its possible to add colors to the prompt by modifying the mysql CLI tool by adding ANSI color codes to processed_prompt.append() calls on the construct_prompt() function located on client/mysql.cc, for example replacing :
By :
At line 5120 on 10.0.16 will end up having the prompt "\h" to output "localhost" in green while keeping the rest of the prompt with the default color. As its less than convenient to have to modify the source code to put statically colors, the simplest way to allow colors on prompts is to add new "variables" on the construct_prompt() function such as :
And adding a reset of the color in the end of the prompt (if \0 was not called before the end of the prompt) by replacing at the end of the function :
With :
(doing this only if a color code has been specified on the prompt would be safer/cleaner) Then having a prompt of "\2\N\0 \h [\3\d\0]> " would display "MariaDB localhost [(none)]> ". You might also be interrested in | ||||||||||||||||
| Comment by Fabio Alessandro Locati [ 2015-02-07 ] | ||||||||||||||||
|
the prompt is also possible to be modified from the .my.cnf file, but the problem is that if I use prompt='master [\d]> ' I see it properly (not colored but I see what I'm expecting, while if I write prompt='\033[0;31mmaster\033[00m [\d]> ' it shows the string instead of "parsing" the \033[0;31m r\033[00m codes to actual colours. | ||||||||||||||||
| Comment by Jean Weisbuch [ 2015-02-08 ] | ||||||||||||||||
|
Allowing the input of complete color codes this way would require some more complex changes as the color codes have the default delimiter ";" on it and also because it only allow macros of one character as it parse only the next character after an antislash "\". I also dont think that it would make it easier to read and simpler to modify than my initial proposal but its only my point of view. | ||||||||||||||||
| Comment by Fabio Alessandro Locati [ 2015-02-10 ] | ||||||||||||||||
|
It's surely true your point, it will be easier with a "remap" of colours. At the moment IIRC, there are 256 colours available so the code would become pretty long if for each color 4 lines are added (that would be 1024 lines). So a way to put the colors directly from the input string to the output string could be line saving. At the end of the day, I'm more looking for the feature than the implementation itself. | ||||||||||||||||
| Comment by Jean Weisbuch [ 2015-02-11 ] | ||||||||||||||||
|
There are 8 main ANSI colors (including white and black) and the same 8 background colors : http://www.bluesock.org/~willg/dev/ansi.html Attributes such as bold/light, blinking or underline could be implemented as modifiers ; for example if \u was for underline, every color codes defined afterwise would be underlined and another \u or a \0 (a macro to unset all style attributes) would undefine the modifier. For example :
Would display :
| ||||||||||||||||
| Comment by Sergei Golubchik [ 2015-10-30 ] | ||||||||||||||||
|
One can easily do it now. I've just got my client to show
with this line in my .my.cnf:
That is, you can put ANSI sequences directly in the config file and they will work just fine. |