Date: Fri, 31 Aug 2012 16:04:08 +0000 (UTC) From: Eitan Adler <eadler@FreeBSD.org> To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r303430 - head/Tools/scripts/dialogwrapper Message-ID: <201208311604.q7VG48ge058088@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eadler Date: Fri Aug 31 16:04:08 2012 New Revision: 303430 URL: http://svn.freebsd.org/changeset/ports/303430 Log: 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@ Added: head/Tools/scripts/dialogwrapper/ head/Tools/scripts/dialogwrapper/dialogwrapper.sh (contents, props changed) head/Tools/scripts/dialogwrapper/readme.txt (contents, props changed) Added: head/Tools/scripts/dialogwrapper/dialogwrapper.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/Tools/scripts/dialogwrapper/dialogwrapper.sh Fri Aug 31 16:04:08 2012 (r303430) @@ -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 Added: head/Tools/scripts/dialogwrapper/readme.txt ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/Tools/scripts/dialogwrapper/readme.txt Fri Aug 31 16:04:08 2012 (r303430) @@ -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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201208311604.q7VG48ge058088>