Skip to content

Colorized prompt. #53

@mocallins

Description

@mocallins

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]] % "
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions