Whiptail change background color dynamically from magenta?
Internal colour palette of whiptail may be overwritten at compilation by providing a path to a file containing color definitions.
In ubuntu sudo update-alternatives --config newt-palette
provides a way of selecting between ubuntu palette and original palette.
The location of this file can be overriden by setting the NEWT_COLORS_FILE
to point to an alternative file.
Furthermore both previous overrides can be overriden by setting the NEWT_COLORS
environment variable.
The structure of the definitions is:
name=[fg],[bg][;|:|\n|\r|\t]name2=[fg],[bg]]...
name
can be:
root root fg, bg
border border fg, bg
window window fg, bg
shadow shadow fg, bg
title title fg, bg
button button fg, bg
actbutton active button fg, bg
checkbox checkbox fg, bg
actcheckbox active checkbox fg, bg
entry entry box fg, bg
label label fg, bg
listbox listbox fg, bg
actlistbox active listbox fg, bg
textbox textbox fg, bg
acttextbox active textbox fg, bg
helpline help line
roottext root text
emptyscale scale full
fullscale scale empty
disentry disabled entry fg, bg
compactbutton compact button fg, bg
actsellistbox active & sel listbox
sellistbox selected listbox
bg
and fg
can be:
color0 or black
color1 or red
color2 or green
color3 or brown
color4 or blue
color5 or magenta
color6 or cyan
color7 or lightgray
color8 or gray
color9 or brightred
color10 or brightgreen
color11 or yellow
color12 or brightblue
color13 or brightmagenta
color14 or brightcyan
color15 or white
Example displaying a message box with red window background:
#!/bin/sh
NEWT_COLORS='
window=,red
border=white,red
textbox=white,red
button=black,white
' \
whiptail --msgbox "passwords don't match" 0 0
Appending to ubuntu colors:
#!/bin/bash
readarray -t newtcols < /etc/newt/palette
newtcols_error=(
window=,red
border=white,red
textbox=white,red
button=black,white
)
NEWT_COLORS="${newtcols[@]} ${newtcols_error[@]}" \
whiptail --msgbox "passwords don't match" 0 0
Related videos on Youtube
Eric
Updated on September 18, 2022Comments
-
Eric over 1 year
How would one change the background color on the fly for Whiptail. For example red, green, or yellow, Blue seams to be a lack of color. I checked How to get rid of purple background color in newt apps? which really breaks the system. If you want permanent blue it is OK.
I know that it can be done as when you install Ubuntu they change the background color when you don't get matching passwords for example. Non of the manuals for Whiptail discuss how.
I do know that it deal with newt as this is its base, but even there they don't tell you how.
-
Eric almost 8 yearsYes works except for one thing the root background goes to blue, I tried to add root to NEWT_COLORS but the root background goes to black. What is the variable to get the root background to magenta like Ubuntu uses?
-
Admin almost 8 years
root=,magenta
. Please note that there is only 1 override that takes place. If you setNEWT_COLORS
none of the overrides takes place. -
Eric almost 8 yearsI did exactly that and it makes the background black. I also found out that if you don't do NEWT_COLORS on all whiptail windows they are black background. Which means that it affects all whiptails.
-
Admin almost 8 years@Eric, if you set an invalid color to an elements it makes it black. i.e.
root=,mageta
would make root window black. -
Eric almost 8 yearsThere must be a problem with Ubuntu 14.04 as I get the black background for root. When I do it in Ubuntu 16.04 it works perfectly (magenta root background). Would you know if there is a difference between the two?
-
Admin almost 8 years@Eric, try
sudo apt-get install --reinstall libnewt0.52
. This will probably fix your problem. -
Eric almost 8 years@Anonis, no go but will be replacing shortly. Question, how would you make an array for "Appending to ubuntu colors:" above so that you can change colors on fly. I have function that I call from for loop things happen so fast that most people would not see that things have changed that is why I would like to change that colors.
-
Admin almost 8 years@Eric, You'll can dynamically change color of each dialog, but you can't after it's displayed. You can create a sequence of dialogs to show progress, or use a gauge. If this does not serve your needs, imho, whiptail is not the tool for the job.