Examples
This section showcases various term-transcript options. It uses the CLI app
as more approachable, but all showcased features work in the Rust library as well.
Command-line args
| Section | Covered command-line args |
|---|---|
| Basics | --palette, --pure-svg, --pty, --scroll, --line-height, --advance-width |
| Window Appearance | --width, --hard-wrap, --scroll-interval, --scroll-len, --window |
| Line Numbering | --line-numbers, --continued-mark, --hard-wrap-mark |
| Custom Fonts | --font, --embed-font |
| Input Control | --no-inputs |
| Custom Config | --tpl, --config-path |
rainbow script
Most examples use rainbow – a shell script showcasing various ANSI styles.
rainbow shell script (click to expand)
#!/usr/bin/env sh
# Standalone shell script to output various text styles
BASE_COLORS="black red green yellow blue magenta cyan white"
RGB_COLOR_NAMES="pink orange brown teal"
RGB_COLOR_VALUES="255;187;221 255;170;68 159;64;16 16;136;159"
RESET='\033[0m'
BOLD='\033[1m'
DIMMED='\033[2m'
ITALIC='\033[3m'
UNDERLINE='\033[4m'
BLINK='\033[5m'
INVERTED='\033[7m'
CONCEALED='\033[8m'
STRIKE='\033[9m'
GREEN_FG='\033[32m'
YELLOW_FG='\033[33m'
MAGENTA_BG='\033[45m'
CYAN_BG='\033[46m'
index() {
shift "$1"
echo "$2"
}
base_styles_line() {
base_style="$1"
name="$2"
line="$name: ${base_style}Regular$RESET"
line="$line ${base_style}$BOLD${GREEN_FG}Bold$RESET"
line="$line ${base_style}$ITALIC$YELLOW_FG${MAGENTA_BG}Italic$RESET"
line="$line ${base_style}$BOLD$CYAN_BG${ITALIC}Bold+Italic$RESET"
line="$line ${base_style}${STRIKE}Strike$RESET"
echo "$line"
}
base_colors_line() {
start_code="$1"
underline_oddity="$2"
line=""
for i in $(seq 0 7); do
color=$((i + start_code))
decor=""
if [ $((i % 2)) -eq "$underline_oddity" ]; then
decor="$UNDERLINE"
fi
line=$line'\033['$color'm'$decor$(index "$i" $BASE_COLORS)$RESET' '
if [ "$3" = "1" ]; then
line=$line'\033['$color'm'$UNDERLINE$ITALIC$(index "$i" $BASE_COLORS)"/italic"$RESET' '
fi
done
echo "$line"
}
ansi_colors_line() {
line=""
for i in $(seq 16 231); do
fg_color="\033[37m" # white
col=$(((i - 16) % 36))
if [ "$col" -gt 18 ]; then
fg_color="\033[30m" # black
fi
line=$line'\033[38;5;'$i'm!\033[0m'$fg_color'\033[48;5;'$i'm?\033[0m'
if [ "$1" != "1" ] && [ "$col" -eq 35 ]; then
echo "$line"
line=""
fi
done
if [ "$1" = "1" ]; then
echo "$line"
fi
}
ansi_grayscale_line() {
line=""
for i in $(seq 232 255); do
fg_color="\033[37m" # white
if [ "$i" -ge 244 ]; then
fg_color="\033[30m" # black
fi
line=$line'\033[38;5;'$i'm!\033[0m'$fg_color'\033[48;5;'$i'm?\033[0m'
done
echo "$line"
}
rgb_colors_line() {
line=""
for i in $(seq 0 3); do
name=$(index "$i" $RGB_COLOR_NAMES)
value=$(index "$i" $RGB_COLOR_VALUES)
line=$line'\033[38;2;'$value'm'$name'\033[0m '
done
echo "$line"
}
if [ "$1" = "--short" ]; then
echo "Base styles:"
base_styles_line '' " None"
base_styles_line "$DIMMED" " Dimmed"
base_styles_line "$UNDERLINE" "Underline"
base_styles_line "$BLINK" " Blink"
base_styles_line "$CONCEALED" "Concealed"
base_styles_line "$INVERTED" " Inverted"
base_styles_line '\033[30m\033[47m' " With bg"
echo "Partial switches (<ESC>[2x):"
printf ' \033[1m''bold \033[3m''italic\033[22m \033[4m''underline\033[23m\033[5m\033[32m blink \033[7m\033[24m'
printf 'reversed \033[25m\033[8m\033[9m''concealed\033[27m\033[28m\n'
printf ' \033[45m''strikethrough\033[29m\033[39m\033[49m regular\033[0m\n'
fi
long_lines=""
if [ "$1" = "--long-lines" ]; then
long_lines=1
fi
echo "Base colors:"
base_colors_line 30 0 "$long_lines"
base_colors_line 90 1 "$long_lines"
echo "Base colors (bg):"
base_colors_line 40 2
base_colors_line 100 2
if [ "$1" = "--short" ]; then
exit 0
fi
echo "ANSI color palette:"
ansi_colors_line $long_lines
echo "ANSI grayscale palette:"
ansi_grayscale_line
echo "24-bit colors:"
rgb_colors_line