|
|
| |
Term::Choose::Util(3) |
User Contributed Perl Documentation |
Term::Choose::Util(3) |
Term::Choose::Util - TUI-related functions for selecting directories, files,
numbers and subsets of lists.
choose_directories
- Option enchanted removed.
- Options add_dirs, parent_dir and cs_label
removed.
- The option init_dir expects always a decoded string, regardless of
how the option decoded is set.
choose_a_file
- Option enchanted removed.
- Options show_files, parent_dir and cs_label
removed.
- The option init_dir expects always a decoded string, regardless of
how the option decoded is set.
choose_a_directory
- Option enchanted removed.
- Option parent_dir removed.
- The option init_dir expects always a decoded string, regardless of
how the option decoded is set.
Functional interface:
use Term::Choose::Util qw( choose_a_directory );
my $chosen_directory = choose_a_directory();
Object-oriented interface:
use Term::Choose::Util;
my $ob = Term::Choose->new ();
my $chosen_directory = $ob->choose_a_directory();
See "SUBROUTINES".
This module provides TUI-related functions for selecting directories, files,
numbers and subsets of lists.
Values in brackets are default values.
Options are passed as a hash reference. The options argument is
the last (or the only) argument.
Options available for all subroutines
- clear_screen
If enabled, the screen is cleared before the output.
Values: [0],1,2.
- color
Setting color to 1 enables the
support for color and text formatting escape sequences except for the
current selected element. If set to 2, also for
the current selected element the color support is enabled (inverted
colors).
Values: [0],1,2.
- hide_cursor
Hide the cursor
Values: 0,[1].
- info
A string placed on top of of the output.
Default: undef
- mouse
Enable the mouse mode. An item can be chosen with the left
mouse key, the right mouse key can be used instead of the SpaceBar
key.
Values: [0],1.
- prompt
A string placed on top of the available choices.
Default: undef
- back
Customize the string of the menu entry
"back".
Default: "BACK"
- confirm
Customize the string of the menu entry
"confirm".
Default: "CONFIRM".
$ob = Term::Choose::Util->new( { mouse => 1, ... } );
Returns a new Term::Choose::Util object.
Options: all
$chosen_directory = choose_a_directory( { layout => 1, ... } )
With "choose_a_directory" the
user can browse through the directory tree and choose a directory which is
then returned.
To move around in the directory tree:
- select a directory and press
"Return" to enter in the selected
directory.
- choose the ""..""
(parent directory) menu entry to move upwards.
To return the current working-directory as the chosen directory
choose the "confirm" menu entry.
The "back" menu entry causes
"choose_a_directory" to return
nothing.
Options:
- alignment
Elements in columns are aligned to the left if set to
0, aligned to the right if set to
1 and centered if set to
2.
Values: [0],1,2.
- cs_label
The value of cs_label (current selection label) is a
string which is placed in front of the current selection.
Defaults:
"choose_directories": 'Dirs: ',
"choose_a_directory": 'Dir: ',
"choose_a_file": 'File: '. For
"choose_a_number",
"choose_a_subset" and
"settings_menu" the default is
undefined.
The current selection output is placed between the info
string and the prompt string.
- decoded
If enabled, the directory name is returned decoded with
"locale_fs" form Encode::Locale.
Values: 0,[1].
- init_dir
Set the starting point directory. Defaults to the home
directory.
init_dir expects the directory path as a decoded
string.
- layout
See the option layout in Term::Choose
Values: 0,[1],2.
- order
If set to 1, the items are ordered
vertically else they are ordered horizontally.
This option has no meaning if layout is set to
2.
Values: 0,[1].
- show_hidden
If enabled, hidden directories are added to the available
directories.
Values: 0,[1].
$chosen_file = choose_a_file( { show_hidden => 0, ... } )
Choose the file directory and then choose a file from the chosen
directory. To return the chosen file select the "confirm"
menu entry.
Options:
- alignment
Elements in columns are aligned to the left if set to
0, aligned to the right if set to
1 and centered if set to
2.
Values: [0],1,2.
- decoded
If enabled, the directory name is returned decoded with
"locale_fs" form Encode::Locale.
Values: 0,[1].
- filter
If set, the value of this option is used as a glob pattern.
Only files matching this pattern will be displayed.
- init_dir
Set the starting point directory. Defaults to the home
directory.
If the option decoded is enabled (default),
init_dir expects the directory path as a decoded string.
- layout
See the option layout in Term::Choose
Values: 0,[1],2.
- order
If set to 1, the items are ordered
vertically else they are ordered horizontally.
This option has no meaning if layout is set to
2.
Values: 0,[1].
- show_hidden
If enabled, hidden directories are added to the available
directories.
Values: 0,[1].
$chosen_directories = choose_directories( { mouse => 1, ... } )
"choose_directories" is similar
to "choose_a_directory" but it is possible
to return multiple directories.
Options:
- alignment
Elements in columns are aligned to the left if set to
0, aligned to the right if set to
1 and centered if set to
2.
Values: [0],1,2.
- decoded
If enabled, the directory name is returned decoded with
"locale_fs" form Encode::Locale.
Values: 0,[1].
- init_dir
Set the starting point directory. Defaults to the home
directory.
If the option decoded is enabled (default),
init_dir expects the directory path as a decoded string.
- layout
See the option layout in Term::Choose
Values: 0,[1],2.
- order
If set to 1, the items are ordered
vertically else they are ordered horizontally.
This option has no meaning if layout is set to
2.
Values: 0,[1].
- show_hidden
If enabled, hidden directories are added to the available
directories.
Values: 0,[1].
$new = choose_a_number( 5, { cs_label => 'Number: ', ... } );
This function lets you choose/compose a number (unsigned integer)
which is returned.
The fist argument is an integer and determines the range of the
available numbers. For example setting the first argument to 4 would offer a
range from 0 to 9999.
Options:
- cs_label
The value of cs_label (current selection label) is a
string which is placed in front of the current selection.
Defaults: undef
The current selection output is placed between the info
string and the prompt string.
- default_number
Set a default number (unsigned integer in the range of the
available numbers).
Default: undef
- small_first
Put the small number ranges on top.
Default: off
- thousands_separator
Sets the thousands separator.
Default: ","
The current-selection line is shown if cs_label is
defined or as soon as a number has been chosen.
$subset = choose_a_subset( \@available_items, { cs_label => 'new> ', ... } )
"choose_a_subset" lets you
choose a subset from a list.
The first argument is a reference to an array which provides the
available list.
Options:
- all_by_default
If enabled, all elements are selected if CONFIRM is chosen
without any selected elements.
Values: [0],1.
- alignment
Elements in columns are aligned to the left if set to
0, aligned to the right if set to
1 and centered if set to
2.
Values: [0],1,2.
- cs_begin
Current selection: the cs_begin string is placed
between the cs_label string and the chosen elements as soon as an
element has been chosen.
Default: empty string
- cs_end
Current selection: as soon as elements have been chosen the
cs_end string is placed at the end of the chosen elements.
Default: empty string
- cs_label
The value of cs_label (current selection label) is a
string which is placed in front of the current selection.
Default: undef
The current selection output is placed between the info
string and the prompt string.
- cs_separator
Current selection: the cs_separator is placed between
the chosen list elements.
Default: " ,"
- index
If true, the index positions in the available list of the made
choices are returned.
Values: [0],1.
- keep_chosen
If enabled, the chosen items are not removed from the
available choices.
Values: [0],1;
- layout
See the option layout in Term::Choose.
Values: 0,1,[2].
- mark
Expects as its value a reference to an array with indexes.
Elements corresponding to these indexes are pre-selected when
"choose_a_subset" is called.
- order
If set to 1, the items are ordered
vertically else they are ordered horizontally.
This option has no meaning if layout is set to 2.
Values: 0,[1].
- prefix
prefix expects as its value a string. This string is
put in front of the elements of the available list in the menu. The
chosen elements are returned without this prefix.
Default: empty string.
The current-selection line is shown if cs_label is defined
or as soon as elements have been chosen.
To return the chosen subset (as an array reference) select the
"confirm" menu entry.
The "back" menu entry removes the last added
chosen items. If the list of chosen items is empty, "back"
causes "choose_a_subset" to return
nothing.
$menu = [
[ 'enable_logging', "- Enable logging", [ 'NO', 'YES' ] ],
[ 'case_sensitive', "- Case sensitive", [ 'NO', 'YES' ] ],
[ 'attempts', "- Attempts" , [ '1', '2', '3' ] ]
];
$config = {
'enable_logging' => 1,
'case_sensitive' => 1,
'attempts' => 2
};
settings_menu( $menu, $config );
The first argument is a reference to an array of arrays. These
arrays have three elements:
- the unique name of the option
- the prompt string
- an array reference with the available values of the option.
The second argument is a hash reference:
- the keys are the option names
- the values (0 if not defined) are the indexes of
the current value of the respective key/option.
With the optional third argument can be passed these options:
- cs_begin
Current selection: the cs_begin string is placed
between the cs_label string and the chosen elements as soon as an
element has been chosen.
Default: empty string
- cs_end
Current selection: as soon as elements have been chosen the
cs_end string is placed at the end of the chosen elements.
Default: empty string
- cs_label
The value of cs_label (current selection label) is a
string which is placed in front of the current selection.
Default: undef
The current selection output is placed between the info
string and the prompt string.
- cs_separator
Current selection: the cs_separator is placed between
the chosen list elements.
Default: " ,"
When "settings_menu" is called,
it displays for each array entry a row with the prompt string and the
current value. It is possible to scroll through the rows. If a row is
selected, the set and displayed value changes to the next. After scrolling
through the list once the cursor jumps back to the top row.
If the "back" menu entry is chosen,
"settings_menu" does not apply the made
changes and returns nothing. If the "confirm" menu entry is
chosen, "settings_menu" applies the made
changes in place to the passed configuration hash-reference (second
argument) and returns the number of made changes.
Setting the option cs_label to a defined value adds an info
output line.
Requires Perl version 5.10.0 or greater.
Ensure the encoding layer for STDOUT, STDERR and STDIN are set to the correct
value.
You can find documentation for this module with the perldoc command.
perldoc Term::Choose::Util
Matthäus Kiem <cuer2s@gmail.com>
Thanks to the Perl-Community.de <http://www.perl-community.de> and the
people form stackoverflow <http://stackoverflow.com> for the help.
Copyright 2014-2021 Matthäus Kiem.
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl 5.10.0. For details, see the full
text of the licenses in the file LICENSE.
Visit the GSP FreeBSD Man Page Interface. Output converted with ManDoc. |