💾 Archived View for rawtext.club › ~samhunter › random › ansicode captured on 2024-08-18 at 22:41:27.

View Raw

More Information

⬅️ Previous capture (2021-12-03)

🚧 View Differences

-=-=-=-=-=-=-

#! /bin/bash
help () {
	cat <<-_help_
	# ANSICODE
	# ansicode - generates strings with "ANSI-coded" colours 
	#
	# Author: samhunter@rc
	#
	# Syntax: 
	#	ansicode FILE 
	#		Generates colourful text "images" using ANSI colour codes
	#	ansicode --example [FILE] | -e [FILE]
	#		Saves example data in specified FILE or in EXAMPLE.ANSI (default)
	#	ansicode --help|-h
	#		This message
	#
	# Available colour codes  (ansi-256 only!)
	#	blac(k)
	#	(B)lue
	#	(G)reen
	#	(R)ed
	#	(Y)ellow
	#	(O)range
	#	(V)iolet
	#	$ = New line
	#
	#
_help_
}
example () {
	local FILE=${1:-EXAMPLE.ANSI}
	cat <<-_example_ > ${FILE}
	RRRRR    RR   R    R RRRRR RRRRRR R    R RRRRR      RRRR  R      R    R RRRRR  
	O    O  O  O  O    O   O   O       O  O    O       O    O O      O    O O    O 
	Y    Y Y    Y Y    Y   Y   YYYYY    YY     Y       Y      Y      Y    Y YYYYY  
	GGGGG  GGGGGG G GG G   G   G        GG     G   GGG G      G      G    G G    G 
	B   B  B    B BB  BB   B   B       B  B    B   BBB B    B B      B    B B    B 
	V    V V    V V    V   V   VVVVVV V    V   V   VVV  VVVV  VVVVVV  VVVV  VVVVV  
_example_

}

[[ "$1" == "-e" || "$1" == "--example" ]] && { example "$2" ; exit 0 ; }
[[ "$1" == "-h" || "$1" == "--help" ]] && { help ; exit 0 ; }
[[ -r "$1" ]] || exit 1
TEXT=""
READ=0
while read LINE ; do
	let READ+=1
	TEXT="$TEXT\$LINE"
done < "$1"
echo -ne "\x1b[${READ}S\x1b[${READ}A"
sed -e  '
	## PROC_START
	s+k+\x1b[48;5;238m \x1b[0m+g;    # blac(k)
	s+B+\x1b[48;5;19m \x1b[0m+g;     # (B)lue
	s+G+\x1b[48;5;241m \x1b[0m+g;    # (G)reen
	s+R+\x1b[45;5;196m \x1b[0m+g;    # (R)ed
	s+Y+\x1b[48;5;220m \x1b[0m+g;    # (Y)ellow
	s+O+\x1b[48;5;208m \x1b[0m+g;    # (O)range
	s+V+\x1b[48;5;54m \x1b[0m+g;     # (V)iolet
	s+\$+\x1b[E+g;                   # $ = New line
	## PROC_END
	' <<<"$TEXT"