VSIDO Community

VSIDO Community => Media Room => Topic started by: Digit on September 28, 2013, 03:52:40 PM

Title: terminal colours
Post by: Digit on September 28, 2013, 03:52:40 PM
(yeah i said colours, not colors ~ brittish education)  ;)


here's a few ways (and please shout at me to add scrots of the lot):
nice one liner, 256:
Code: [Select]
(x=`tput op` y=`printf %76s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done)
perl, 256:
Code: [Select]
#!/usr/bin/perl
# Author: Todd Larason <jtl@molehill.org>
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $

# use the resources for colors 0-15 - usually more-or-less a
# reproduction of the standard ANSI colors, but possibly more
# pleasing shades

# colors 16-231 are a 6x6x6 color cube
for ($red = 0; $red < 6; $red++) {
    for ($green = 0; $green < 6; $green++) {
        for ($blue = 0; $blue < 6; $blue++) {
            printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\",
                   16 + ($red * 36) + ($green * 6) + $blue,
                   ($red ? ($red * 40 + 55) : 0),
                   ($green ? ($green * 40 + 55) : 0),
                   ($blue ? ($blue * 40 + 55) : 0));
        }
    }
}

# colors 232-255 are a grayscale ramp, intentionally leaving out
# black and white
for ($gray = 0; $gray < 24; $gray++) {
    $level = ($gray * 10) + 8;
    printf("\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\",
           232 + $gray, $level, $level, $level);
}


# display the colors

# first the system ones:
print "System colors:\n";
for ($color = 0; $color < 8; $color++) {
    print "\x1b[48;5;${color}m  ";
}
print "\x1b[0m\n";
for ($color = 8; $color < 16; $color++) {
    print "\x1b[48;5;${color}m  ";
}
print "\x1b[0m\n\n";

# now the color cube
print "Color cube, 6x6x6:\n";
for ($green = 0; $green < 6; $green++) {
    for ($red = 0; $red < 6; $red++) {
        for ($blue = 0; $blue < 6; $blue++) {
            $color = 16 + ($red * 36) + ($green * 6) + $blue;
            print "\x1b[48;5;${color}m  ";
        }
        print "\x1b[0m ";
    }
    print "\n";
}


# now the grayscale ramp
print "Grayscale ramp:\n";
for ($color = 232; $color < 256; $color++) {
    print "\x1b[48;5;${color}m  ";
}
print "\x1b[0m\n";

a nice classic graph:
Code: [Select]
#!/bin/bash
#
#   This file echoes a bunch of color codes to the
#   terminal to demonstrate what's available.  Each
#   line is the color code of one forground color,
#   out of 17 (default + 16 escapes), followed by a
#   test use of that color on all nine background
#   colors (default + 8 escapes).
#

T='TiP'   # The test text

echo -e "\n                 40m     41m     42m     43m\
     44m     45m     46m     47m";

for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
           '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
           '  36m' '1;36m' '  37m' '1;37m';
  do FG=${FGs// /}
  echo -en " $FGs \033[$FG  $T  "
  for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
    do echo -en "$EINS \033[$FG\033[$BG  $T  \033[0m";
  done
  echo;
done
echo


another nice classic graph:
Code: [Select]
#!/bin/bash
#
# Description:
#
#    Prints a color table of 8bg * 8fg * 2 states (regular/bold)
#
# Copyright:
#
#    (C) 2009 Wolfgang Frisch <xororand@unfoog.de>
#
# License:
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

echo
echo Table for 16-color terminal escape sequences.
echo Replace ESC with \\033 in bash.
echo
echo "Background | Foreground colors"
echo "---------------------------------------------------------------------"
for((bg=40;bg<=47;bg++)); do
        for((bold=0;bold<=1;bold++)) do
                echo -en "\033[0m"" ESC[${bg}m   | "
                for((fg=30;fg<=37;fg++)); do
                        if [ $bold == "0" ]; then
                                echo -en "\033[${bg}m\033[${fg}m [${fg}m  "
                        else
                                echo -en "\033[${bg}m\033[1;${fg}m [1;${fg}m"
                        fi
                done
                echo -e "\033[0m"
        done
        echo "--------------------------------------------------------------------- "
done

echo
echo

another 256 list:
Code: [Select]
#! /bin/bash
for i in {0..255} ; do
    printf "\x1b[38;5;${i}mcolour${i}\n"
done

a lua one, alegedly:
Code: [Select]
#!/usr/bin/env lua

function cl(e)
return string.format('\27[%sm', e)
end

function print_fg(bg, pre)
for fg = 30,37 do
fg = pre..fg
io.write(cl(bg), cl(fg), string.format(' %6s ', fg), cl(0))
end
end

for bg = 40,47 do
io.write(cl(0), ' ', bg, ' ')
print_fg(bg, ' ')
io.write('\n    ')
print_fg(bg, '1;')
io.write('\n\n')
end

ruby roo?!?
Code: [Select]
#!/usr/bin/env ruby
# coding: utf-8
 
# ANSI color scheme script
# Author: Ivaylo Kuzev < Ivo >
# Original: http://crunchbanglinux.org/forums/post/134749/#p134749
# Modified using Ruby.
 
CL = "\e[0m"
BO = "\e[1m"

R = "\e[31m"
G = "\e[32m"
Y = "\e[33m"
B = "\e[34m"
P = "\e[35m"
C = "\e[36m"
 
print <<EOF
 
#{BO}#{R}  ██████  #{CL} #{BO}#{G}██████  #{CL}#{BO}#{Y}   ██████#{CL} #{BO}#{B}██████ #{CL}  #{BO}#{P}  ██████#{CL} #{BO}#{C}  ███████#{CL}
#{BO}#{R}  ████████#{CL} #{BO}#{G}██    ██ #{CL}#{BO}#{Y}██ #{CL}      #{BO}#{B}██    ██#{CL} #{BO}#{P}██████ #{CL} #{BO}#{C} █████████#{CL}
#{R}  ██  ████#{CL} #{G}██  ████#{CL}#{Y} ████    #{CL} #{B}████  ██#{CL} #{P}████ #{CL}    #{C}█████ #{CL}
#{R}  ██    ██#{CL} #{G}██████ #{CL}#{Y}  ████████#{CL} #{B}██████ #{CL}  #{P}████████#{CL} #{C}██ #{CL}
 
EOF

anyone got more?
Title: Re: terminal colours
Post by: valroadie on October 06, 2013, 06:02:14 PM
Just wanted to add this in here.

Run a tput colors cmd in your terminal.

(http://s23.postimg.org/z0ex22flj/2013_10_06_130330_1280x800_scrot.jpg) (http://postimg.org/image/z0ex22flj/)

We are going to enable 256 colors in your terminal because hey, it's 2013!

sudo apt-get install ncurses-term

Then put this:

export TERM=xterm-256color

Into your ~/.bashrc  or  ~/.bash_profile file.

Then run tput colors again and see the magic happen! (Don't forget to close and restart your terminal for the changes to take effect.)

(http://s23.postimg.org/5ckuumd13/2013_10_06_130536_1280x800_scrot.jpg) (http://postimg.org/image/5ckuumd13/)

Happy coloring! You can then use Digits color tables up top to see the beauty!

(http://s21.postimg.org/7g40aikyr/2013_10_06_130649_1280x800_scrot.jpg) (http://postimg.org/image/7g40aikyr/)