.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Clui 3pm" .TH Clui 3pm "2014-07-12" "perl v5.18.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Term::Clui.pm \- Perl module offering a Command\-Line User Interface .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 6 \& use Term::Clui; \& $chosen = choose("A Title", @a_list); # single choice \& @chosen = choose("A Title", @a_list); # multiple choice \& # multi\-line question\-texts are possible... \& $x = choose("Which ?\en(Mouse, or Arrow\-keys and Return)", @w); \& $x = choose("Which ?\en".help_text(), @w); \& \& if (confirm($text)) { do_something(); }; \& \& $answer = ask($question); \& $answer = ask($question,$suggestion); \& $password = ask_password("Enter password:"); \& $filename = ask_filename("Which file ?"); # with Tab\-completion \& \& $newtext = edit($title, $oldtext); \& edit($filename); \& \& view($title, $text) # if $title is not a filename \& view($textfile) # if $textfile _is_ a filename \& \& edit(choose("Edit which file ?", grep(\-T, readdir D))); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Term::Clui offers a high-level user interface to give the user of command-line applications a consistent \*(L"look and feel\*(R". Its metaphor for the computer is as a human-like conversation-partner, and as each question/response is completed it is summarised onto one line, and remains on screen, so that the history of the session gradually accumulates on the screen and is available for review, or for cut/paste. This user interface can therefore be intermixed with standard applications which write to \s-1STDOUT\s0 or \s-1STDERR,\s0 such as \fImake\fR, \fIpgp\fR, \fIrcs\fR etc. .PP For the user, \fI\fIchoose()\fI\fR uses either (since 1.50) the mouse; or arrow keys (or hjkl) and Return; also \fBq\fR to quit, and SpaceBar or Button3 to highlight multiple choices. \&\fI\fIconfirm()\fI\fR expects y, Y, n or N. In general, ctrl-L redraws the (currently active bit of the) screen. \&\fI\fIedit()\fI\fR and \fI\fIview()\fI\fR use the default \s-1EDITOR\s0 and \s-1PAGER\s0 if possible. .PP It's fast, simple, and has few external dependencies. It doesn't use \fIcurses\fR (which is a whole-of-screen interface); it uses a small subset of vt100 sequences (up down left right normal and reverse) which are very portable, and also (since 1.50) the \fI\s-1SET_ANY_EVENT_MOUSE\s0\fR and \fIkmous\fR (terminfo) sequences, which are supported by all \fIxterm\fR, \fIrxvt\fR, \fIkonsole\fR, \fIscreen\fR, \&\fIlinux\fR, \fIgnome\fR and \fIputty\fR terminals. .PP There is an associated file selector, Term::Clui::FileSelect .PP Since version 1.60, a speaking interface is provided for the visually-impaired user; it employs \fIeflite\fR or \fIespeak\fR. Speech is turned on if the \fI\s-1CLUI_SPEAK\s0\fR environment variable is set to any non-empty string. Since version 1.62, if \fIspeakup\fR is running, it is silenced while Term::Clui runs, and then restored. Because Term::Clui's metaphor for the computer is a human-like conversation-partner, this works very naturally. The application needs no modification. .PP There is an equivalent Python3 module, with (as far as possible) the same calling interface, at http://cpansearch.perl.org/src/PJB/Term\-Clui\-1.69/py/TermClui.py .PP This is Term::Clui.pm version 1.69 .SH "WINDOW-SIZE" .IX Header "WINDOW-SIZE" Term::Clui attempts to handle the \s-1WINCH\s0 signal. If the window size is changed, then as soon as the user enters the next keystroke (such as ctrl-L) the current question/response will be redisplayed to fit the new size. .PP The first line of the question, the one which will remain on-screen, is not re-formatted, but is left to be dealt with by the width of the window. Subsequent lines are split into blank-separated words which are filled into the available width; lines beginning with white-space are treated as the beginning of a new indented paragraph, individual words which will not fit onto one line are truncated, and successive blank lines are collapsed into one. If the question will not fit within the available rows, it is truncated. .PP If the available choice items in a \fI\fIchoose()\fI\fR overflow the screen, the user is asked to enter \*(L"clue\*(R" letters, and as soon as the items matching them will fit onto the screen they are displayed as a choice. .SH "SUBROUTINES" .IX Header "SUBROUTINES" .ie n .IP "\fIask\fR( $question ); \s-1OR \s0\fIask\fR( $question, $default );" 3 .el .IP "\fIask\fR( \f(CW$question\fR ); \s-1OR \s0\fIask\fR( \f(CW$question\fR, \f(CW$default\fR );" 3 .IX Item "ask( $question ); OR ask( $question, $default );" Asks the user the question and returns a string answer, with no newline character at the end. If the optional second argument is present, it is offered to the user as a default. If the \fI\f(CI$question\fI\fR is multi-line, the entry-field is at the top to the right of the first line, and the subsequent lines are formatted within the screen width and displayed beneath, as with \fIchoose\fR. .Sp For the user, left and right arrow keys move backward and forward through the string, delete and backspace erase the previous character, ctrl-A moves to the beginning, ctrl-E to the end, and ctrl-D or ctrl-X clear the current string. .ie n .IP "\fIask_password\fR( $question );" 3 .el .IP "\fIask_password\fR( \f(CW$question\fR );" 3 .IX Item "ask_password( $question );" Does the same with no echo, as used for password entry. .ie n .IP "\fIask_filename\fR( $question );" 3 .el .IP "\fIask_filename\fR( \f(CW$question\fR );" 3 .IX Item "ask_filename( $question );" Uses \fITerm::ReadLine::Gnu\fR to provide filename-completion with the \fITab\fR key, but also displays multi-line questions in the same way as \fIask\fR and \fIchoose\fR do. This function was introduced in version 1.65. .ie n .IP "\fIchoose\fR( $question, @list );" 3 .el .IP "\fIchoose\fR( \f(CW$question\fR, \f(CW@list\fR );" 3 .IX Item "choose( $question, @list );" Displays the question, and formats the list items onto the lines beneath it. .Sp If \fIchoose\fR is called in a scalar context, the user can choose an item using arrow keys (or hjkl) and Return, or cancel the choice with a \*(L"q\*(R". \&\fIchoose\fR then returns the chosen item, or \fIundefined\fR if the choice was cancelled. .Sp If \fIchoose\fR is called in an array context, the user can also mark an item with the SpaceBar. \&\fIchoose\fR then returns the list of marked items, (including the item highlit when Return was pressed), or an empty array if the choice was cancelled. .Sp A \s-1DBM\s0 database is maintained of the question and its chosen response. The next time the user is offered a choice with the same question, if that response is still in the list it is highlighted as the default; otherwise the first item is highlighted. Different parts of the code, or different applications using \fITerm::Clui.pm\fR can therefore exchange defaults simply by using the same question words, such as \*(L"Which printer ?\*(R". Multiple choices are not remembered, as the danger exists that the user might fail to notice some of the highlit items (for example, all the items might not fit onto one screen). .Sp The database \fI~/.clui_dir/choices\fR or \fI\f(CI$ENV\fI{\s-1CLUI_DIR\s0}/choices\fR is available to be read or written if lower-level manipulation is needed, and the \fI\s-1EXPORT_OK\s0\fR routines \fIget_default\fR($question) and \&\fIset_default\fR($question, \f(CW$choice\fR) should be used for this purpose, as they handle \s-1DBM\s0's problem with concurrent accesses. The whole default database mechanism can be disabled by \&\fICLUI_DIR=OFF\fR if you really want to :\-( .Sp If the items won't fit on the screen, the user is asked to enter a substring as a clue. As soon as the matching items will fit, they are displayed to be chosen as normal. If the user pressed \*(L"q\*(R" at this choice, they are asked if they wish to change their substring clue; if they reply \*(L"n\*(R" to this, choose quits and returns \fIundefined\fR. .Sp If the \f(CW$question\fR is multi-line, The first line is put at the top as usual with the choices arranged beneath it; the subsequent lines are formatted within the screen width and displayed at the bottom. After the choice is made all but the first line is erased, and the first line remains on-screen with the choice appended after it. You should therefore try to arrange multi-line questions so that the first line is the question in short form, and subsequent lines are explanation and elaboration. .ie n .IP "\fIconfirm\fR( $question );" 3 .el .IP "\fIconfirm\fR( \f(CW$question\fR );" 3 .IX Item "confirm( $question );" Asks the question, takes \*(L"y\*(R", \*(L"n\*(R", \*(L"Y\*(R" or \*(L"N\*(R" as a response. If the \f(CW$question\fR is multi-line, after the response, all but the first line is erased, and the first line remains on-screen with \fIYes\fR or \fINo\fR appended after it; you should therefore try to arrange multi-line questions so that the first line is the question in short form, and subsequent lines are explanation and elaboration. Returns true or false. .ie n .IP "\fIedit\fR( $title, $text ); \s-1OR \s0\fIedit\fR( $filename );" 3 .el .IP "\fIedit\fR( \f(CW$title\fR, \f(CW$text\fR ); \s-1OR \s0\fIedit\fR( \f(CW$filename\fR );" 3 .IX Item "edit( $title, $text ); OR edit( $filename );" Uses the environment variable \s-1EDITOR \s0( or \fIvi\fR :\-) Uses \s-1RCS\s0 if directory \s-1RCS/\s0 exists .ie n .IP "\fIsorry\fR( $message );" 3 .el .IP "\fIsorry\fR( \f(CW$message\fR );" 3 .IX Item "sorry( $message );" Similar to \fIwarn \*(L"Sorry, \f(CI$message\fI\en\*(R";\fR .ie n .IP "\fIinform\fR( $message );" 3 .el .IP "\fIinform\fR( \f(CW$message\fR );" 3 .IX Item "inform( $message );" Similar to \fIwarn \*(L"$message\en\*(R";\fR except that it doesn't add the newline at the end if there already is one, and it uses \fI/dev/tty\fR rather than \fI\s-1STDERR\s0\fR if it can. .ie n .IP "\fIview\fR( $title, $text ); \s-1OR \s0\fIview\fR( $filename );" 3 .el .IP "\fIview\fR( \f(CW$title\fR, \f(CW$text\fR ); \s-1OR \s0\fIview\fR( \f(CW$filename\fR );" 3 .IX Item "view( $title, $text ); OR view( $filename );" If the \fI\f(CI$text\fI\fR is longer than a screenful, uses the environment variable \s-1PAGER \s0( or \fIless\fR ) to display it. If it is one or two lines it just omits the title and displays it. Otherwise it uses a simple built-in routine which expects either \*(L"q\*(R" or \fIReturn\fR from the user; if the user presses \fIReturn\fR the displayed text remains on the screen and the dialogue continues after it, if the user presses \*(L"q\*(R" the text is erased. .Sp If there is only one argument and it's a filename, then the user's \s-1PAGER\s0 displays it, except (since 1.65) if it's a \fI.doc\fR file, when either \&\fIwvText\fR, \fIantiword\fR or \fIcatdoc\fR is used to extract its contents first. .ie n .IP "\fIhelp_text\fR( $mode );" 3 .el .IP "\fIhelp_text\fR( \f(CW$mode\fR );" 3 .IX Item "help_text( $mode );" This returns a short help message for the user. If \fImode\fR is \*(L"ask\*(R" then the text describes the keys the user has available when responding to an \fI&ask\fR question; If \fImode\fR is \*(L"multi\*(R" then the text describes the keys and mouse actions the user has available when responding to a multiple-choice \fI&choose\fR question; otherwise, the text describes the keys and mouse actions the user has available when responding to a single-choice \fI&choose\fR. .SH "EXPORT_OK SUBROUTINES" .IX Header "EXPORT_OK SUBROUTINES" The following routines are not exported by default, but are exported under the \fI\s-1ALL\s0\fR tag, so if you need them you should: .PP .Vb 1 \& import Term::Clui qw(:ALL); .Ve .IP "\fIbeep\fR()" 3 .IX Item "beep()" Beeps. .IP "\fItimestamp\fR()" 3 .IX Item "timestamp()" Returns a sortable timestamp string in \*(L"\s-1YYYYMMDD\s0 hhmmss\*(R" form. .ie n .IP "\fIget_default\fR( $question )" 3 .el .IP "\fIget_default\fR( \f(CW$question\fR )" 3 .IX Item "get_default( $question )" Consults the database \fI~/.clui_dir/choices\fR or \&\fI\f(CI$ENV\fI{\s-1CLUI_DIR\s0}/choices\fR and returns the choice that the user made the last time this question was asked. This is better than opening the database directly as it handles \s-1DBM\s0's problem with concurrent accesses. .ie n .IP "\fIset_default\fR( $question, $new_default )" 3 .el .IP "\fIset_default\fR( \f(CW$question\fR, \f(CW$new_default\fR )" 3 .IX Item "set_default( $question, $new_default )" Opens the database \fI~/.clui_dir/choices\fR or \&\fI\f(CI$ENV\fI{\s-1CLUI_DIR\s0}/choices\fR and sets the default response which will be offered to the user made the next time this question is asked. This is better than opening the database directly as it handles \s-1DBM\s0's problem with concurrent accesses. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" It requires Exporter, which is core Perl. It uses Term::ReadKey if it's available; and uses Term::Size if it's available; if not, it tries \fItput\fR before guessing 80x24. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" The environment variable \fI\s-1CLUI_DIR\s0\fR can be used (by programmer or user) to override \fI~/.clui_dir\fR as the directory in which \fI\fIchoose()\fI\fR keeps its database of previous choices. The whole default database mechanism can be disabled by \&\fI\s-1CLUI_DIR\s0 = \s-1OFF\s0\fR if you really want to :\-( .PP If either the \s-1LANG\s0 or the \s-1LC_TYPE\s0 environment variables contain the string \fIutf8\fR or \fIutf\-8\fR (case insensitive), then \fI\fIchoose()\fI\fR and \fI\fIinform()\fI\fR open \fI/dev/tty\fR with a \fIutf8\fR encoding. .PP If the environment variable \fI\s-1CLUI_SPEAK\s0\fR is set or if \fI\s-1EDITOR\s0\fR is set to \fIemacspeak\fR, and if \fIflite\fR is installed, then \fITerm::Clui\fR will use \fIflite\fR to speak its questions and choices out loud. .PP If the environment variable \fI\s-1CLUI_MOUSE\s0\fR is set to \fI\s-1OFF\s0\fR then \fI\fIchoose()\fI\fR will not interpret mouse-clicks as making a choice. The advantage of this is that the mouse can then be used to highlight and paste text from this window as usual. .PP \&\fITerm::Clui\fR also consults the environment variables \&\s-1HOME, LOGDIR, EDITOR\s0 and \s-1PAGER,\s0 if they are set. .SH "EXAMPLES" .IX Header "EXAMPLES" These scripts using Term::Clui and Term::Clui::FileSelect are to be found in the \fIexamples\fR subdirectory of the build directory. .IP "\fIlinux_admin\fR" 3 .IX Item "linux_admin" I use this script a lot at work, for routine system administration of linux boxes, particularly Fedora and Debian. It includes crontab, chkconfig, update\-rc.d, visudo, vipw, starting and stopping daemons, reconfiguring squid samba or apache, editing sysconfig or running any of the system\-config\-* utilities, and much else. .IP "\fIaudio_stuff\fR" 3 .IX Item "audio_stuff" This script offers an arrow-key-and-return interface integrating aplaymidi, cdrecord, cdda2wav, icedax, lame, mkisofs, muscript, normalize, normalize-audio, mpg123, sndfile-play, timidity, wodim and so on, allowing audio files to be ripped, burned, played, or converted between Muscript, \s-1MIDI, WAV\s0 and \s-1MP3\s0 formats. .IP "\fIlogin_shell\fR" 3 .IX Item "login_shell" This script offers the naive user arrow-key-and-return access to a text-based browser, a mail client, a news client, ssh and ftp and various other stuff. .IP "\fItest_script\fR" 3 .IX Item "test_script" This is the test script, as used during development. .IP "\fIchoose\fR" 3 .IX Item "choose" This is a script which wraps Term::Clui::choose for use at the shell-script level. It can either choose between command-line arguments, or, with the \fB\-f\fR (filter) option, between lines of \s-1STDIN,\s0 like grep. A \fB\-m\fR (multiple) option allows multiple-choice. This can be a very useful script, and you may want to copy it into \&\fI/usr/local/bin/\fR or elsewhere in your \s-1PATH.\s0 .SH "AUTHOR" .IX Header "AUTHOR" Peter J Billam www.pjb.com.au/comp/contact.html .SH "CREDITS" .IX Header "CREDITS" Based on some old perl 4 libraries, \fIask.pl\fR, \fIchoose.pl\fR, \&\fIconfirm.pl\fR, \fIedit.pl\fR, \fIsorry.pl\fR, \fIinform.pl\fR and \fIview.pl\fR, which were in turn based on some even older curses-based programs in \fIC\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" .Vb 10 \& Term::Clui::FileSelect \& Term::ReadKey \& Term::Size \& http://www.pjb.com.au/ \& http://invisible\-island.net/xterm/ctlseqs/ctlseqs.html \& http://search.cpan.org/~pjb \& festival(1) \& eflite(1) \& espeak(1) \& espeakup(1) \& edbrowse(1) \& emacspeak(1) \& perl(1) .Ve .PP There is an equivalent Python3 module, with (as far as possible) the same calling interface, at http://cpansearch.perl.org/src/PJB/Term\-Clui\-1.69/py/TermClui.py