From 280fdac2bc2146a73282b47b2c7ce66c19a0d3f2 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 29 Nov 2005 10:08:41 +0000 Subject: r3555@krups: intrigeri | 2005-11-15 13:59:57 +0100 Moved easydialog.sh to lib/ directory: more code is going to be shared, let's start here. --- lib/Makefile.am | 6 ++ lib/Makefile.in | 290 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/easydialog.sh | 255 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 551 insertions(+) create mode 100644 lib/Makefile.am create mode 100644 lib/Makefile.in create mode 100644 lib/easydialog.sh (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..1a8ed4c --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,6 @@ + +EXTRALIBRARIES = easydialog.sh + +EXTRA_DIST = Makefile.am $(EXTRALIBRARIES) + +dist_pkglib_DATA = $(EXTRALIBRARIES) diff --git a/lib/Makefile.in b/lib/Makefile.in new file mode 100644 index 0000000..d462ea8 --- /dev/null +++ b/lib/Makefile.in @@ -0,0 +1,290 @@ +# Makefile.in generated by automake 1.9.5 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = lib +DIST_COMMON = $(dist_pkglib_DATA) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_CLEAN_FILES = +SOURCES = +DIST_SOURCES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(pkglibdir)" +dist_pkglibDATA_INSTALL = $(INSTALL_DATA) +DATA = $(dist_pkglib_DATA) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BASH = @BASH@ +CFGDIR = @CFGDIR@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__leading_dot = @am__leading_dot@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +EXTRALIBRARIES = easydialog.sh +EXTRA_DIST = Makefile.am $(EXTRALIBRARIES) +dist_pkglib_DATA = $(EXTRALIBRARIES) +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu lib/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu lib/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +uninstall-info-am: +install-dist_pkglibDATA: $(dist_pkglib_DATA) + @$(NORMAL_INSTALL) + test -z "$(pkglibdir)" || $(mkdir_p) "$(DESTDIR)$(pkglibdir)" + @list='$(dist_pkglib_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(dist_pkglibDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(pkglibdir)/$$f'"; \ + $(dist_pkglibDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(pkglibdir)/$$f"; \ + done + +uninstall-dist_pkglibDATA: + @$(NORMAL_UNINSTALL) + @list='$(dist_pkglib_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(pkglibdir)/$$f'"; \ + rm -f "$(DESTDIR)$(pkglibdir)/$$f"; \ + done +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(DATA) +installdirs: + for dir in "$(DESTDIR)$(pkglibdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: install-dist_pkglibDATA + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-dist_pkglibDATA uninstall-info-am + +.PHONY: all all-am check check-am clean clean-generic distclean \ + distclean-generic distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am \ + install-dist_pkglibDATA install-exec install-exec-am \ + install-info install-info-am install-man install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ + pdf-am ps ps-am uninstall uninstall-am \ + uninstall-dist_pkglibDATA uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/lib/easydialog.sh b/lib/easydialog.sh new file mode 100644 index 0000000..0113d9c --- /dev/null +++ b/lib/easydialog.sh @@ -0,0 +1,255 @@ +#!/bin/bash + +# copyright 2002 lmoore@tump.com under the terms of the GNU LGPL. +# additions 2005 collective@riseup.net + +# whiptail has trouble being called in the foo=$(whiptail ...) fashion for +# some reason. this is very annoying. this means that we need to use +# temporary files to store the answers from the input and list based boxes +# and then read the answers into a REPLY variable. that just really +# stinks, oh well, that's what you get when you have a weak link +# implementation... +# +# inputBox and passwordBox could be refactored to use a common function + +test -z "$WIDTH" && WIDTH=0 +test -z "$HEIGHT" && HEIGHT=0 +BACKTITLE="" +DIALOG=dialog +HELP= + +setApplicationTitle() { + BACKTITLE=$* +} + +setHelp() { + HELP="$@" +} + +setDimension() { + WIDTH=$1 + HEIGHT=$2 +} + +booleanBox() { + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + `[ "$3" == no ] && echo '--defaultno'` --yesno "$2" $HEIGHT $WIDTH +} + +msgBox() { + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + --msgbox "$2" $HEIGHT $WIDTH +} + +gaugeBox() { + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + --gauge "$2" $HEIGHT $WIDTH 0 +} + +inputBox() { + local temp=$(mktemp -t) || exit 1 + trap "rm -f $temp" 0 + REPLY= + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp + local status=$? + [ $status = 0 ] && REPLY=$(cat $temp) + rm -f $temp + return $status +} + +# Xdialog and {dialog,whiptail} use different mechanism to "qoute" the +# values from a checklist. {dialog,whiptail} uses standard double quoting +# while Xdialog uses a "/" as the separator. the slash is arguably better, +# but the double quoting is more standard. anyway, this function can be +# overridden to allow a derived implementation to change it's quoting +# mechanism to the standard double-quoting one. it receives two +# arguements, the file that has the data and the box type. +_listReplyHook() { + cat $1 +} + +# this is the base implementation of all the list based boxes, it works +# out nicely that way. the real function just passes it's arguments to +# this function with an extra argument specifying the actual box that +# needs to be rendered. +_genericListBox() { + local box=$1 + shift 1 + local title=$1 + local text=$2 + shift 2 + local temp=$(mktemp -t) || exit 1 + trap "rm -f $temp" 0 + REPLY= + $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \ + $box "$text" $HEIGHT $WIDTH 10 \ + "$@" 2> $temp + local status=$? + [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box) + rm -f $temp + _DEFAULT= + return $status +} + +setDefault() { + _DEFAULT="--default-item $1" +} + +menuBox() { + _genericListBox --menu "$@" +} + +## a menu box with additional help info displayed +## at the bottom of the window when an item is selected +menuBoxHelp() { + HELP="--item-help" + _genericListBox --menu "$@" + status=$? + HELP= + return $status +} + +## a menu box with an addition button 'help' +menuBoxHelpFile() { + HELP="--help-button" + _genericListBox --menu "$@" + status=$? + HELP= + return $status +} + +checkBox() { + _genericListBox --checklist "$@" +} + +radioBox() { + _genericListBox --radiolist "$@" +} + +textBox() { + $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH +} + +passwordBox() { + local temp=$(mktemp -t) || exit 1 + trap "rm -f $temp" 0 + REPLY= + $DIALOG --backtitle "$BACKTITLE" --title "$1" \ + --passwordbox "$2" $HEIGHT $WIDTH 2> $temp + local status=$? + [ $status = 0 ] && REPLY=$(cat $temp) + rm -f $temp + return $status +} + + +######################################################### +## begin-item-display style lists +## +## these lists are built by calling fuctions multiple times. +## this can make it easier to build your list in a loop +## + +listBegin() { + _menu_title=$1 + _menu_msg=$2 + _menu_items=0 + _menu_text= + _menu_labels= + _menu_status= +} + +listItem() { + _menu_labels[$_menu_items]=$1 + _menu_text[$_menu_items]=$2 + _menu_status[$_menu_items]=$3 # available only for checklist + let "_menu_items += 1" +} + + +## +## takes one of: +## menu, checklist, radiolist +## +listDisplay() { + boxtype=$1 + local temp=$(mktemp -t) || exit 1 + trap "rm -f $temp" 0 + + local label + local text + local status + ( + echo -ne " $HELP $_DEFAULT " + echo -ne " --backtitle '$BACKTITLE' " + echo -ne " --title '$_menu_title' " + echo -ne " --$boxtype '$_menu_msg' " + echo -ne " $HEIGHT $WIDTH 10 " + for ((i=0; i < $_menu_items ; i++)); do + label=${_menu_labels[$i]} + text=${_menu_text[$i]} + status=${_menu_status[$i]} + echo -ne " $label '$text' $status " + done + ) | xargs $DIALOG 2> $temp + + local status=$? + REPLY="" + [ $status = 0 ] && REPLY=`cat $temp` + rm -f $temp + _DEFAULT= + return $status +} + +#################################################### +## FORM + +_form_gap=2 +formBegin() { + _form_title=$1 + _form_items=0 + _form_labels= + _form_text= +} + +formItem() { + _form_labels[$_form_items]=$1 + _form_text[$_form_items]=$2 + let "_form_items += 1" +} + +formDisplay() { + local temp=$(mktemp -t) || exit 1 + + max_length=0 + for ((i=0; i < ${#_form_labels[@]} ; i++)); do + label=${_form_labels[$i]} + length=`expr length $label` + if [ $length -gt $max_length ]; then + max_length=$length + fi + done + let "max_length += 2" + + local xpos=1 + ( + echo -n -e "--form '$_form_title' 0 0 20" + for ((i=0; i < $_form_items ; i++)); do + label=${_form_labels[$i]} + text=${_form_text[$i]} + echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30" + let "xpos += _form_gap" + done + ) | xargs $DIALOG 2> $temp + local status=$? + + REPLY= + if [ $status = 0 ]; then + IFS=$'' + REPLY=`cat $temp` + IFS=$' \t\n' + fi + rm -f $temp + return $status +} -- cgit v1.2.3