如何動態改變 Whiptail 的背景顏色。例如紅色、綠色或黃色、藍色接縫是缺乏顏色的。我檢查了如何擺脫蠑螈應用程式中的紫色背景顏色?這確實破壞了系統。如果你想要永久的藍色也可以。
我知道可以這樣做,因為當你安裝 Ubuntu 時,例如,當你沒有獲得匹配的密碼時,它們會更改背景顏色。 Whiptail 的手冊中都沒有討論如何操作。
我確實知道它處理蠑螈,因為這是它的基礎,但即使在那裡他們也沒有告訴你如何處理。
答案1
Whiptail 的內部調色板可以在編譯時透過提供包含顏色定義的檔案的路徑來覆蓋。
在ubuntu中sudo update-alternatives --config newt-palette
提供了一種在ubuntu調色板和原始調色板之間進行選擇的方法。
NEWT_COLORS_FILE
可以透過設定指向替代文件來覆蓋此文件的位置。
此外,可以透過設定NEWT_COLORS
環境變數來覆蓋先前的兩個覆蓋。
定義的結構是:
name=[fg],[bg][;|:|\n|\r|\t]name2=[fg],[bg]]...
name
可:
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
並且fg
可以是:
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
顯示具有紅色視窗背景的訊息框的範例:
#!/bin/sh
NEWT_COLORS='
window=,red
border=white,red
textbox=white,red
button=black,white
' \
whiptail --msgbox "passwords don't match" 0 0
附加到 ubuntu 顏色:
#!/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