Tput: Difference between revisions

From wikinotes
(Created page with "The Termcap DB is a library/db that abstracts control codes to manipulate a terminal.<br> The <code>tput</code> command can interact with it from shellscript.")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The Termcap DB is a library/db that abstracts control codes to manipulate a terminal.<br>
The Termcap DB is a library/db that abstracts control codes to manipulate a terminal.<br>
The <code>tput</code> command can interact with it from shellscript.
The <code>tput</code> command can interact with it from shellscript.
= Documentation =
<blockquote>
{| class="wikitable"
|-
| <code>man tput</code> || https://man.archlinux.org/man/core/ncurses/tput.1.en
|-
|}
</blockquote><!-- Documentation -->
= Console Info =
<blockquote>
<syntaxhighlight lang="bash">
tput lines  # height of terminal in chars
tput cols  # width of terminal in chars
</syntaxhighlight>
</blockquote><!-- Console Info -->
= Text Formatting =
<blockquote>
<syntaxhighlight lang="bash">
# colour
tput setaf 1  # set foreground colour to 1/255 (red)
tput setab 1  # set foreground colour to 1/255 (red)
# weight
tput bold  # bold
tput smul  # underline
# reset
tput sgr0    # reset formatting
</syntaxhighlight>
</blockquote><!-- Text Formatting -->
= Help Menu Colouring =
<blockquote>
I wrote and use this a lot.
<syntaxhighlight lang="bash">
setup_colours() {
    if [ $(tput colors) -gt 8 ] ; then
        C=$(tput setaf 6)  # code
        H=$(tput setaf 3)  # heading
        E=$(tput setaf 1)  # error
        B=$(tput bold)    # bold
        R=$(tput sgr0)    # reset
    else
        C=$(tput sgr0)
        H=$(tput sgr0)
        E=$(tput sgr0)
        B=$(tput sgr0)
        R=$(tput sgr0)
    fi
}
</syntaxhighlight>
</blockquote><!-- Help Menu Colouring -->

Latest revision as of 21:13, 16 October 2021

The Termcap DB is a library/db that abstracts control codes to manipulate a terminal.
The tput command can interact with it from shellscript.

Documentation

man tput https://man.archlinux.org/man/core/ncurses/tput.1.en

Console Info

tput lines  # height of terminal in chars
tput cols   # width of terminal in chars

Text Formatting

# colour
tput setaf 1  # set foreground colour to 1/255 (red)
tput setab 1  # set foreground colour to 1/255 (red)

# weight
tput bold  # bold
tput smul  # underline

# reset
tput sgr0     # reset formatting

Help Menu Colouring

I wrote and use this a lot.

setup_colours() {
    if [ $(tput colors) -gt 8 ] ; then
        C=$(tput setaf 6)  # code
        H=$(tput setaf 3)  # heading
        E=$(tput setaf 1)  # error
        B=$(tput bold)     # bold
        R=$(tput sgr0)     # reset
    else
        C=$(tput sgr0)
        H=$(tput sgr0)
        E=$(tput sgr0)
        B=$(tput sgr0)
        R=$(tput sgr0)
    fi
}