Print a 256-color test pattern in the terminal











up vote
51
down vote

favorite
29












How do I print a 256-colour test pattern in my terminal?



I want to check that my terminal correctly supports 256 colours.










share|improve this question
























  • type /cubes in irssi (source)
    – mirabilos
    Sep 6 '16 at 19:01















up vote
51
down vote

favorite
29












How do I print a 256-colour test pattern in my terminal?



I want to check that my terminal correctly supports 256 colours.










share|improve this question
























  • type /cubes in irssi (source)
    – mirabilos
    Sep 6 '16 at 19:01













up vote
51
down vote

favorite
29









up vote
51
down vote

favorite
29






29





How do I print a 256-colour test pattern in my terminal?



I want to check that my terminal correctly supports 256 colours.










share|improve this question















How do I print a 256-colour test pattern in my terminal?



I want to check that my terminal correctly supports 256 colours.







command-line colors






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 7 '16 at 5:01









Anwar

55.6k22143252




55.6k22143252










asked Sep 5 '16 at 9:32









Tom Hale

1,42921027




1,42921027












  • type /cubes in irssi (source)
    – mirabilos
    Sep 6 '16 at 19:01


















  • type /cubes in irssi (source)
    – mirabilos
    Sep 6 '16 at 19:01
















type /cubes in irssi (source)
– mirabilos
Sep 6 '16 at 19:01




type /cubes in irssi (source)
– mirabilos
Sep 6 '16 at 19:01










5 Answers
5






active

oldest

votes

















up vote
77
down vote



accepted










256-colour test pattern



To get the below image, use:



curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash


256-colour test pattern



The gist bash/zsh code is shellcheck clean, and also supports "Look Ma, no subprocesses!".





Alternatively, for a bash quicky:



for i in {0..255} ; do
printf "x1b[48;5;%sm%3de[0m " "$i" "$i"
if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
printf "n";
fi
done


For total overkill, the granddaddy of the lot is terminal-colors, a 572-line script with multiple output formats.



You can also print a true color (24-bit) test pattern.






share|improve this answer



















  • 6




    I like your comment on the grayscale on the scripts GitHub page - "#Not 50, but 24 Shades of Grey"
    – MadisonCooper
    Sep 6 '16 at 13:47












  • Here's another 24-bit color test: gist.github.com/lifepillar/09a44b8cf0f9397465614e622979107f
    – masterxilo
    Dec 5 at 18:20










  • To run terminal-colors, do curl -s https://raw.githubusercontent.com/eikenb/terminal-colors/master/terminal-colors | python
    – masterxilo
    Dec 5 at 18:22










  • @masterxilo what is terminal-colors and how does it compare to the options I suggested?
    – Tom Hale
    Dec 11 at 1:22




















up vote
31
down vote













I found a nice Python script for that on GitHub written by Justin Abrahms which also prints the hex codes of the colours.



Download the script to current working directory



wget https://gist.githubusercontent.com/justinabrahms/1047767/raw/a79218b6ca8c1c04856968d2d202510a4f7ec215/colortest.py


give it execute permission



chmod +x colortest.py


Run it:



./colortest.py




Here's the script in full in case of link-rot:



#!/usr/bin/env python
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349

print "Color indexes should be drawn in bold text of the same color."
print

colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
colored_palette = [
"%02x/%02x/%02x" % (r, g, b)
for r in colored
for g in colored
for b in colored
]

grayscale = [0x08 + 10 * n for n in range(0, 24)]
grayscale_palette = [
"%02x/%02x/%02x" % (a, a, a)
for a in grayscale
]

normal = "33[38;5;%sm"
bold = "33[1;38;5;%sm"
reset = "33[0m"

for (i, color) in enumerate(colored_palette + grayscale_palette, 16):
index = (bold + "%4s" + reset) % (i, str(i) + ':')
hex = (normal + "%s" + reset) % (i, color)
newline = 'n' if i % 6 == 3 else ''
print index, hex, newline,





share|improve this answer






























    up vote
    8
    down vote













    While not quite a "test pattern", I have xterm-color-chooser:



    screenshot






    share|improve this answer





















    • curl -s https://raw.githubusercontent.com/grawity/code/master/term/xterm-color-chooser | python3
      – masterxilo
      Dec 5 at 18:24


















    up vote
    4
    down vote













    Yet another script, written by me, is located in the VTE repository: https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38.



    It requires a window of 120-ish or more columns, but arranges the colors of the 6x6x6 cube nicely and compactly. The first digits of the indices are stripped for compactness, you can easily figure them out. The vertical bars provide you the ability to examine the exact RGB of the foreground color without antialiasing kicking in (as it does at the digits).



    The top of the output (not shown in the screenshot below) demonstrates the craziness that goes around with the bold vs. bright ambiguity, namely that the boldness escape sequence combined with one of the legacy 8 colors' escape sequence for the foreground also switches to the bright counterpart color, whereas with the new style (256-color capable) escape sequences this is no longer the case, not even for the first 8 colors. At least that's how xterm and VTE (GNOME Terminal etc.) behave.



    This screenshot shows about half of the output:



    Output of 256test.sh in GNOME Terminal






    share|improve this answer





















    • curl -s -L https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38 | bash
      – masterxilo
      Dec 5 at 18:25


















    up vote
    3
    down vote













    Perhaps superfluous but I've written a version that prints the 256 colors using the background with automatic shell width detection so the colors are more easily visible.



    https://gist.github.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3



    256 color test demo



    #!/usr/bin/env python
    from __future__ import print_function

    import os
    import shutil
    import subprocess


    def get_width(default=80):
    '''Attempt to detect console width and default to 80'''
    try:
    columns, rows = shutil.get_terminal_size()
    except AttributeError:
    try:
    _, columns = subprocess.check_output(['stty', 'size']).split()
    except OSError:
    columns = os.environ.get('COLUMNS', default)

    columns = int(columns) - 77
    # Since we have 6 columns with 1 space on each side, we can increment the
    # size for every 12 extra columns
    return max(0, columns / 12)


    # Loosely based on https://gist.github.com/justinabrahms/1047767
    colored = [0] + list(range(95, 256, 40))
    colored_palette = [
    (r, g, b)
    for r in colored
    for g in colored
    for b in colored
    ]


    grayscale_palette = [(g, g, g) for g in range(8, 240, 10)]


    esc = '33['
    # Reset all colors sequence
    reset = esc + '0m'
    # Regular color
    normal = esc + '38;5;{i}m'
    # Bold color
    bold = esc + '1;' + normal
    # Background color
    background = esc + '48;5;{i}m'

    pattern = (
    '{normal}{background}{padding:^{width}}{i:^3d} ' # pad the background
    '{r:02X}/{g:02X}/{b:02X}' # show the hex rgb code
    '{padding:^{width}}' # pad the background on the other side
    '{reset}' # reset again
    )

    base_context = dict(reset=reset, padding='', width=get_width())

    for i, (r, g, b) in enumerate(colored_palette + grayscale_palette, 16):
    context = dict(i=i, r=r, g=g, b=b, color=r + g + b, **base_context)
    context.update(bold=bold.format(**context))
    context.update(background=background.format(**context))

    # Change text color from black to white when it might become unreadable
    if max(r, g, b) > 0xCC:
    context.update(normal=normal.format(i=0))
    else:
    context.update(normal=normal.format(i=255))

    print(pattern.format(**context), end='')

    # Print newlines when needed
    if i % 6 == 3:
    print()
    else:
    print(' ', end='')





    share|improve this answer

















    • 2




      If anyone wants to run this script in a one liner, run curl https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/250eb2e3f2acca1c51aa52adf611ec0380291e8a/colortest.py | python3
      – Tommaso Thea Cioni
      Jul 26 at 17:21












    • I suggest curl -s https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/colortest.py | python3
      – masterxilo
      Dec 5 at 18:27











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f821157%2fprint-a-256-color-test-pattern-in-the-terminal%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    77
    down vote



    accepted










    256-colour test pattern



    To get the below image, use:



    curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash


    256-colour test pattern



    The gist bash/zsh code is shellcheck clean, and also supports "Look Ma, no subprocesses!".





    Alternatively, for a bash quicky:



    for i in {0..255} ; do
    printf "x1b[48;5;%sm%3de[0m " "$i" "$i"
    if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
    printf "n";
    fi
    done


    For total overkill, the granddaddy of the lot is terminal-colors, a 572-line script with multiple output formats.



    You can also print a true color (24-bit) test pattern.






    share|improve this answer



















    • 6




      I like your comment on the grayscale on the scripts GitHub page - "#Not 50, but 24 Shades of Grey"
      – MadisonCooper
      Sep 6 '16 at 13:47












    • Here's another 24-bit color test: gist.github.com/lifepillar/09a44b8cf0f9397465614e622979107f
      – masterxilo
      Dec 5 at 18:20










    • To run terminal-colors, do curl -s https://raw.githubusercontent.com/eikenb/terminal-colors/master/terminal-colors | python
      – masterxilo
      Dec 5 at 18:22










    • @masterxilo what is terminal-colors and how does it compare to the options I suggested?
      – Tom Hale
      Dec 11 at 1:22

















    up vote
    77
    down vote



    accepted










    256-colour test pattern



    To get the below image, use:



    curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash


    256-colour test pattern



    The gist bash/zsh code is shellcheck clean, and also supports "Look Ma, no subprocesses!".





    Alternatively, for a bash quicky:



    for i in {0..255} ; do
    printf "x1b[48;5;%sm%3de[0m " "$i" "$i"
    if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
    printf "n";
    fi
    done


    For total overkill, the granddaddy of the lot is terminal-colors, a 572-line script with multiple output formats.



    You can also print a true color (24-bit) test pattern.






    share|improve this answer



















    • 6




      I like your comment on the grayscale on the scripts GitHub page - "#Not 50, but 24 Shades of Grey"
      – MadisonCooper
      Sep 6 '16 at 13:47












    • Here's another 24-bit color test: gist.github.com/lifepillar/09a44b8cf0f9397465614e622979107f
      – masterxilo
      Dec 5 at 18:20










    • To run terminal-colors, do curl -s https://raw.githubusercontent.com/eikenb/terminal-colors/master/terminal-colors | python
      – masterxilo
      Dec 5 at 18:22










    • @masterxilo what is terminal-colors and how does it compare to the options I suggested?
      – Tom Hale
      Dec 11 at 1:22















    up vote
    77
    down vote



    accepted







    up vote
    77
    down vote



    accepted






    256-colour test pattern



    To get the below image, use:



    curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash


    256-colour test pattern



    The gist bash/zsh code is shellcheck clean, and also supports "Look Ma, no subprocesses!".





    Alternatively, for a bash quicky:



    for i in {0..255} ; do
    printf "x1b[48;5;%sm%3de[0m " "$i" "$i"
    if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
    printf "n";
    fi
    done


    For total overkill, the granddaddy of the lot is terminal-colors, a 572-line script with multiple output formats.



    You can also print a true color (24-bit) test pattern.






    share|improve this answer














    256-colour test pattern



    To get the below image, use:



    curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash


    256-colour test pattern



    The gist bash/zsh code is shellcheck clean, and also supports "Look Ma, no subprocesses!".





    Alternatively, for a bash quicky:



    for i in {0..255} ; do
    printf "x1b[48;5;%sm%3de[0m " "$i" "$i"
    if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
    printf "n";
    fi
    done


    For total overkill, the granddaddy of the lot is terminal-colors, a 572-line script with multiple output formats.



    You can also print a true color (24-bit) test pattern.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 11 at 1:21

























    answered Sep 5 '16 at 9:42









    Tom Hale

    1,42921027




    1,42921027








    • 6




      I like your comment on the grayscale on the scripts GitHub page - "#Not 50, but 24 Shades of Grey"
      – MadisonCooper
      Sep 6 '16 at 13:47












    • Here's another 24-bit color test: gist.github.com/lifepillar/09a44b8cf0f9397465614e622979107f
      – masterxilo
      Dec 5 at 18:20










    • To run terminal-colors, do curl -s https://raw.githubusercontent.com/eikenb/terminal-colors/master/terminal-colors | python
      – masterxilo
      Dec 5 at 18:22










    • @masterxilo what is terminal-colors and how does it compare to the options I suggested?
      – Tom Hale
      Dec 11 at 1:22
















    • 6




      I like your comment on the grayscale on the scripts GitHub page - "#Not 50, but 24 Shades of Grey"
      – MadisonCooper
      Sep 6 '16 at 13:47












    • Here's another 24-bit color test: gist.github.com/lifepillar/09a44b8cf0f9397465614e622979107f
      – masterxilo
      Dec 5 at 18:20










    • To run terminal-colors, do curl -s https://raw.githubusercontent.com/eikenb/terminal-colors/master/terminal-colors | python
      – masterxilo
      Dec 5 at 18:22










    • @masterxilo what is terminal-colors and how does it compare to the options I suggested?
      – Tom Hale
      Dec 11 at 1:22










    6




    6




    I like your comment on the grayscale on the scripts GitHub page - "#Not 50, but 24 Shades of Grey"
    – MadisonCooper
    Sep 6 '16 at 13:47






    I like your comment on the grayscale on the scripts GitHub page - "#Not 50, but 24 Shades of Grey"
    – MadisonCooper
    Sep 6 '16 at 13:47














    Here's another 24-bit color test: gist.github.com/lifepillar/09a44b8cf0f9397465614e622979107f
    – masterxilo
    Dec 5 at 18:20




    Here's another 24-bit color test: gist.github.com/lifepillar/09a44b8cf0f9397465614e622979107f
    – masterxilo
    Dec 5 at 18:20












    To run terminal-colors, do curl -s https://raw.githubusercontent.com/eikenb/terminal-colors/master/terminal-colors | python
    – masterxilo
    Dec 5 at 18:22




    To run terminal-colors, do curl -s https://raw.githubusercontent.com/eikenb/terminal-colors/master/terminal-colors | python
    – masterxilo
    Dec 5 at 18:22












    @masterxilo what is terminal-colors and how does it compare to the options I suggested?
    – Tom Hale
    Dec 11 at 1:22






    @masterxilo what is terminal-colors and how does it compare to the options I suggested?
    – Tom Hale
    Dec 11 at 1:22














    up vote
    31
    down vote













    I found a nice Python script for that on GitHub written by Justin Abrahms which also prints the hex codes of the colours.



    Download the script to current working directory



    wget https://gist.githubusercontent.com/justinabrahms/1047767/raw/a79218b6ca8c1c04856968d2d202510a4f7ec215/colortest.py


    give it execute permission



    chmod +x colortest.py


    Run it:



    ./colortest.py




    Here's the script in full in case of link-rot:



    #!/usr/bin/env python
    # Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349

    print "Color indexes should be drawn in bold text of the same color."
    print

    colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
    colored_palette = [
    "%02x/%02x/%02x" % (r, g, b)
    for r in colored
    for g in colored
    for b in colored
    ]

    grayscale = [0x08 + 10 * n for n in range(0, 24)]
    grayscale_palette = [
    "%02x/%02x/%02x" % (a, a, a)
    for a in grayscale
    ]

    normal = "33[38;5;%sm"
    bold = "33[1;38;5;%sm"
    reset = "33[0m"

    for (i, color) in enumerate(colored_palette + grayscale_palette, 16):
    index = (bold + "%4s" + reset) % (i, str(i) + ':')
    hex = (normal + "%s" + reset) % (i, color)
    newline = 'n' if i % 6 == 3 else ''
    print index, hex, newline,





    share|improve this answer



























      up vote
      31
      down vote













      I found a nice Python script for that on GitHub written by Justin Abrahms which also prints the hex codes of the colours.



      Download the script to current working directory



      wget https://gist.githubusercontent.com/justinabrahms/1047767/raw/a79218b6ca8c1c04856968d2d202510a4f7ec215/colortest.py


      give it execute permission



      chmod +x colortest.py


      Run it:



      ./colortest.py




      Here's the script in full in case of link-rot:



      #!/usr/bin/env python
      # Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349

      print "Color indexes should be drawn in bold text of the same color."
      print

      colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
      colored_palette = [
      "%02x/%02x/%02x" % (r, g, b)
      for r in colored
      for g in colored
      for b in colored
      ]

      grayscale = [0x08 + 10 * n for n in range(0, 24)]
      grayscale_palette = [
      "%02x/%02x/%02x" % (a, a, a)
      for a in grayscale
      ]

      normal = "33[38;5;%sm"
      bold = "33[1;38;5;%sm"
      reset = "33[0m"

      for (i, color) in enumerate(colored_palette + grayscale_palette, 16):
      index = (bold + "%4s" + reset) % (i, str(i) + ':')
      hex = (normal + "%s" + reset) % (i, color)
      newline = 'n' if i % 6 == 3 else ''
      print index, hex, newline,





      share|improve this answer

























        up vote
        31
        down vote










        up vote
        31
        down vote









        I found a nice Python script for that on GitHub written by Justin Abrahms which also prints the hex codes of the colours.



        Download the script to current working directory



        wget https://gist.githubusercontent.com/justinabrahms/1047767/raw/a79218b6ca8c1c04856968d2d202510a4f7ec215/colortest.py


        give it execute permission



        chmod +x colortest.py


        Run it:



        ./colortest.py




        Here's the script in full in case of link-rot:



        #!/usr/bin/env python
        # Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349

        print "Color indexes should be drawn in bold text of the same color."
        print

        colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
        colored_palette = [
        "%02x/%02x/%02x" % (r, g, b)
        for r in colored
        for g in colored
        for b in colored
        ]

        grayscale = [0x08 + 10 * n for n in range(0, 24)]
        grayscale_palette = [
        "%02x/%02x/%02x" % (a, a, a)
        for a in grayscale
        ]

        normal = "33[38;5;%sm"
        bold = "33[1;38;5;%sm"
        reset = "33[0m"

        for (i, color) in enumerate(colored_palette + grayscale_palette, 16):
        index = (bold + "%4s" + reset) % (i, str(i) + ':')
        hex = (normal + "%s" + reset) % (i, color)
        newline = 'n' if i % 6 == 3 else ''
        print index, hex, newline,





        share|improve this answer














        I found a nice Python script for that on GitHub written by Justin Abrahms which also prints the hex codes of the colours.



        Download the script to current working directory



        wget https://gist.githubusercontent.com/justinabrahms/1047767/raw/a79218b6ca8c1c04856968d2d202510a4f7ec215/colortest.py


        give it execute permission



        chmod +x colortest.py


        Run it:



        ./colortest.py




        Here's the script in full in case of link-rot:



        #!/usr/bin/env python
        # Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349

        print "Color indexes should be drawn in bold text of the same color."
        print

        colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
        colored_palette = [
        "%02x/%02x/%02x" % (r, g, b)
        for r in colored
        for g in colored
        for b in colored
        ]

        grayscale = [0x08 + 10 * n for n in range(0, 24)]
        grayscale_palette = [
        "%02x/%02x/%02x" % (a, a, a)
        for a in grayscale
        ]

        normal = "33[38;5;%sm"
        bold = "33[1;38;5;%sm"
        reset = "33[0m"

        for (i, color) in enumerate(colored_palette + grayscale_palette, 16):
        index = (bold + "%4s" + reset) % (i, str(i) + ':')
        hex = (normal + "%s" + reset) % (i, color)
        newline = 'n' if i % 6 == 3 else ''
        print index, hex, newline,






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 5 '16 at 18:52

























        answered Sep 5 '16 at 9:39









        Zanna

        49.4k13128236




        49.4k13128236






















            up vote
            8
            down vote













            While not quite a "test pattern", I have xterm-color-chooser:



            screenshot






            share|improve this answer





















            • curl -s https://raw.githubusercontent.com/grawity/code/master/term/xterm-color-chooser | python3
              – masterxilo
              Dec 5 at 18:24















            up vote
            8
            down vote













            While not quite a "test pattern", I have xterm-color-chooser:



            screenshot






            share|improve this answer





















            • curl -s https://raw.githubusercontent.com/grawity/code/master/term/xterm-color-chooser | python3
              – masterxilo
              Dec 5 at 18:24













            up vote
            8
            down vote










            up vote
            8
            down vote









            While not quite a "test pattern", I have xterm-color-chooser:



            screenshot






            share|improve this answer












            While not quite a "test pattern", I have xterm-color-chooser:



            screenshot







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 6 '16 at 12:04









            grawity

            31318




            31318












            • curl -s https://raw.githubusercontent.com/grawity/code/master/term/xterm-color-chooser | python3
              – masterxilo
              Dec 5 at 18:24


















            • curl -s https://raw.githubusercontent.com/grawity/code/master/term/xterm-color-chooser | python3
              – masterxilo
              Dec 5 at 18:24
















            curl -s https://raw.githubusercontent.com/grawity/code/master/term/xterm-color-chooser | python3
            – masterxilo
            Dec 5 at 18:24




            curl -s https://raw.githubusercontent.com/grawity/code/master/term/xterm-color-chooser | python3
            – masterxilo
            Dec 5 at 18:24










            up vote
            4
            down vote













            Yet another script, written by me, is located in the VTE repository: https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38.



            It requires a window of 120-ish or more columns, but arranges the colors of the 6x6x6 cube nicely and compactly. The first digits of the indices are stripped for compactness, you can easily figure them out. The vertical bars provide you the ability to examine the exact RGB of the foreground color without antialiasing kicking in (as it does at the digits).



            The top of the output (not shown in the screenshot below) demonstrates the craziness that goes around with the bold vs. bright ambiguity, namely that the boldness escape sequence combined with one of the legacy 8 colors' escape sequence for the foreground also switches to the bright counterpart color, whereas with the new style (256-color capable) escape sequences this is no longer the case, not even for the first 8 colors. At least that's how xterm and VTE (GNOME Terminal etc.) behave.



            This screenshot shows about half of the output:



            Output of 256test.sh in GNOME Terminal






            share|improve this answer





















            • curl -s -L https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38 | bash
              – masterxilo
              Dec 5 at 18:25















            up vote
            4
            down vote













            Yet another script, written by me, is located in the VTE repository: https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38.



            It requires a window of 120-ish or more columns, but arranges the colors of the 6x6x6 cube nicely and compactly. The first digits of the indices are stripped for compactness, you can easily figure them out. The vertical bars provide you the ability to examine the exact RGB of the foreground color without antialiasing kicking in (as it does at the digits).



            The top of the output (not shown in the screenshot below) demonstrates the craziness that goes around with the bold vs. bright ambiguity, namely that the boldness escape sequence combined with one of the legacy 8 colors' escape sequence for the foreground also switches to the bright counterpart color, whereas with the new style (256-color capable) escape sequences this is no longer the case, not even for the first 8 colors. At least that's how xterm and VTE (GNOME Terminal etc.) behave.



            This screenshot shows about half of the output:



            Output of 256test.sh in GNOME Terminal






            share|improve this answer





















            • curl -s -L https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38 | bash
              – masterxilo
              Dec 5 at 18:25













            up vote
            4
            down vote










            up vote
            4
            down vote









            Yet another script, written by me, is located in the VTE repository: https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38.



            It requires a window of 120-ish or more columns, but arranges the colors of the 6x6x6 cube nicely and compactly. The first digits of the indices are stripped for compactness, you can easily figure them out. The vertical bars provide you the ability to examine the exact RGB of the foreground color without antialiasing kicking in (as it does at the digits).



            The top of the output (not shown in the screenshot below) demonstrates the craziness that goes around with the bold vs. bright ambiguity, namely that the boldness escape sequence combined with one of the legacy 8 colors' escape sequence for the foreground also switches to the bright counterpart color, whereas with the new style (256-color capable) escape sequences this is no longer the case, not even for the first 8 colors. At least that's how xterm and VTE (GNOME Terminal etc.) behave.



            This screenshot shows about half of the output:



            Output of 256test.sh in GNOME Terminal






            share|improve this answer












            Yet another script, written by me, is located in the VTE repository: https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38.



            It requires a window of 120-ish or more columns, but arranges the colors of the 6x6x6 cube nicely and compactly. The first digits of the indices are stripped for compactness, you can easily figure them out. The vertical bars provide you the ability to examine the exact RGB of the foreground color without antialiasing kicking in (as it does at the digits).



            The top of the output (not shown in the screenshot below) demonstrates the craziness that goes around with the bold vs. bright ambiguity, namely that the boldness escape sequence combined with one of the legacy 8 colors' escape sequence for the foreground also switches to the bright counterpart color, whereas with the new style (256-color capable) escape sequences this is no longer the case, not even for the first 8 colors. At least that's how xterm and VTE (GNOME Terminal etc.) behave.



            This screenshot shows about half of the output:



            Output of 256test.sh in GNOME Terminal







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 22 '16 at 20:50









            egmont

            3,7211922




            3,7211922












            • curl -s -L https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38 | bash
              – masterxilo
              Dec 5 at 18:25


















            • curl -s -L https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38 | bash
              – masterxilo
              Dec 5 at 18:25
















            curl -s -L https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38 | bash
            – masterxilo
            Dec 5 at 18:25




            curl -s -L https://git.gnome.org/browse/vte/plain/perf/256test.sh?h=vte-0-38 | bash
            – masterxilo
            Dec 5 at 18:25










            up vote
            3
            down vote













            Perhaps superfluous but I've written a version that prints the 256 colors using the background with automatic shell width detection so the colors are more easily visible.



            https://gist.github.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3



            256 color test demo



            #!/usr/bin/env python
            from __future__ import print_function

            import os
            import shutil
            import subprocess


            def get_width(default=80):
            '''Attempt to detect console width and default to 80'''
            try:
            columns, rows = shutil.get_terminal_size()
            except AttributeError:
            try:
            _, columns = subprocess.check_output(['stty', 'size']).split()
            except OSError:
            columns = os.environ.get('COLUMNS', default)

            columns = int(columns) - 77
            # Since we have 6 columns with 1 space on each side, we can increment the
            # size for every 12 extra columns
            return max(0, columns / 12)


            # Loosely based on https://gist.github.com/justinabrahms/1047767
            colored = [0] + list(range(95, 256, 40))
            colored_palette = [
            (r, g, b)
            for r in colored
            for g in colored
            for b in colored
            ]


            grayscale_palette = [(g, g, g) for g in range(8, 240, 10)]


            esc = '33['
            # Reset all colors sequence
            reset = esc + '0m'
            # Regular color
            normal = esc + '38;5;{i}m'
            # Bold color
            bold = esc + '1;' + normal
            # Background color
            background = esc + '48;5;{i}m'

            pattern = (
            '{normal}{background}{padding:^{width}}{i:^3d} ' # pad the background
            '{r:02X}/{g:02X}/{b:02X}' # show the hex rgb code
            '{padding:^{width}}' # pad the background on the other side
            '{reset}' # reset again
            )

            base_context = dict(reset=reset, padding='', width=get_width())

            for i, (r, g, b) in enumerate(colored_palette + grayscale_palette, 16):
            context = dict(i=i, r=r, g=g, b=b, color=r + g + b, **base_context)
            context.update(bold=bold.format(**context))
            context.update(background=background.format(**context))

            # Change text color from black to white when it might become unreadable
            if max(r, g, b) > 0xCC:
            context.update(normal=normal.format(i=0))
            else:
            context.update(normal=normal.format(i=255))

            print(pattern.format(**context), end='')

            # Print newlines when needed
            if i % 6 == 3:
            print()
            else:
            print(' ', end='')





            share|improve this answer

















            • 2




              If anyone wants to run this script in a one liner, run curl https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/250eb2e3f2acca1c51aa52adf611ec0380291e8a/colortest.py | python3
              – Tommaso Thea Cioni
              Jul 26 at 17:21












            • I suggest curl -s https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/colortest.py | python3
              – masterxilo
              Dec 5 at 18:27















            up vote
            3
            down vote













            Perhaps superfluous but I've written a version that prints the 256 colors using the background with automatic shell width detection so the colors are more easily visible.



            https://gist.github.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3



            256 color test demo



            #!/usr/bin/env python
            from __future__ import print_function

            import os
            import shutil
            import subprocess


            def get_width(default=80):
            '''Attempt to detect console width and default to 80'''
            try:
            columns, rows = shutil.get_terminal_size()
            except AttributeError:
            try:
            _, columns = subprocess.check_output(['stty', 'size']).split()
            except OSError:
            columns = os.environ.get('COLUMNS', default)

            columns = int(columns) - 77
            # Since we have 6 columns with 1 space on each side, we can increment the
            # size for every 12 extra columns
            return max(0, columns / 12)


            # Loosely based on https://gist.github.com/justinabrahms/1047767
            colored = [0] + list(range(95, 256, 40))
            colored_palette = [
            (r, g, b)
            for r in colored
            for g in colored
            for b in colored
            ]


            grayscale_palette = [(g, g, g) for g in range(8, 240, 10)]


            esc = '33['
            # Reset all colors sequence
            reset = esc + '0m'
            # Regular color
            normal = esc + '38;5;{i}m'
            # Bold color
            bold = esc + '1;' + normal
            # Background color
            background = esc + '48;5;{i}m'

            pattern = (
            '{normal}{background}{padding:^{width}}{i:^3d} ' # pad the background
            '{r:02X}/{g:02X}/{b:02X}' # show the hex rgb code
            '{padding:^{width}}' # pad the background on the other side
            '{reset}' # reset again
            )

            base_context = dict(reset=reset, padding='', width=get_width())

            for i, (r, g, b) in enumerate(colored_palette + grayscale_palette, 16):
            context = dict(i=i, r=r, g=g, b=b, color=r + g + b, **base_context)
            context.update(bold=bold.format(**context))
            context.update(background=background.format(**context))

            # Change text color from black to white when it might become unreadable
            if max(r, g, b) > 0xCC:
            context.update(normal=normal.format(i=0))
            else:
            context.update(normal=normal.format(i=255))

            print(pattern.format(**context), end='')

            # Print newlines when needed
            if i % 6 == 3:
            print()
            else:
            print(' ', end='')





            share|improve this answer

















            • 2




              If anyone wants to run this script in a one liner, run curl https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/250eb2e3f2acca1c51aa52adf611ec0380291e8a/colortest.py | python3
              – Tommaso Thea Cioni
              Jul 26 at 17:21












            • I suggest curl -s https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/colortest.py | python3
              – masterxilo
              Dec 5 at 18:27













            up vote
            3
            down vote










            up vote
            3
            down vote









            Perhaps superfluous but I've written a version that prints the 256 colors using the background with automatic shell width detection so the colors are more easily visible.



            https://gist.github.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3



            256 color test demo



            #!/usr/bin/env python
            from __future__ import print_function

            import os
            import shutil
            import subprocess


            def get_width(default=80):
            '''Attempt to detect console width and default to 80'''
            try:
            columns, rows = shutil.get_terminal_size()
            except AttributeError:
            try:
            _, columns = subprocess.check_output(['stty', 'size']).split()
            except OSError:
            columns = os.environ.get('COLUMNS', default)

            columns = int(columns) - 77
            # Since we have 6 columns with 1 space on each side, we can increment the
            # size for every 12 extra columns
            return max(0, columns / 12)


            # Loosely based on https://gist.github.com/justinabrahms/1047767
            colored = [0] + list(range(95, 256, 40))
            colored_palette = [
            (r, g, b)
            for r in colored
            for g in colored
            for b in colored
            ]


            grayscale_palette = [(g, g, g) for g in range(8, 240, 10)]


            esc = '33['
            # Reset all colors sequence
            reset = esc + '0m'
            # Regular color
            normal = esc + '38;5;{i}m'
            # Bold color
            bold = esc + '1;' + normal
            # Background color
            background = esc + '48;5;{i}m'

            pattern = (
            '{normal}{background}{padding:^{width}}{i:^3d} ' # pad the background
            '{r:02X}/{g:02X}/{b:02X}' # show the hex rgb code
            '{padding:^{width}}' # pad the background on the other side
            '{reset}' # reset again
            )

            base_context = dict(reset=reset, padding='', width=get_width())

            for i, (r, g, b) in enumerate(colored_palette + grayscale_palette, 16):
            context = dict(i=i, r=r, g=g, b=b, color=r + g + b, **base_context)
            context.update(bold=bold.format(**context))
            context.update(background=background.format(**context))

            # Change text color from black to white when it might become unreadable
            if max(r, g, b) > 0xCC:
            context.update(normal=normal.format(i=0))
            else:
            context.update(normal=normal.format(i=255))

            print(pattern.format(**context), end='')

            # Print newlines when needed
            if i % 6 == 3:
            print()
            else:
            print(' ', end='')





            share|improve this answer












            Perhaps superfluous but I've written a version that prints the 256 colors using the background with automatic shell width detection so the colors are more easily visible.



            https://gist.github.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3



            256 color test demo



            #!/usr/bin/env python
            from __future__ import print_function

            import os
            import shutil
            import subprocess


            def get_width(default=80):
            '''Attempt to detect console width and default to 80'''
            try:
            columns, rows = shutil.get_terminal_size()
            except AttributeError:
            try:
            _, columns = subprocess.check_output(['stty', 'size']).split()
            except OSError:
            columns = os.environ.get('COLUMNS', default)

            columns = int(columns) - 77
            # Since we have 6 columns with 1 space on each side, we can increment the
            # size for every 12 extra columns
            return max(0, columns / 12)


            # Loosely based on https://gist.github.com/justinabrahms/1047767
            colored = [0] + list(range(95, 256, 40))
            colored_palette = [
            (r, g, b)
            for r in colored
            for g in colored
            for b in colored
            ]


            grayscale_palette = [(g, g, g) for g in range(8, 240, 10)]


            esc = '33['
            # Reset all colors sequence
            reset = esc + '0m'
            # Regular color
            normal = esc + '38;5;{i}m'
            # Bold color
            bold = esc + '1;' + normal
            # Background color
            background = esc + '48;5;{i}m'

            pattern = (
            '{normal}{background}{padding:^{width}}{i:^3d} ' # pad the background
            '{r:02X}/{g:02X}/{b:02X}' # show the hex rgb code
            '{padding:^{width}}' # pad the background on the other side
            '{reset}' # reset again
            )

            base_context = dict(reset=reset, padding='', width=get_width())

            for i, (r, g, b) in enumerate(colored_palette + grayscale_palette, 16):
            context = dict(i=i, r=r, g=g, b=b, color=r + g + b, **base_context)
            context.update(bold=bold.format(**context))
            context.update(background=background.format(**context))

            # Change text color from black to white when it might become unreadable
            if max(r, g, b) > 0xCC:
            context.update(normal=normal.format(i=0))
            else:
            context.update(normal=normal.format(i=255))

            print(pattern.format(**context), end='')

            # Print newlines when needed
            if i % 6 == 3:
            print()
            else:
            print(' ', end='')






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 8 at 8:55









            Wolph

            21413




            21413








            • 2




              If anyone wants to run this script in a one liner, run curl https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/250eb2e3f2acca1c51aa52adf611ec0380291e8a/colortest.py | python3
              – Tommaso Thea Cioni
              Jul 26 at 17:21












            • I suggest curl -s https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/colortest.py | python3
              – masterxilo
              Dec 5 at 18:27














            • 2




              If anyone wants to run this script in a one liner, run curl https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/250eb2e3f2acca1c51aa52adf611ec0380291e8a/colortest.py | python3
              – Tommaso Thea Cioni
              Jul 26 at 17:21












            • I suggest curl -s https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/colortest.py | python3
              – masterxilo
              Dec 5 at 18:27








            2




            2




            If anyone wants to run this script in a one liner, run curl https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/250eb2e3f2acca1c51aa52adf611ec0380291e8a/colortest.py | python3
            – Tommaso Thea Cioni
            Jul 26 at 17:21






            If anyone wants to run this script in a one liner, run curl https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/250eb2e3f2acca1c51aa52adf611ec0380291e8a/colortest.py | python3
            – Tommaso Thea Cioni
            Jul 26 at 17:21














            I suggest curl -s https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/colortest.py | python3
            – masterxilo
            Dec 5 at 18:27




            I suggest curl -s https://gist.githubusercontent.com/WoLpH/8b6f697ecc06318004728b8c0127d9b3/raw/colortest.py | python3
            – masterxilo
            Dec 5 at 18:27


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f821157%2fprint-a-256-color-test-pattern-in-the-terminal%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How did Captain America manage to do this?

            迪纳利

            南乌拉尔铁路局