Simple Colors?

Cameron Simpson cs at cskk.id.au
Tue Feb 25 01:24:36 UTC 2020


On 24Feb2020 15:43, Paul Gilmartin <PaulGBoulder at AIM.COM> wrote:
>On 2020-02-24, at 14:40:52, Cameron Simpson wrote:
>> On 24Feb2020 13:55, Paul Gilmartin wrote:
>>> With my failing eyes, I'd like everything high contrast,
>>> mostly black on white.
>>
>> What's the natural colour scheme of your terminal?
>>
>Foreground black; background white.
>
>>> When I do in .mutt/muttrc
>>> color normal	black white
>>> ... I seem to get black on gray.
>>
>> Odd. What about other colours than "white", as a test?
>>
>E.g. brightyellow works.  brightwhite is whiter than white,
>but still somewhat gray.  Is there something like #FFF?
>Is there a "realwhite"?
>>> When I do:
>>> color normal	white black
>>> ... I get white (or maybe gray) on black.
>>
>> What if you switch out "white" for "default"?
>>
>Ah!  "color normal    default default" works.  "default" is
>whiter than white.  Who woulda thunk it.
>
>Where should I have found this in the Ref.?

Maybe nowhere, though it could probably use some discussion there.

The colours are requested with escape sequences and the colour displayed 
are thus dependent on your terminal emulator; the names "white" etc map 
to a palette. So you want to start with the settings in your terminal 
emulator.

For reference, here are some colours from my ancient ANSI colour python 
module, where you can see 0, 7, 4 etc embedded.

    # the known colour names and their escape sequences
    COLOURS = {
        'normal': '\033[0m',
        'reverse': '\033[7m',
        'underline': '\033[4m',
        'bold': '\033[1m',
        'black': '\033[30m',
        'red': '\033[31m',
        'green': '\033[32m',
        'yellow': '\033[33m',
        'blue': '\033[34m',
        'magenta': '\033[35m',
        'cyan': '\033[36m',
        'white': '\033[37m',
    }

That palette used to be about 8 colours, then there were terminals with 
256 colours (eg support from things like xterm-256) and maybe there's an 
arbitrary #RGB format these days.

I also attach my script "colour_echo" and the "with-colour" script it 
calls. Usage:

    colour_echo white message...

which you might use to fiddle around with the standard colour names to 
see what your terminal produces.

I'd be happy to be further educated about modern colour escape 
sequences.

Cheers,
Cameron Simpson <cs at cskk.id.au>
-------------- next part --------------
#!/bin/sh
#
# Perform command with output in particular colour.
# - Cameron Simpson <cs at cskk.id.au> 08jul2007
#

set -ue

: ${WITH_COLOUR_ON:=''}

cmd=$0
usage="Usage: $cmd colour command [args...]"

badopts=

if [ $# = 0 ]
then
  echo "$cmd: missing colour" >&2
  badopts=1
else
  colour=$1
  shift

  if [ $# = 0 ]
  then
    echo "$cmd: missing command" >&2
    badopts=1
  fi
fi

[ $badopts ] && { echo "$usage" >&2; exit 2; }

exec 3>&2 2>/dev/null
on= off=
case $colour in
  normal)   on= ;;
  bold)     on=`tput bold`&& off=`tput sgr0` ;;
  reverse)  on=`tput rev` && off=`tput sgr0` ;;
  standout) on=`tput smso` && off=`tput rmso` ;;
  it|italic)on=`tput sitm` && off=`tput ritm` ;;
  ul|underline)
            on=`tput smul` && off=`tput rmul` ;;
  sl|status)on=`tput tsl` && off=`tput fsl` ;;
  black)    on=`tput setaf 0 || tput setaf 0 0 0 || tput setf 0` ;;
  red)      on=`tput setaf 1 || tput setaf 1 0 0 || tput setf 4` ;;
  green)    on=`tput setaf 2 || tput setaf 2 0 0 || tput setf 2` ;;
  yellow)   on=`tput setaf 3 || tput setaf 3 0 0 || tput setf 6` ;;
  blue)     on=`tput setaf 4 || tput setaf 4 0 0 || tput setf 1` ;;
  magenta)  on=`tput setaf 5 || tput setaf 5 0 0 || tput setf 5` ;;
  cyan)     on=`tput setaf 6 || tput setaf 6 0 0 || tput setf 3` ;;
  white)    on=`tput setaf 7 || tput setaf 7 0 0 || tput setf 7` ;;
  *)        echo "$cmd: warning: unsupported colour: $colour" >&2 ;;
esac || on=
exec 2>&3 3>&-

# no "on" sequence? just run the command
[ -n "$on" ] || exec "$@"
# no "off"? restore original colour pair
[ -n "$off" ] || off=`tput op`

xit=0
printf "%s" "$on"
env "WITH_COLOUR_ON=$on" "$@" || xit=$?
printf "%s%s" "$off$WITH_COLOUR_ON"
exit $xit
-------------- next part --------------
#!/bin/sh
#
# Echo in colour.       - Cameron Simpson <cs at cskk.id.au>
#

set -ue

cmd=$0
usage="Usage: $cmd [-n] colour message..."

badopts=

echo=echo

while [ $# -gt 0 ]
do
  case $1 in
    -n)	echo=necho; shift ;;
    --) shift; break ;;
    -?*)echo "$cmd: unrecognised option: $1" >&2
        badopts=1
        ;;
    *)	break ;;
  esac
  shift
done

if [ $# = 0 ]
then
  echo "$cmd: missing colour" >&2
  badopts=1
else
  colour=$1
  shift
fi

[ $badopts ] && { echo "$usage" >&2; exit 2; }

exec with-colour "$colour" "$echo" ${1+"$@"}


More information about the Mutt-users mailing list