Tui - Text user interface toolkit
#!/usr/bin/perl use Curses; use Tui; Tui::init; Tui::background; refresh; Tui::msgbox("Title","Message"); my ($label) = new Tui::Label("Label",2,2); my ($entry) = new Tui::Entryfield("Name",2,4,20,20); my ($ok) = new Tui::Button("OK",18,5); my ($form) = new Tui::Form("A form",1,1,27,10,1); $form->add($label,$entry,$ok); my ($result,$widgetno) = $form->run; my ($name) = $entry->data; endwin; print "your name is $name\n";
Described here are some general functions which can be used in a script. They're also used within the other objects.
Initializes some stuff needed for operating the Tui toolkit.
1 none
1 color (defaults to 1)
Draws a box.
1 x1,y1 topleft coordinate 3 x2,y2 bottomright coordinate 4 color 6 style raised or lowered 7 window (defaults to stdscr) 8 keepclear, if true doesn't clear inside
Prints a line on a certain position in a certain color.
1 x coordinate where to print 2 y coordinate where to print 3 line, the text to print 4 color, (defaults to 1) 5 bold, flag whether to use bold
1
Draws a vertical scrollbar
1 x coordinate at the top 2 y coordinate at the top 3 height, the height 4 total, the total of the scale 5 pos, position of thumbnail within the scale 6 color (defaults to 1) 7 win (defaults to stdscr)
Draws a horizontal scrollbar
1 x coordinate at the left 2 y coordinate at the left 3 length, the length 4 total, the total of the scale 5 pos, position of thumbnail within the scale 6 color (defaults to 1) 7 win (defaults to stdscr)
Retrieves the keycode and key.
1 key, contains the actual key 2 keycode, contains a code for special keys
1 home 2 insert 3 delete 4 end 5 pageup 6 pagedown 7 up 8 down 9 right 10 left 11 backspace 12 M-q 13 M-b 14..M-d 15 M-v 16 M-< 17 M-> 18 M-h 19 M-x 20 M-f 21 M-i 22 M-w 23 M-a 24 M-e 50 M-enter 200 $key gives the keypress as a character
Draws a message box with an OK button.
1 title 2 text of the message
Draws a dialog with Yes and No buttons.
1 result, 1 is yes, 0 is no
Draws a dialog box with OK and Cancel buttons
1 title 2 message in the box
1 result, 1 for ok, 0 for cancel
Provide a simple dialog to enter a string.
1 title 2 label text 3 prompt 4 length of the entrypart (defaults to 20) 5 maxlength of the entry (defaults to 20) 6 whether it is a password (* will be echoed) 7 whether to use a cancel button 8 default text (optional)
if no cancel button : 1 the entry otherwise 1 the entry 2 result (1 = ok, 0 is cancel pressed)
an abstract class from which all other widgets are derived
Constructor
1 reference to object
Sets the flag that will make the widget exit when alt-X is pressed
Sets the flag that will make the widget exit when alt-H is pressed
Sets the flag that will make the widget exit when alt-enter is pressed
Sets the flag that will make the widget exit when enter is pressed
Sets $self->{win} to a supplied window.
1 window
returns whether this widget is runnable, labels and boxes are not.
1 boolean whether widget is runnable
Provides a label widget. It can contain several newlines as long as it fits within the provided coordinates.
Inherits from "CLASS Tui::Widget".
Constructor of this class.
1 text which is to be printed 2,3 x,y coordinates 4 color (defaults to 1)
Draws the widget.
Returns whether widget is runnable.
1.0, widget is not runnable
A box, does nothing besides being boxlike;)
Constructor for the box widget
1 x coordinate of left top 2 y coordinate of left top 3 number of columns 4 number of rows 5 color 6 style (raised or lowered)
Draws the box
1 reference of the object
A pushbutton widget.
Constructor of the Button widget.
1 text of label 2 x coordinate 3 y coordinate
Draws the actual button widget.
1 boolean whether the widget has the focus 2 boolean whether it is pushed
Pushes the button, prints it depressed, waits a bit and then redraws it.
Actually run the widget
1 result code
This widget provides a checkbox
Constructor of the checkbox widget.
1 label to be used 2 x coordinate 3 y coordinate 4 if true, the checkbox will be checked
1 reference to the object
Draw the checkbox widget
1 whether the widget has the focus
Toggles the checkbox
Runs the checkbox widget
1 result code of the run
Returns a boolean whether the checkbox is checked
1 result
A radiobutton widget
Radiobutton widget constructor
1 label 2 x coordinate 3 y coordinate
Sets the group to which this radiobutton belongs
1 reference to the Tui::Radiogroup
1 refernece to the object
Draws the widget
1 boolean whether the widget has the focus
Select the radio button, also unsets the selected one in the radiogroup
Returns whether this radiobutton is selected.
1 boolean whether we're selected
Set the button to on or off
1 boolean whether to tunr on or off
Run the radiobutton widget, it makes no sense to use this on its own. You need a radiogroup with it to make any use of it.
1 result of the run operation
Retrieve whether this button was selected.
1 boolean whether it's selected
A class to group radiobuttons together
Doesn't inherit from anything.
Constructor for the radiogroup widget
1 list of readiobutton widgets to add to group
Add radiobuttons to the group.
1 list of radiobuttons to add to the group
Set a certain radiobutton within the group as selected.
1 index of the radiobutton to be selected
Redraws the radiobuttons within the group
Return the index of the radiobutton that is selected.
1 index of the radiobutton that is selected
This is a listbox widget. It will draw scrollbars if need be (and allowed).
Constructor for the listbox widget.
1 label to print in the top 2 x coordinate of lefttop 3 y coordinate of lefttop 4 columns of the box 5 rows of the box
Add some entried to the listbox.
1 list of strings to add.
Turns both scrollbars on or off (they'll only be drawn if necessary)
1 boolean whether to turn them on or off
Turns the horizontal scrollbar on or off
1 boolean whether to turn the scrolbar on or off
Turns the vertical scrollbar on or off
Turns on or off the drawing of a box.
1 boolean whether to draw the box
Sets whether the widget will wrap around or not. Defaults to off.
1 boolean whether to turn it on or off
Set the selected entry
1 index of the entry to be selected
Clears the contents of the list box
Runs the listbox widget
1 result of the run
Returns the index of the selected entry
1 index of the selected entry
This widget is very much like the listbox widget, except that it allows multiple selections.
Inherits from "CLASS Tui::Listbox".
Constructor for the multiple selection listbox widget.
(inherited from "CLASS Tui::Listbox").
Add some entried to the multiple selction listbox.
Set the entries which are to be selected.
1 list of indeces that are to be selected
Draws the multiple selction listbox widget
Runs the multiple selection listbox widget
Return a list of indeces of the selected entries
1 list of selected entries (the index of them!)
This widget is sometimes also known als a combobox. When it recieved the focus, a listbox will dropdown where the user can make a choice. The only restriction is that the dropbox MUST fit into the Form where it is used when used within a form.
Contructor for the dropbox widget
1 x coordinate of the left top 2 y coordinate of the left top 3 width of the widget 4 heigth of the dropbox (defaults to 6)
Adds a list of entries to the dropbox
1 list of strings to add
Set the selction in the dropbox.
Turns on or off both scrollbars (they're on by default but will only be drawn if needed).
Turn on or off the horizontal scrollbar (it's on by default)
1 refrence to the object
Turn on or off the vertical scrollbar (it's on by default)
Draws the dropbox widget
1 boolean indicating whether this widget has the focus
Runs the dropbox widget
A widget for entering text. The entered line can be longer than would fit in the widget, it'll scroll as need be.
1 label to print before entryfield 2 x coordinate 3 y coordinate 4 length of the widget 5 maximum length of the text 6 default text
This will set the default text of the entryfield widget.
1 the text
Acutally draws the widget.
1 boolean whether the widget has focus
This draws the actual text.
Runs the widget.
Retrieve the data entered in the widget.
1 text entered
A widget for entering passwords. Provides pretty much the same functionality as the Entryfield widgets, except that entered characters are shown with a '*'.
Inherits from "CLASS Tui::Entryfield".
This widget is a spinner, it contains a value and can be in-/decreased with the cursor keys.
Constructo for the spinner widget.
1 label 2 x coordinate 3 y coordinate 4 width 5 value
Sets the step value of a spinner widget.
1 step value
Sets the floor and ceiling value of a spinner widget.
1 floor 2 ceiling
Set the value of the spinner.
1 value
Retireves the value of the widget
Actually draws the widget.
1 boolean whether it has the focus or not
Runs the spiner widget
This is a widget that'll show some text. The text can be larger than the widget, it provides scrollbars if need be.
Constructor for the viewarea widget.
1 x coordinate of left top 2 y coordinate of left top 3 number of collumns 4 number of rows 5 boolean whether to draw a border
Sets the text of the viewarea widget
1 text in 1 string, it'll be split on newlines
Turns horizontal scrollbar on or off.(defaults to on)
1 boolean whether to turn it off or on
Turns vertical scrollbar on or off.(defaults to on)
Turns on or off the position (percent) indicator for the widget It defaults to on.
1 boolean whether to turn on or off
Draws the viewarea widget.
1 boolean whether widget has the focus
Moves the cursor a supplied amount.
1 delta x 2 delta y
Actually runs the widget.
This widget is a small editor. It provides some basic editor functionality. The following keys are supported:
cursor keys : movement alt-a : beginning of line alt-e : end of line backspace : delete the character before the cursor alt-d : delete the character at the cursor tab : move on to the next widget
Constructor for the Editarea widget
1 x coordinate of left top 2 y coordinate of left top 3 number of collumns 4 number of rows 5 whether to draw a border
Sets the default text in the editarea.
1 the text as 1 string
Turns horizontal scrollbar on or of (defaults to on)
Turns vertical scrollbar on or of (defaults to on)
Turn on or off the position indicator (on by default)
Returns the text as 1 string
Draws the editarea widget.
1 boolean whether the widget has the focus 3 boolean whether to NOT clear the inside (just redraw the border and scrollbars)
Redraws the text, not the box and possible scrollbars.
Adjust xpos and xstart if needed. Makes sure that the current cursor position is within the view
Insert a newline at the cursor.
1 x coordinate 2 y coordinate 3 boolean whether to leave xpos and ypos (for fute extension)
Insert a character at the cursor taking into account the insertmode
1 the character to be inserted
Delete the character before the cursor
Delete a character at the cursor
Move the cursor within the editarea according to 2 delta's
Actuall run the editarea widget
A sub menu widget. This is used by "CLASS Tui::Menubar".
Constructor for the menu widget, this is actually meant as a sub menu.
1 x coordinate of the left top 2 y coordinate of the left top 3 window of the parent 4 list of entries to put in menu
Draws the Menu widget. You shouldn't need to call this, the run method will.
Actually runs the sub menu.
1 result of the window which can be 1 of the following 1 entry was selected 2 menu is closed now 3 we moved right 4 we moved left 2 last chosen entry
Hide the submenu. You shouldn't need to call this normally.
1 reference to the object.
The name says it all, this is a menubar.
Constructor for the menubar widget.
1 x coordinate of left top (default 0) 2 y coordinate of left top (default 0) 3 cols (default whole screen width)
Adds a menu to the menubar.
1 name of the submenu 2..N list of entries in the submenu
Clears all the menus in the bar.
Draws the menubar.
1 boolean whether the menubar has the focus 2 index of the menu that is opened (and there's no focus)
Opens a submenu
1 result that came back from the submenu 2 entry that came back from the submenu
Runs the menubar, basically keeps running it until you make a choice.
1 index of the menu you chose from 2 index of the entry within the sub menu
Class which provides a dialog form. Widgets can be added to it after which it can be run. When it exits, the content of the widgets can be retrieved.
Tui::Form contructor
1 title of the form 2 x coordinate of left top 3 y coordinate of left top 4 number of collumns 5 number of rows 6 boolean whether to center window 7 boolean whether to exit on alt-enter (default false) 8 boolean whether to exit on alt-x (default false) 9 boolean whether to exit on alt-h (default false)
Add widgets to a form. The order in which they are added also sets the tab order. The first widget to be added gets the focus first. (unless Tui::Form::setfocus is used).
1 list of widgets
Sets the initial focus to the widget as supplied by index
1 index of the widget to get initial focus
Draw a form, draws the form and makes each widget draw itself.
Prints a string in a form.
1 text 2 x coordinate 3 y coordinate 4 color 5 boolean whether to do it bold
1 reference tot he object
Prints a character in a form.
1 character 2 x coordinate 3 y coordinate 4 color 5 boolean whether to do it bold
Returns the window in which th form operates.
1 handle of the window
Runs the form.
1 boolean whether to leave the dialog after run returns.
1 resultcode 2 widgetnumber The result can be anyone of : 8 enter pressed 9 alt-x pressed 10 alt-h pressed 11 alt-enter pressed
Hide the form dialog.
Written by Ronald F. Lens ( ronald@ronaldlens.com )
The home page is at http://www.ronaldlens.com/tui.html
Finish pod documentation, perhaps a tutorial. Document the code more itself (don't know whether I'll understand it myself in time;). Navigating between the widgets with cursor keys where possible. Clean up the code (there is a lot of duplicate code) Make use of hardware scrolling in windows. Use the panel library, overlapping windows! Dialog builder. Get the code to live through a use strict;)
Added "CLASS Tui::Menu" and "CLASS Tui::Menubar" classes
Added Tui_Form_xyprint and Tui_Form_xyprintchar method
Added Tui_Form_setfocus method.
Added a lot of poddocs.
Fixed some small bugs in the default dailogs (they didn't return the correct values)
Added Tui_Listbox_reset method.
Fixed some bugs with misspelled variable names.
Finished initial version, added lots of poddoc.
To install Tui, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tui
CPAN shell
perl -MCPAN -e shell install Tui
For more information on module installation, please visit the detailed CPAN module installation guide.