| 1 | #!/usr/bin/env perl |
| 2 | |
| 3 | use Term::UI; |
| 4 | use Term::ReadLine; |
| 5 | |
| 6 | my $term = Term::ReadLine->new('brand'); |
| 7 | |
| 8 | my $reply = $term->get_reply( |
| 9 | prompt => 'What is your favourite colour?', |
| 10 | choices => [qw|blue red green|], |
| 11 | default => blue, |
| 12 | ); |
| 13 | |
| 14 | my $bool = $term->ask_yn( |
| 15 | prompt => 'Do you like cookies?', |
| 16 | default => 'y', |
| 17 | ); |
| 18 | |
| 19 | |
| 20 | my $string = q[some_command -option --no-foo --quux='this thing']; |
| 21 | |
| 22 | my ($options,$munged_input) = $term->parse_options($string); |
| 23 | |
| 24 | |
| 25 | ### don't have Term::UI issue warnings -- default is '1' |
| 26 | $Term::UI::VERBOSE = 0; |
| 27 | |
| 28 | ### always pick the default (good for non-interactive terms) |
| 29 | ### -- default is '0' |
| 30 | $Term::UI::AUTOREPLY = 1; |
| 31 | |
| 32 | ### Retrieve the entire session as a printable string: |
| 33 | $hist = Term::UI::History->history_as_string; |
| 34 | $hist = $term->history_as_string; |
| 35 | |
| 36 | |