Details
-
Type:
Epic
-
Status: Open
-
Priority:
Major
-
Resolution: Unresolved
-
Fix Version/s: None
-
Component/s: None
-
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.
Gliffy Diagrams
Attachments
Issues in Epic
MDEV-7552
Colors in the shell
true
MDEV-7552
Colors in the shell
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
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 :
processed_prompt.append("localhost");By :
processed_prompt.append("\033[01;32mlocalhost\033[00m");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 :
case '0': /* print the following text in the default terminal color */ processed_prompt.append("\033[00m"); break; case '2': /* print the following text in green */ processed_prompt.append("\033[01;32m"); break; case '3': /* print the following text in yellow */ processed_prompt.append("\033[01;33m"); break;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 :
processed_prompt.append('\0');With :
processed_prompt.append("\033[00m\0");(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 MDEV-505 which is about adding the ability to display the actual server hostname instead of localhost when connecting to localhost/socket.