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

            There are no issues in this epic.

              Activity

              Hide
              jb-boin Jean Weisbuch added a comment - - edited

              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.

              Show
              jb-boin Jean Weisbuch added a comment - - edited 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.
              Hide
              fale Fabio Alessandro Locati added a comment -

              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.
              This I believe whould be the expected behaviour

              Show
              fale Fabio Alessandro Locati added a comment - 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. This I believe whould be the expected behaviour
              Hide
              jb-boin Jean Weisbuch added a comment -

              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.

              Show
              jb-boin Jean Weisbuch added a comment - 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.
              Hide
              fale Fabio Alessandro Locati added a comment -

              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.

              Show
              fale Fabio Alessandro Locati added a comment - 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.
              Hide
              jb-boin Jean Weisbuch added a comment -

              There are 8 main ANSI colors (including white and black) and the same 8 background colors : http://www.bluesock.org/~willg/dev/ansi.html
              Attributing 16 macros could become a bit tricky, using only the main colors as direct macros using numbers and using a modifier for setting the background color is also possible but would make it a bit less complicated for end user.

              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 :

              prompt \u\2\N\0 \h [\3\d\0]>

              Would display :

              MariaDB localhost [(none)]>

              Show
              jb-boin Jean Weisbuch added a comment - There are 8 main ANSI colors (including white and black) and the same 8 background colors : http://www.bluesock.org/~willg/dev/ansi.html Attributing 16 macros could become a bit tricky, using only the main colors as direct macros using numbers and using a modifier for setting the background color is also possible but would make it a bit less complicated for end user. 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 : prompt \u\2\N\0 \h [\3\d\0]> Would display : MariaDB localhost [ (none) ]>

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  fale Fabio Alessandro Locati
                • Votes:
                  1 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated: