Visit

Showing posts with label terminale con font colorati. Show all posts
Showing posts with label terminale con font colorati. Show all posts

06 September 2011

colore caratteri, colore sfondo

dopo varie ricerche e prove ho finalmente capito come avere nel terminale caratteri rossi e sfondo giallo da una mia applicazione. ecco due esempi, uno in c e uno in script sh fond_color.c
/* * ---------------------------------------------------------------------- * by Erika * begin : september 02 2011 * Last change: september 03 2011 * * compilare with: * gcc -g -Wall fond_color.c -o fond_color * per avviarlo ./fond_color *----------------------------------------------------------------------- */ #include int main() { int attributo = 0, fore_ground = 0, back_ground = 0; for (attributo = 0; attributo <= 7; ++attributo) { printf ("--------------------------------------------------------\n"); printf ("ESC[%d;Foreground;Background -\n", attributo); for (fore_ground = 30; fore_ground <= 37; ++fore_ground) { for (back_ground = 40; back_ground <= 47; ++back_ground) { printf ("\e[%d;%d;%dm %d;%d \e[00m", attributo, fore_ground, back_ground, fore_ground, back_ground); } printf ("\n"); } } return (0); }
colori_bash.sh
#!/bin/sh #----------------------------------------------------------------------- # by Erika # begin : september 01 2011 # Last change: september 03 2011 # # per renderlo eseguibile # chmod +x colori_bash.sh # per avviarlo ./colori_bash.sh #----------------------------------------------------------------------- for attr in 0 1 4 5 7 ; do echo "--------------------------------------------------------" printf "ESC[%s;Foreground;Background - \n" $attr for fore in 30 31 32 33 34 35 36 37; do for back in 40 41 42 43 44 45 46 47; do printf '\033[%s;%s;%sm %02s;%02s \033[0m' $attr $fore $back $fore $back done printf '\n' done done