mirror of
https://git.freebsd.org/ports.git
synced 2025-06-06 05:10:29 -04:00
By request, add dialog wrapper used to give the ports options dialog
additional features such as: - extended descriptions - auto resizing - compatability with older dialog implementations Submitted by: wblock Reviewed by: ports@
This commit is contained in:
parent
04a589dee4
commit
bdc98b35f5
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=303430
2 changed files with 150 additions and 0 deletions
75
Tools/scripts/dialogwrapper/dialogwrapper.sh
Executable file
75
Tools/scripts/dialogwrapper/dialogwrapper.sh
Executable file
|
@ -0,0 +1,75 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# dialog wrapper script
|
||||||
|
|
||||||
|
AWK="/usr/bin/awk"
|
||||||
|
DIALOG="/usr/bin/dialog"
|
||||||
|
ECHO="/bin/echo"
|
||||||
|
SED="/usr/bin/sed"
|
||||||
|
STTY="/bin/stty"
|
||||||
|
|
||||||
|
# get terminal size
|
||||||
|
size=$( ${STTY} size )
|
||||||
|
visheight="${size%%[$IFS]*}"
|
||||||
|
visheight=$(($visheight-3))
|
||||||
|
listheight=$(($visheight-6))
|
||||||
|
viswidth="${size#*[$IFS]}"
|
||||||
|
viswidth=$(($viswidth-10))
|
||||||
|
descwidth=$(($viswidth-22))
|
||||||
|
|
||||||
|
# test for a minimum version of dialog(1)
|
||||||
|
DIALOG_VER="0"
|
||||||
|
DIALOG_MIN="1.1-20100428"
|
||||||
|
dialogout=$( ${DIALOG} --print-version 2>&1 )
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
DIALOG_VER=$( ${ECHO} "$dialogout" | ${SED} -e 's/^[^0-9]*//' )
|
||||||
|
# only newer versions of dialog have --item-help
|
||||||
|
HAS_ITEM_HELP="1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# escape the menu title
|
||||||
|
TITLE=$( ${AWK} -v title="$2" \
|
||||||
|
'BEGIN { gsub(/'\''/, "'\''\\'\'\''", title); print title }' )
|
||||||
|
|
||||||
|
cmdstr=""
|
||||||
|
[ "${HAS_ITEM_HELP}" ] && cmdstr="--item-help"
|
||||||
|
cmdstr="$cmdstr $1 '$2' $visheight $viswidth $listheight"
|
||||||
|
shift 5
|
||||||
|
|
||||||
|
menulist=$(
|
||||||
|
varlist=
|
||||||
|
_maxvarlen=0
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
var="$1"
|
||||||
|
[ ${#var} -gt $_maxvarlen ] && export _maxvarlen=${#var}
|
||||||
|
varlist="$varlist${varlist:+
|
||||||
|
}$var"
|
||||||
|
# build hashed environment variables
|
||||||
|
export _${var}_desc="$2"
|
||||||
|
export _${var}_val="$3"
|
||||||
|
shift 3
|
||||||
|
done
|
||||||
|
${ECHO} "$varlist" \
|
||||||
|
| ${AWK} -v hasitemhelp="${HAS_ITEM_HELP}" -v viswid="$viswidth" '
|
||||||
|
{
|
||||||
|
var = $1
|
||||||
|
desc = ENVIRON["_" var "_desc"]
|
||||||
|
val = ENVIRON["_" var "_val"]
|
||||||
|
descwid = viswid -(ENVIRON["_maxvarlen"] + 12)
|
||||||
|
extdesc = ""
|
||||||
|
if ( length(desc) > descwid ) {
|
||||||
|
extdesc = substr(desc, descwid)
|
||||||
|
gsub(/'\''/, "'\''\\'\'\''", extdesc)
|
||||||
|
desc = substr(desc, 1, descwid - 1) "+"
|
||||||
|
}
|
||||||
|
gsub(/'\''/, "'\''\\'\'\''", desc)
|
||||||
|
printf "'\''%s'\'' '\''%s'\'' '\''%s'\''", var, desc, val
|
||||||
|
if ( hasitemhelp ) printf " '\''%s'\''", extdesc
|
||||||
|
printf "\n"
|
||||||
|
} '
|
||||||
|
)
|
||||||
|
|
||||||
|
eval ${DIALOG} $cmdstr $menulist
|
||||||
|
status="$?"
|
||||||
|
echo
|
||||||
|
exit $status
|
75
Tools/scripts/dialogwrapper/readme.txt
Normal file
75
Tools/scripts/dialogwrapper/readme.txt
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
Updated August 6, 2012
|
||||||
|
|
||||||
|
Bug fix for use on FreeBSD 8.x supplied by Devin Teske. Thanks!
|
||||||
|
|
||||||
|
|
||||||
|
What is this?
|
||||||
|
|
||||||
|
This is a sh/awk wrapper script to give the ports options setting screen
|
||||||
|
more features:
|
||||||
|
|
||||||
|
Extended descriptions for FreeBSD 8.3+ and 9.0+. Port maintainers can
|
||||||
|
make descriptions longer and more explanatory.
|
||||||
|
|
||||||
|
Auto-sizing of the option screen to fit the terminal window. Wider or
|
||||||
|
taller windows can display more of the descriptions, or more options.
|
||||||
|
Windows smaller than 80x24 also work.
|
||||||
|
|
||||||
|
Older versions of dialog(1) had a bug in displaying descriptions that
|
||||||
|
are longer than the available space. When an old version of dialog is
|
||||||
|
detected, descriptions are cut to the available space. These earlier
|
||||||
|
versions of dialog did not support the --item-help feature used to
|
||||||
|
show extended descriptions, so only the trimmed description will be
|
||||||
|
shown. Descriptions that have been trimmed will still end in a "+" to
|
||||||
|
indicate that part of it has been trimmed.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
|
||||||
|
Download http://www.wonkity.com/~wblock/dialogwrapper/dialogwrapper.sh
|
||||||
|
to /usr/ports/Tools/scripts.
|
||||||
|
|
||||||
|
Make it executable.
|
||||||
|
|
||||||
|
Edit /etc/make.conf:
|
||||||
|
|
||||||
|
DIALOG="/usr/ports/Tools/scripts/dialogwrapper.sh"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Testing long descriptions
|
||||||
|
|
||||||
|
Open a terminal window and resize it, making it narrower than the
|
||||||
|
default 80 columns. Try 60 or 70 columns.
|
||||||
|
|
||||||
|
su to root and run 'make config' for a port that uses long descriptions.
|
||||||
|
For example:
|
||||||
|
|
||||||
|
# cd /usr/ports/audio/xmms2
|
||||||
|
# make config
|
||||||
|
|
||||||
|
Descriptions that are too long to fit in the window are shown ending in
|
||||||
|
a "+". Scroll downward through the settings to see that the missing
|
||||||
|
part of the description is shown at the bottom of the screen.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Testing auto-sizing
|
||||||
|
|
||||||
|
Open a terminal window and resize it, making it taller than the default
|
||||||
|
24 lines. print/ghostscript9 is a good example.
|
||||||
|
|
||||||
|
# cd /usr/ports/print/ghostscript9
|
||||||
|
# make config
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Work remaining to be done
|
||||||
|
|
||||||
|
Cleanup of the code and additional comments.
|
||||||
|
|
||||||
|
Testing.
|
||||||
|
|
||||||
|
The trimming algorithm should break the description on whitespace to
|
||||||
|
improve readability. fold(1) may be an easy way to do that.
|
Loading…
Add table
Reference in a new issue