Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorized prompt. #53

Open
mocallins opened this issue Oct 8, 2023 · 0 comments
Open

Colorized prompt. #53

mocallins opened this issue Oct 8, 2023 · 0 comments

Comments

@mocallins
Copy link

I've got a possible enhancement for inclusion, colorozed prompts.

The code is not fully fleshed out, (i.e. all the possible combination based on *nix color codes),
but is basically layed out for them.

In tclreadlineSetup.tcl:

     proc color {{clor {}}} {

      set colors {Black Red Green Yellow Blue Purple Cyan White}

      set pre ""
      set colr ""
      regexp -nocase -- "^(\\w*)([join $colors {|}])$" $clor - pre colr


      if {$colr != ""} {
          set idx [lsearch -regexp -nocase $colors $colr]
      }

      set sep ";"

      switch -regexp -nocase -- {$pre} {
          {^b$} {
#        Bold {\e[1;30m}
              set mod 1
              incr idx 30
          }
          {^U$} {
#        Underline {\e[4;30m}
              incr idx 30
              set mod 4
          }
          {^bg$} {
#        Background {\e[40m}
              incr idx 40
              set mod ""
              set sep ""
          }
          {^i$} {
      #  high Intensity {\e[0;90m}
              incr idx 90
              set mod 0
          }
          {^bi$} {
      #  Bold high Intensity   {\e[1;90m}
              incr idx 90
              set mod 1
          }
          {^bgi$} {
      #  BackGround high Intensity   {\e[0;100m}
              incr idx 100
              set mod 0
          }
          {} {
#         Regular color {\e[0;30m}
              if {$colr == ""} {
                  set sep ""
                  set idx ""
                  set mod ""
              } else {
                  incr idx 30
                  set mod 0
              }
          }
      }

     return "\033\[${mod}${sep}${idx}m"

#      return "\033\[1;${idx}m"
    }

    proc colorStr {str {colr {}}} {
      return "[color $colr]$str[color]"
    }

And I used it thus, in tclshrc.tcl,

    proc ::tclreadline::prompt1 {} {
          return "\[ [::tclreadline::colorStr [lindex [split [info hostname] "."] 0] cyan] \] [eval file join [lrange [split [pwd] "/"] end-1 end]] % "
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant