RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
WHITE="$(tput setaf 7)"
RESET=$WHITE
echo "${RED}An error occurred${RESET}"
echo "${YELLOW}Warning: Be careful${RESET}"
echo "${GREEN}Everything is groovy${RESET}"
(source)
Old, naive way:
GREEN="\[\033[32m\]"
YELLOW="\[\033[33m\]"
RESET="\[\033[0m\]"
A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.
Jump to
Showing posts with label output. Show all posts
Showing posts with label output. Show all posts
Determine a day's ordinal suffix: 1st, 2nd, 3rd, 4th, etc.
e.g. for dates you don't want to display "19 July" but rather "19th July":
Bonus points if you can integrate this with DateTime's strftime() method neatly.
(source)
my $ordinal;
if ($foo =~ /(?<!1)1$/) {
$ordinal = 'st';
} elsif ($foo =~ /(?<!1)2$/) {
$ordinal = 'nd';
} elsif ($foo =~ /(?<!1)3$/) {
$ordinal = 'rd';
} else {
$ordinal = 'th';
}
Bonus points if you can integrate this with DateTime's strftime() method neatly.
(source)
Colouring terminal output
- Emacs, in a
termbuffer: configurefont-lock-keywordsforterm-mode - spc (Supercat)
- grc (Generic Colouriser)
- highlight
- histring
- pygmentize
- grep --color
Thanks to StackOverflow
UPDATE: You can actually do this yourself with pretty much any programming language that has an ANSI colours library.
UPDATE: You can actually do this yourself with pretty much any programming language that has an ANSI colours library.
Subscribe to:
Posts (Atom)