Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

154 votes
7 answers
169909 views
tput setaf color table? How to determine color codes?
I am in the process of colorizing my terminal’s `PS1`. I am setting color variables using `tput`; for example, here’s purple: PURPLE=$(tput setaf 125) ### Question: How do I find the color codes (e.g. `125`) of other colors? Is there a color table guide/cheat sheet somewhere? I’m just not sure what...
I am in the process of colorizing my terminal’s PS1. I am setting color variables using tput; for example, here’s purple: PURPLE=$(tput setaf 125) ### Question: How do I find the color codes (e.g. 125) of other colors? Is there a color table guide/cheat sheet somewhere? I’m just not sure what 125 is … Is there some way to take a hex color and convert into a number that setaf can use?
mhulse (1859 rep)
Mar 11, 2016, 04:42 AM • Last activity: Apr 27, 2025, 07:42 AM
0 votes
1 answers
37 views
Command substitution used with tput which doesn't print anything
I am doing a code-study of `/lib/lsb/init-functions` on mint 20 just to familiarise myself with SystemV init system. There is `log_action_end_msg` function in it which has this code snippet, ``` TPUT=/usr/bin/tput if log_use_fancy_output; then RED=$( $TPUT setaf 1) #=> Step 1 NORMAL=$( $TPUT op) # /...
I am doing a code-study of /lib/lsb/init-functions on mint 20 just to familiarise myself with SystemV init system. There is log_action_end_msg function in it which has this code snippet,
TPUT=/usr/bin/tput
if log_use_fancy_output; then
            RED=$( $TPUT setaf 1)  #=> Step 1
            NORMAL=$( $TPUT op)    #
            /bin/echo -e "${RED}failed${end}${NORMAL}" || true #=> Step 2
else
            echo "failed${end}" || true
fi
when the variable RED is assigned the value of $( $TPUT setaf 1 ), i expect RED to be assigned an empty string, since tput run on command-line doesn't print any stuff. But, I see the variable is passed onto echo in Step 2 implying that it has something stored in it. How does the variable RED get set, when tput doesn't print anything? (Or) Let us leave aside all the other stuffs. Take a fresh terminal and just run RED=$( $TPUT setaf 1) on my terminal and i expect terminal font color to be set as red but it is not so. Only when i do echo $RED, it turns red. Why is that tput command not getting run during the substitution step, but runs when you invoke echo.
Saravana (193 rep)
Feb 3, 2025, 08:13 PM • Last activity: Feb 3, 2025, 10:19 PM
2 votes
1 answers
287 views
How can I get tput to fill the whole background without leaving a border?
I'm using bash in cygwin on a Windows laptop. I'd like to be able to change the background color of my terminal to green (actual color irrelevant) and to do that I can use either of these commands: 1. `tput setb 2; echo` 2. `printf '\e]11;#00FF00\a'` For more info on what that `printf` is doing, see...
I'm using bash in cygwin on a Windows laptop. I'd like to be able to change the background color of my terminal to green (actual color irrelevant) and to do that I can use either of these commands: 1. tput setb 2; echo 2. printf '\e]11;#00FF00\a' For more info on what that printf is doing, see [how-to-set-the-background-color-of-the-linux-console-screen](https://unix.stackexchange.com/questions/474502/how-to-set-the-background-color-of-the-linux-console-screen/474924#474924) and the specific use of 11 for background is documented on page 34 of https://invisible-island.net/xterm/ctlseqs/ctlseqs.pdf (Ps = 1 0 → Change VT100 text foreground color to Pt. and Ps = 1 1 → Change VT100 text background color to Pt.) The printf immediately changes the bacground of the whole terminal while the tput just sets the color for what is typed next, hence the echo to start on the next empty line, but I don't care much about that. What I do most care about is the following: The tput leaves a small border in the original background color (pale beige, set by the "Options" GUI I get by clicking on the top-left of the terminal) as can be seen in this image (the pale grey around the left/bottom of the image is my Windows desktop color): enter image description here The printf changes the color of the border (it's a lighter shade of green from tput's but that's irrelevant): enter image description here but it does not change the area of the background that was set by tput unless I first re-initialize what my original tput did with tput init; echo and then execute the printf: enter image description here I can just use the printf to get what I want as long as I don't use tput setb first but I'd prefer to **only** use tput setb if I can for portability so - why is tput leaving a small border of the existing background color and is there any way to tell tput to set the background color in a way that does not leave that small border? I'd also like to know if there's a way to have tput set the whole terminal background immediately, as the printf does, rather than after the next string I type, but that's not nearly as important as getting rid of that border. Additional info now that [@MarcusMüller](https://unix.stackexchange.com/users/106650/marcus-m%c3%bcller) gave me the hint [in a comment](https://unix.stackexchange.com/questions/780532/how-can-i-get-tput-to-fill-the-whole-background-without-leaving-a-border?noredirect=1#comment1493703_780532) that this might be a mintty issue - I see this same behavior when I use git bash from Windows on a different machine. They apparently both use mintty as the terminal emulator. Since I have to log into many different Windows machines and use cygwin or git bash, I'd like to be able to solve this problem without having to change terminal emulator every time I use one of those machines (I'm not even sure if/how I could do that). In fact, if it came down to changing terminal emulator to solve the tput problem, I'd just use the printf approach instead. I found at [set-border-width-for-mintty-window-on-cygwin-windows-10](https://stackoverflow.com/a/67448126/1745001) a way to control the border width from ~/.minttyrc by setting the Padding variable and if I update it to say: Padding=0 then that does work around the above tput problem but 1. That'd mean I'd have to change the .minttyrc on every machine I log into and restart the terminal afterwards, and 2. When I open the "Options" GUI to change anything about the terminal then save it, it overwrites that .minttyrc file and removes the Padding setting so I still would like to find some way to simply tell tput to fill that "padding" area just like it does the rest of the background. [@Vilinkameni](https://unix.stackexchange.com/users/367454/vilinkameni) also points out [in a comment](https://unix.stackexchange.com/questions/780532/how-can-i-get-tput-to-fill-the-whole-background-without-leaving-a-border#comment1493719_780532) that with the above tput in a mintty and MSYS2 MINGW64 terminal, any ANSI SGR color switching by a subsequent ls --color or other command that uses colors will effectively reset the color again. That does not happen if I use the above printf so I may ask about that in a subsequent question. See also "Changing colours" towards the bottom https://code.google.com/archive/p/mintty/wikis/Tips.wiki#Changing_colours for more information on the above printf and other things related to mintty. My $TERM value is xterm.
Ed Morton (35459 rep)
Jul 21, 2024, 12:32 PM • Last activity: Jul 26, 2024, 11:46 AM
2 votes
1 answers
144 views
How to "render" ouput from a command playing with tput so only the final terminal-postprocessed result is kept?
I captured the output of a script that uses tput to draw certain things on screen. When I perform cat myoutput then everything is well seen (looks like terminal reinterprets it from beginning), but when I edit or pipe that output I see plenty of ansi sequences and all the stuff previous to destructi...
I captured the output of a script that uses tput to draw certain things on screen. When I perform cat myoutput then everything is well seen (looks like terminal reinterprets it from beginning), but when I edit or pipe that output I see plenty of ansi sequences and all the stuff previous to destructive printing like tput clear and the like. How can I a postprocess it so I only get the final "render"? Even better, the origin of this is that I am currently teeing my script so it prints everything to a file aside from to the terminal with exec > >(tee /dev/tty) is there a way to tell the stdout channel to "render" everything before saving?
Whimusical (285 rep)
Mar 16, 2024, 09:41 AM • Last activity: Mar 16, 2024, 12:10 PM
17 votes
2 answers
3363 views
Full list of tput options
I wanted to hide the cursor, and I was aware of `tput` command. I did search its man page. On searching the Internet, I found $ tput civis # to hide the cursor $ tput cnorm # to bring back the cursor These work perfectly, but these options are not mentioned anywhere in the man page. Where are they o...
I wanted to hide the cursor, and I was aware of tput command. I did search its man page. On searching the Internet, I found $ tput civis # to hide the cursor $ tput cnorm # to bring back the cursor These work perfectly, but these options are not mentioned anywhere in the man page. Where are they officially documented?
mtk (28468 rep)
Sep 27, 2015, 10:42 AM • Last activity: Feb 1, 2024, 09:33 PM
19 votes
4 answers
4498 views
Is there any objective benefit to escape sequences over tput?
In people's '`.*rc`' files I see online or in various code, I tend to see a lot of people who manually use ANSI escape sequences instead of using `tput`. I had the understanding that `tput` is more universal/safe, so this makes me wonder: Is there any objective reason one should use escape sequences...
In people's '.*rc' files I see online or in various code, I tend to see a lot of people who manually use ANSI escape sequences instead of using tput. I had the understanding that tput is more universal/safe, so this makes me wonder: Is there any objective reason one should use escape sequences in place of tput? (Portability, robustness on errors, unusual terminals...?)
Captain Man (1218 rep)
Apr 5, 2016, 02:40 PM • Last activity: Dec 9, 2023, 07:37 PM
-1 votes
1 answers
278 views
The Command tput sgr0 Changes my Terminal Font and Text Colour, how to Stop This? Any echo After tput sgr0 Outputs as Bold White
When I do `tput sgr0` it changes my terminal font and colour to white (should be black) and looks blocky. Please see screenshot: [![enter image description here][1]][1] How do I stop this? To be more concise, any `echo` after `tput sgr 0` seems to output to bold white, my terminal text colour is bla...
When I do tput sgr0 it changes my terminal font and colour to white (should be black) and looks blocky. Please see screenshot: enter image description here How do I stop this? To be more concise, any echo after tput sgr 0 seems to output to bold white, my terminal text colour is black. ### Update: My ~.bashrc:
export LC_ALL="en_GB.UTF-8"
export BASH_SILENCE_DEPRECATION_WARNING=1

branch() {
  git branch 2> /dev/null | \ 
  grep \*                 | \ 
  awk '{print$2}'         | \ 
  sed '
    s#^#(#g;
    s#$#)#g
  '
 }

colo() { tput setaf $1; }


PS1='tput boldcolo 5\W: tput sgr0colo 0branchcolo 0 \n λ '
Nickotine (554 rep)
Nov 22, 2023, 02:46 AM • Last activity: Nov 22, 2023, 02:53 PM
1 votes
2 answers
1408 views
bash script to get current line and row not working
ive written the following script to print out the current line and row every time it changes aka every time i press up,down,left or right but the output is always the same: row:43:col:141 i believe this means top left of the screen where 0 0 would be bottom right, but im not too sure. heres my scrip...
ive written the following script to print out the current line and row every time it changes aka every time i press up,down,left or right but the output is always the same: row:43:col:141 i believe this means top left of the screen where 0 0 would be bottom right, but im not too sure. heres my script: #!/bin/bash echo "press a key" tput clear row=$(tput lines) col=$(tput cols) while true; do echo "row:$row:col:$col" K1=,K2=,K3= read -s -N1 K1="$REPLY" read -s -N1 -t 0.001 K2="$REPLY" read -s -N1 -t 0.001 K3="$REPLY" key="$K1$K2$K3" case "$key" in $'\033[A') tput cuu 1;; $'\033[B') tput cud 1;; $'\033[C') tput cuf 1;; $'\033[D') tput cup $row $(($col-1));; *) echo "pressed a key!";; esac row=$(tput lines) col=$(tput cols) done exit 0 apparently theres no way to move the cursor left using tput, so I used: tput cup $row $(($col-1)) but this doesn't work either, any ideas how to fix?
Mathew (243 rep)
Oct 19, 2023, 03:47 PM • Last activity: Oct 21, 2023, 05:56 AM
6 votes
1 answers
7017 views
What is the ANSI escape equivalent of `tput sgr0`?
To avoid a subshell, what are the ANSI escape equivalents of `tput sgr0` for an ANSI-compatible terminal?
To avoid a subshell, what are the ANSI escape equivalents of tput sgr0 for an ANSI-compatible terminal?
Tom Hale (32892 rep)
Sep 21, 2018, 09:38 AM • Last activity: Aug 13, 2023, 01:44 PM
1 votes
2 answers
176 views
Adding a newline above PS1 that survives prepending
In OBSD ksh, I had a PS1 which prepended a blank line: ```bash PS1="\n[\u@\h] \w\n\$" ``` The problem with this was that pyenv prepends the name of a virtual environment when that environment is activated. Here is the relevant bit of the pyenv activation script: ```bash PS1="(porcupine) ${PS1:-}" ``...
In OBSD ksh, I had a PS1 which prepended a blank line:
PS1="\n[\u@\h] \w\n\$"
The problem with this was that pyenv prepends the name of a virtual environment when that environment is activated. Here is the relevant bit of the pyenv activation script:
PS1="(porcupine) ${PS1:-}"
This eats the blank line, turning
[myusername@myhostname] ~/some/path $ echo foo
foo

[myusername@myhostname] ~/some/path $
into
(virtual-environment-name)
[myusername@myhostname] ~/some/path $ echo foo
foo
(virtual-environment-name)
[myusername@myhostname] ~/some/path $
This is annoying, so I tried to fix it with tput:
PS1_TEXT="[\u@\h] \w\n\$ "
PS1="$(tput sc il1 nw)$(tput rc DO 1)\n$PS1_TEXT"
This moves the cursor to the row above the virtual environment name, makes it a blank line, then returns and sticks in my original PS1. This almost works, but when I hit the bottom of the terminal window, the virtual environment name vanishes. This is annoying, again.
user1093043 (103 rep)
Aug 2, 2023, 08:59 PM • Last activity: Aug 3, 2023, 01:16 PM
0 votes
2 answers
162 views
Not enough arguments for capability `setaf` in OpenBSD
I want to change the text colour in a shell. I can use `tput` to get the correct escape codes. For example, ```shell echo "$(tput setaf 5)My text$(tput sgr0)" ``` outputs `My text` in a pink-ish tone. This works fine on Linux, macOS, FreeBSD, NetBSD, and Solaris. On OpenBSD 7.2, however, I get the f...
I want to change the text colour in a shell. I can use tput to get the correct escape codes. For example,
echo "$(tput setaf 5)My text$(tput sgr0)"
outputs My text in a pink-ish tone. This works fine on Linux, macOS, FreeBSD, NetBSD, and Solaris. On OpenBSD 7.2, however, I get the following error:
tput: not enough arguments (3) for capability `setaf'
According to [the OpenBSD docs of tput](https://man.openbsd.org/tput) , the attribute should be defined in terminfo or termcap. I don't see setaf defined in [the docs for termcap](https://man.openbsd.org/termcap.5) , so I assume tput interprets setaf as defined in [the docs for terminfo](https://man.openbsd.org/terminfo.5) . According to those docs: > To change the current foreground or background color on a Tektronix-type terminal, use **setaf** (set ANSI foreground) and **setab** (set ANSI background) or **setf** (set foreground) and **setb** (set background). These take one parameter, the color number. This conflicts what I've been told by the error message. On the other hand, I can use tput setaf 5 0 0 and, regardless of the last two parameters, the foreground colour is changed to pink-ish. Why does tput require three parameters on OpenBSD, and what do those extra two parameters mean?
FWDekker (101 rep)
Feb 17, 2023, 06:13 PM • Last activity: Feb 18, 2023, 03:35 PM
10 votes
6 answers
17103 views
How can I print a variable with padded center alignment?
How can I print `$myvar` padded so that it is in the center of the terminal, and to either side are `=` to the edge of the screen?
How can I print $myvar padded so that it is in the center of the terminal, and to either side are = to the edge of the screen?
Wildcard (37446 rep)
Mar 5, 2016, 12:09 AM • Last activity: Jan 26, 2023, 04:59 PM
0 votes
1 answers
478 views
How does `tput` detect color support
I am trying to make my shell script supporting as much terminals as possible, that is, adding ANSI colors, bold and dim only when supported. However, I want to detect the number of colors supported. We can use `tput colors`. However, I find that some systems that are stripped down to minimal does no...
I am trying to make my shell script supporting as much terminals as possible, that is, adding ANSI colors, bold and dim only when supported. However, I want to detect the number of colors supported. We can use tput colors. However, I find that some systems that are stripped down to minimal does not have it installed. So, I want to implement it in shell. How does tput colors work? Any equivalent of tput colors with POSIX commands? Please help and answer.
sudoer (65 rep)
Jan 6, 2023, 12:44 PM • Last activity: Jan 6, 2023, 01:33 PM
5 votes
2 answers
712 views
tput ed is empty
The output of `tput ed` is empty and I can't figure out why. Other capabilities work fine. Also `ed` is not missing from `infocmp` output so tput should match, right? ``` $ printf '%q' "$(tput ed)" '' ``` ``` $ printf '%q' "$(tput home)" $'\033'\[H ``` I'm using zsh on Mac OS 10.14.6 and iTerm2. TER...
The output of tput ed is empty and I can't figure out why. Other capabilities work fine. Also ed is not missing from infocmp output so tput should match, right?
$ printf '%q' "$(tput ed)"
''
$ printf '%q' "$(tput home)"
$'\033'\[H
I'm using zsh on Mac OS 10.14.6 and iTerm2. TERM=xterm-256color.
cambunctious (210 rep)
Nov 18, 2019, 11:06 PM • Last activity: Nov 30, 2022, 11:19 PM
1 votes
4 answers
7906 views
linux + tput: No value for $TERM and no -T specified
I use in my bash script the tput command in order to colored the text as tput setaf 2 when I run the script from putty or console every thing is ok but when I run some external WIN application engine that run the script via SSH the we get the following error on tput tput: No value for $TERM and no -...
I use in my bash script the tput command in order to colored the text as tput setaf 2 when I run the script from putty or console every thing is ok but when I run some external WIN application engine that run the script via SSH the we get the following error on tput tput: No value for $TERM and no -T specified tput: No value for $TERM and no -T specified tput: No value for $TERM and no -T specified tput: No value for $TERM and no -T specified please advice what need to set ( ENV or else ) in my bash script in order to use the tput command ?
yael (13936 rep)
Jan 10, 2018, 10:55 AM • Last activity: Nov 23, 2022, 02:03 PM
1 votes
0 answers
178 views
Use altscreen like vim with screen with Ubuntu XTerm
When I exit a screen, I want to be able to return to the terminal looking as I left it. But right now, all I can do is have it clear the screen and put the terminal at the top or the bottom through modifying my `.screenrc` file. I can get the interaction I want by doing `tput smcup; screen -S hello;...
When I exit a screen, I want to be able to return to the terminal looking as I left it. But right now, all I can do is have it clear the screen and put the terminal at the top or the bottom through modifying my .screenrc file. I can get the interaction I want by doing tput smcup; screen -S hello; tput rmcup, but I don't think I can easily alias or safely make it into a function*.  How would I change my .screenrc file to get this behavior? Here is what I have tried to little effect from other Stack Exchange questions:
termcapinfo xterm|xterms|xs|rxvt ti@:te@
termcapinfo xterm*|rxvt*  te=\E?1049l:ti=\E[?1049h:
termcapinfo xterm*|rxvt*  te=:ti=
from [How to prevent GNU screen from clearing the screen when terminating? I also read the answer to “Why doesn't the screen clear when running vi?” in the XTerm FAQ by Thomas E. Dickey , but couldn't translate it into something actionable. Changing the term command didn't affect me and I didn't try the second part: Detaching from a GNU Screen suddenly clears the terminal (on Super User). \____________ \ \* I did actually try my hand at it, but I'd like some confirmation that this wouldn't break anything: jscreen () { if [ $# -eq 2 ]; then if [ $1 == "-r" ] || [ $1 == "-S" ]; then tput smcup screen $@ tput rmcup return fi fi screen $@ }
Jeff (121 rep)
Nov 7, 2022, 02:44 AM • Last activity: Nov 8, 2022, 04:39 AM
8 votes
2 answers
4525 views
tput: No value for $TERM and no -T specified
I am trying to run a bash script I have via cron, and I am getting the following error at the beginning of the execution: tput: No value for $TERM and no -T specified Here is what is in my crontab: 0 8 * * 1-5 cd /var/www/inv/ && /var/www/inv/unitTest run all 2>&1| mail -r "user@example.com" -s "Dai...
I am trying to run a bash script I have via cron, and I am getting the following error at the beginning of the execution: tput: No value for $TERM and no -T specified Here is what is in my crontab: 0 8 * * 1-5 cd /var/www/inv/ && /var/www/inv/unitTest run all 2>&1| mail -r "user@example.com" -s "Daily Inventory Unit Test Results" user@example.com
ComputerLocus (183 rep)
Jun 11, 2015, 12:42 PM • Last activity: Sep 19, 2022, 10:00 PM
23 votes
1 answers
19736 views
Hide and unhide cursor with tput
tput civis successfully hides the cursor. tput cvvis should unhide it, but it doesn't. Any idea what the problem might be?
tput civis successfully hides the cursor. tput cvvis should unhide it, but it doesn't. Any idea what the problem might be?
Petr Skocik (29590 rep)
Aug 5, 2015, 01:16 PM • Last activity: May 12, 2022, 10:47 AM
2 votes
1 answers
525 views
Setting LESS_TERMCAP_* variables with $(tput ...) in ~/.profile not working
This is my `~/.bashrc`: ```shell # ...unnecessary lines skipped... # man colors LESS_TERMCAP_mb=$(tput blink) # start bold LESS_TERMCAP_md=$(tput setaf 2 ; tput bold) # start bold LESS_TERMCAP_me=$(tput sgr0) # turn off bold, blink and underline LESS_TERMCAP_so=$(tput smso) # start standout (reverse...
This is my ~/.bashrc:
# ...unnecessary lines skipped...
# man colors
LESS_TERMCAP_mb=$(tput blink) # start bold
LESS_TERMCAP_md=$(tput setaf 2 ; tput bold) # start bold
LESS_TERMCAP_me=$(tput sgr0)  # turn off bold, blink and underline
LESS_TERMCAP_so=$(tput smso)  # start standout (reverse video)
LESS_TERMCAP_se=$(tput rmso)  # stop standout
LESS_TERMCAP_us=$(tput smul)  # start underline
LESS_TERMCAP_ue=$(tput rmul)  # stop underline
export LESS_TERMCAP_mb
export LESS_TERMCAP_md
export LESS_TERMCAP_me
export LESS_TERMCAP_so
export LESS_TERMCAP_se
export LESS_TERMCAP_us
export LESS_TERMCAP_ue
This works, I can see colors in man pages. But when I move that lines from ~/.bashrc to ~/.profile (and re-login), the colors in man pages disappears. I really want to use tput because it is more clear than a heap of control symbols. Why do tput not working from .profile?
Alexander (93 rep)
Oct 9, 2021, 10:03 AM • Last activity: Apr 8, 2022, 10:54 AM
4 votes
1 answers
5439 views
How to check if a terminal can display undercurl from within a bash/zsh script?
How to check if a terminal can display undercurl from within a bash/zsh script? In a recent project I used undercurl escape sequence for output printed by a zsh script. It works well in modern terminals, but Apple's Terminal.app shows that as a reversed background-foreground. It would be nice to be...
How to check if a terminal can display undercurl from within a bash/zsh script? In a recent project I used undercurl escape sequence for output printed by a zsh script. It works well in modern terminals, but Apple's Terminal.app shows that as a reversed background-foreground. It would be nice to be able to detect if the terminal has the ability to display undercurl, and only then use undercurl or default to regular underline.
codepoet (626 rep)
Mar 21, 2022, 06:41 AM • Last activity: Mar 22, 2022, 06:49 AM
Showing page 1 of 20 total questions