Improve the "dialog/rxvt workaround" introduced in r457

Make the workaround less CPU-hungry and also enable it
for screen sessions.
Thanks to Phillip Warner for the extensive feedback, and
to slakmagik for suggesting the use of 'pgrep'.

Signed-off-by: Mauro Giachero <mauro.giachero@gmail.com>
This commit is contained in:
mauro.giachero 2009-02-18 14:44:41 +00:00
parent 334aa785fa
commit 3907e6d45d

View file

@ -45,24 +45,24 @@ CWD="$(pwd)"
SBOVER=svn_r$(cat ${0} | grep '$Id: ' | head -1 | \
sed -e 's/^.*Id: sbopkg \([0-9.]*\) .*$/\1/')
dialog_rxvt_workaround() {
# Dialog and rxvt-based terminals have some problems -- the user often
# has to resize the terminal window to force a redraw, without which
# the dialogs are not drawn on the screen.
# This function enables a workaround, consisting on a background task
dialog_refresh_workaround() {
# Dialog has refresh problems on some terminals (currently known are
# some rxvt-based terminals and screen sessions), preventing correct
# dialogs rendering.
# This function enables a workaround, consisting of a background task
# sending SIGWINCH to any new dialog istance.
# Despite being probably harmless on xterm-based terminals, this function
# should really be called only on problematic terminals.
DIALOG_RXVT_WORKAROUND_SBOPKG_PID=$$
# Despite being probably harmless on "good" terminals, this function
# should really be called only on problematic ones.
DIALOG_REFRESH_WORKAROUND_SBOPKG_PID=$$
( # The background task runs in a separate shell
olddialogs=
while [[ $(ps h --pid $DIALOG_RXVT_WORKAROUND_SBOPKG_PID) ]]; do
dialogs=$(ps h |grep "[0-9]. dialog" |grep -o "^[ 0-9]*")
while [[ $(ps h --pid $DIALOG_REFRESH_WORKAROUND_SBOPKG_PID) ]]; do
dialogs=$(pgrep -x "^dialog$")
if [[ "$dialogs" != "$olddialogs" ]]; then
[[ "$dialogs" ]] && kill -WINCH $dialogs
olddialogs="$dialogs"
fi
sleep 0.1
sleep 0.3
done
) &
}
@ -2883,7 +2883,8 @@ directory_checks
pid_check
if [[ "$DIAG" ]]; then
[[ "$TERM" = "rxvt" ]] && dialog_rxvt_workaround
[[ "$TERM" =~ "^rxvt.*" || "$TERM" =~ "^screen.*" ]] && \
dialog_refresh_workaround
main_menu
cleanup
else