Skip to content
holzkohlengrill edited this page Dec 15, 2023 · 2 revisions

Cursor, colour, text formatting and more

Guide still missing

For now refer to: http://linuxcommand.org/lc3_adv_tput.php

Cursor

# Get number of lines and columns in current window
tput lines
tput cols

# Position cursor and print "Hello" centered
clear
tput cup $(expr $(tput lines) / 2) $(expr $(tput cols) / 2); printf HELLO

Example defines

# Definitions

BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)

BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)

# Example Usage
printf "%40s\n" "${BLUE}This text is blue${NORMAL}"

Sources

Clone this wiki locally