Ir para o conteúdo
ou

Software livre Brasil

 Voltar a Blogosfera d...
Tela cheia Sugerir um artigo

Antonio Terceiro: A visual cheat sheet for ANSI color codes

28 de Janeiro de 2012, 0:00 , por Software Livre Brasil - 0sem comentários ainda | Ninguém está seguindo este artigo ainda.
Visualizado 642 vezes

Now and then I want to output some ANSI color escape codes from software I write, and I always end up doing some trial-and-error to figure out the exact codes I want. Sometimes it’s overkill to add a dependency on an existing library that already deals with it, or the language I am using does not have one.

There are a lot of listings of the ANSI color codes out there, but I couldn’t find one that matches the actual codes with the resulting effect in a visual way. Even the Wikipedia article has a colored table with the actual colors, but I have to lookup manually which code combination produces which color.

So I spent a few minutes to write a shell script that prints all useful combinations, formatted with themselves. This way I can quickly figure out which exact code I want to achieve the desired effect.

The code for now is very simple:


#!/bin/sh -e

for attr in $(seq 0 1); do
  for fg in $(seq 30 37); do
    for bg in $(seq 40 47); do
      echo -n "\033[$attr;${bg};${fg}m$attr;$fg;$bg\033[m " 
    done
    echo
  done
done

Is there a package in Debian that already does that? Would people find it useful to have this packaged?

update: it turns out you can find some similar stuff on google images. It was a quick and fun hack, though.


Fonte: http://softwarelivre.org/terceiro/blog/a-visual-cheat-sheet-for-ansi-color-codes

0sem comentários ainda

Enviar um comentário

Os campos são obrigatórios.

Se você é um usuário registrado, pode se identificar e ser reconhecido automaticamente.