Term-Choose-1.511/0000755000175000001440000000000013237602053012177 5ustar mmusersTerm-Choose-1.511/META.json0000644000175000001440000000272313237602053013624 0ustar mmusers{ "abstract" : "Choose items from a list interactively.", "author" : [ "Matthaeus Kiem " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Term-Choose", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "File::Spec::Functions" : "0", "FindBin" : "0", "Test::Fatal" : "0", "Test::More" : "0", "lib" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "0", "Term::ReadKey" : "0", "Unicode::GCString" : "0", "constant" : "0", "perl" : "5.008003", "strict" : "0", "warnings" : "0" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/kuerbis/Term-Choose.git", "web" : "https://github.com/kuerbis/Term-Choose" } }, "version" : "1.511", "x_serialization_backend" : "JSON::PP version 2.27400_02" } Term-Choose-1.511/META.yml0000644000175000001440000000146513237602053013456 0ustar mmusers--- abstract: 'Choose items from a list interactively.' author: - 'Matthaeus Kiem ' build_requires: File::Spec::Functions: '0' FindBin: '0' Test::Fatal: '0' Test::More: '0' lib: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Term-Choose no_index: directory: - t - inc requires: Carp: '0' Exporter: '0' Term::ReadKey: '0' Unicode::GCString: '0' constant: '0' perl: '5.008003' strict: '0' warnings: '0' resources: repository: https://github.com/kuerbis/Term-Choose.git version: '1.511' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Term-Choose-1.511/lib/0000755000175000001440000000000013237602053012745 5ustar mmusersTerm-Choose-1.511/lib/Term/0000755000175000001440000000000013237602053013654 5ustar mmusersTerm-Choose-1.511/lib/Term/Choose/0000755000175000001440000000000013237602053015074 5ustar mmusersTerm-Choose-1.511/lib/Term/Choose/LineFold.pm0000644000175000001440000001026413237335672017143 0ustar mmuserspackage Term::Choose::LineFold; use warnings; use strict; use 5.008003; our $VERSION = '1.511'; use Exporter qw( import ); our @EXPORT_OK = qw( line_fold print_columns cut_to_printwidth ); use Unicode::GCString; sub print_columns { Unicode::GCString->new( $_[0] )->columns(); } sub cut_to_printwidth { # $_[0] == string, # $_[1] == available width # $_[2] == return the rest (yes/no) my $gc_str = Unicode::GCString->new( $_[0] ); if ( $gc_str->columns() <= $_[1] ) { return $_[0], '' if $_[2]; return $_[0]; } my $left = $gc_str->substr( 0, $_[1] ); my $left_w = $left->columns(); if ( $left_w == $_[1] ) { return $left->as_string, $gc_str->substr( $_[1] )->as_string if $_[2]; return $left->as_string; } if ( $_[1] < 2 ) { die "The terminal width is too small."; } my ( $nr_chars, $adjust ); if ( $left_w > $_[1] ) { $nr_chars = int( $_[1] / 2 ); $adjust = int( ( $nr_chars + 1 ) / 2 ); #$nr_chars = int( $_[1] / 4 * 3 ); #$adjust = int( ( $_[1] + 7 ) / 8 ); } elsif ( $left_w < $_[1] ) { $nr_chars = int( $_[1] + ( $gc_str->length() - $_[1] ) / 2 ); $adjust = int( ( $gc_str->length() - $nr_chars + 1 ) / 2 ); } while ( 1 ) { $left = $gc_str->substr( 0, $nr_chars ); $left_w = $left->columns(); if ( $left_w + 1 == $_[1] ) { my $len_next_char = $gc_str->substr( $nr_chars, 1 )->columns(); if ( $len_next_char == 1 ) { return $gc_str->substr( 0, $nr_chars + 1 )->as_string, $gc_str->substr( $nr_chars + 1 )->as_string if $_[2]; return $gc_str->substr( 0, $nr_chars + 1 )->as_string; } elsif ( $len_next_char == 2 ) { return $left->as_string . ' ' , $gc_str->substr( $nr_chars )->as_string if $_[2]; return $left->as_string . ' '; } } if ( $left_w > $_[1] ) { $nr_chars = int( $nr_chars - $adjust ); } elsif ( $left_w < $_[1] ) { $nr_chars = int( $nr_chars + $adjust ); } else { return $left->as_string, $gc_str->substr( $nr_chars )->as_string if $_[2]; return $left->as_string; } $adjust = int( ( $adjust + 1 ) / 2 ); } } sub line_fold { my ( $string, $avail_width, $init_tab, $subseq_tab ) = @_; #copy for ( $init_tab, $subseq_tab ) { if ( $_ ) { s/\s/ /g; s/\p{C}//g; if ( length > $avail_width / 4 ) { $_ = cut_to_printwidth( $_, int( $avail_width / 2 ) ); } } else { $_ = ''; } } $string =~ s/[^\n\P{Space}]/ /g; $string =~ s/[^\n\P{C}]//g; if ( $string !~ /\n/ && print_columns( $init_tab . $string ) <= $avail_width ) { return $init_tab . $string; } my $trailer = ''; if ( $string =~ /(\n+)\z/ ) { $trailer = $1; } my @paragraph; for my $row ( split "\n", $string ) { my @lines; $row =~ s/\s+\z//; my @words = split( /(?<=\S)(?=\s)/, $row ); my $line = $init_tab; for my $i ( 0 .. $#words ) { if ( print_columns( $line . $words[$i] ) <= $avail_width ) { $line .= $words[$i]; } else { my $tmp; if ( $i == 0 ) { $tmp = $init_tab . $words[$i];; } else { push( @lines, $line ); $words[$i] =~ s/^\s+//; $tmp = $subseq_tab . $words[$i]; } ( $line, my $remainder ) = cut_to_printwidth( $tmp, $avail_width, 1 ); while ( length $remainder ) { push( @lines, $line ); $tmp = $subseq_tab . $remainder; ( $line, $remainder ) = cut_to_printwidth( $tmp, $avail_width, 1 ); } } if ( $i == $#words ) { push( @lines, $line ); } } push( @paragraph, join( "\n", @lines ) ); } return join( "\n", @paragraph ) . $trailer; } 1; __END__ Term-Choose-1.511/lib/Term/Choose/Linux.pm0000644000175000001440000002014213237335707016541 0ustar mmuserspackage Term::Choose::Linux; use warnings; use strict; use 5.008003; our $VERSION = '1.511'; use Term::ReadKey qw( GetTerminalSize ReadKey ReadMode ); use Term::Choose::Constants qw( :linux ); sub new { return bless {}, $_[0]; } sub __get_key_OS { my ( $self, $mouse ) = @_; my $c1 = ReadKey( 0 ); return if ! defined $c1; if ( $c1 eq "\e" ) { my $c2 = ReadKey( 0.10 ); if ( ! defined $c2 ) { return KEY_ESC; } # unused #elsif ( $c3 eq 'A' ) { return VK_UP; } vt 52 #elsif ( $c3 eq 'B' ) { return VK_DOWN; } #elsif ( $c3 eq 'C' ) { return VK_RIGHT; } #elsif ( $c3 eq 'D' ) { return VK_LEFT; } #elsif ( $c3 eq 'H' ) { return VK_HOME; } elsif ( $c2 eq 'O' ) { my $c3 = ReadKey( 0 ); if ( $c3 eq 'A' ) { return VK_UP; } elsif ( $c3 eq 'B' ) { return VK_DOWN; } elsif ( $c3 eq 'C' ) { return VK_RIGHT; } elsif ( $c3 eq 'D' ) { return VK_LEFT; } elsif ( $c3 eq 'F' ) { return VK_END; } elsif ( $c3 eq 'H' ) { return VK_HOME; } elsif ( $c3 eq 'Z' ) { return KEY_BTAB; } else { return NEXT_get_key; } } elsif ( $c2 eq '[' ) { my $c3 = ReadKey( 0 ); if ( $c3 eq 'A' ) { return VK_UP; } elsif ( $c3 eq 'B' ) { return VK_DOWN; } elsif ( $c3 eq 'C' ) { return VK_RIGHT; } elsif ( $c3 eq 'D' ) { return VK_LEFT; } elsif ( $c3 eq 'F' ) { return VK_END; } elsif ( $c3 eq 'H' ) { return VK_HOME; } elsif ( $c3 eq 'Z' ) { return KEY_BTAB; } elsif ( $c3 =~ m/^[0-9]$/ ) { my $c4 = ReadKey( 0 ); if ( $c4 eq '~' ) { if ( $c3 eq '2' ) { return VK_INSERT; } # unused elsif ( $c3 eq '3' ) { return VK_DELETE; } # unused elsif ( $c3 eq '5' ) { return VK_PAGE_UP; } elsif ( $c3 eq '6' ) { return VK_PAGE_DOWN; } else { return NEXT_get_key; } } elsif ( $c4 =~ m/^[;0-9]$/ ) { # response to "\e[6n" my $abs_curs_y = $c3; my $ry = $c4; while ( $ry =~ m/^[0-9]$/ ) { $abs_curs_y .= $ry; $ry = ReadKey( 0 ); } return NEXT_get_key if $ry ne ';'; my $abs_curs_x = ''; my $rx = ReadKey( 0 ); while ( $rx =~ m/^[0-9]$/ ) { $abs_curs_x .= $rx; $rx = ReadKey( 0 ); } if ( $rx eq 'R' ) { #$self->{abs_cursor_x} = $abs_curs_x; # unused $self->{abs_cursor_y} = $abs_curs_y; } return NEXT_get_key; } else { return NEXT_get_key; } } # http://invisible-island.net/xterm/ctlseqs/ctlseqs.html elsif ( $c3 eq 'M' && $mouse ) { my $event_type = ord( ReadKey( 0 ) ) - 32; my $x = ord( ReadKey( 0 ) ) - 32; my $y = ord( ReadKey( 0 ) ) - 32; my $button = $self->__mouse_event_to_button( $event_type ); return NEXT_get_key if $button == NEXT_get_key; return [ $self->{abs_cursor_y}, $button, $x, $y ]; } elsif ( $c3 eq '<' && $mouse ) { # SGR 1006 my $event_type = ''; my $m1; while ( ( $m1 = ReadKey( 0 ) ) =~ m/^[0-9]$/ ) { $event_type .= $m1; } return NEXT_get_key if $m1 ne ';'; my $x = ''; my $m2; while ( ( $m2 = ReadKey( 0 ) ) =~ m/^[0-9]$/ ) { $x .= $m2; } return NEXT_get_key if $m2 ne ';'; my $y = ''; my $m3; while ( ( $m3 = ReadKey( 0 ) ) =~ m/^[0-9]$/ ) { $y .= $m3; } return NEXT_get_key if $m3 !~ m/^[mM]$/; my $button_released = $m3 eq 'm' ? 1 : 0; return NEXT_get_key if $button_released; my $button = $self->__mouse_event_to_button( $event_type ); return NEXT_get_key if $button == NEXT_get_key; return [ $self->{abs_cursor_y}, $button, $x, $y ]; } else { return NEXT_get_key; } } else { return NEXT_get_key; } } else { return ord $c1; } }; sub __mouse_event_to_button { my ( $self, $event_type ) = @_; my $button_drag = ( $event_type & 0x20 ) >> 5; return NEXT_get_key if $button_drag; my $button; my $low_2_bits = $event_type & 0x03; if ( $low_2_bits == 3 ) { $button = 0; } else { if ( $event_type & 0x40 ) { $button = $low_2_bits + 4; # 4,5 } else { $button = $low_2_bits + 1; # 1,2,3 } } return $button; } sub __set_mode { my ( $self, $mouse, $hide_cursor ) = @_; if ( $mouse ) { if ( $mouse == 3 ) { my $return = binmode STDIN, ':utf8'; if ( $return ) { print SET_ANY_EVENT_MOUSE_1003; print SET_EXT_MODE_MOUSE_1005; } else { $mouse = 0; warn "binmode STDIN, :utf8: $!\n"; warn "mouse-mode disabled\n"; } } elsif ( $mouse == 4 ) { my $return = binmode STDIN, ':raw'; if ( $return ) { print SET_ANY_EVENT_MOUSE_1003; print SET_SGR_EXT_MODE_MOUSE_1006; } else { $mouse = 0; warn "binmode STDIN, :raw: $!\n"; warn "mouse-mode disabled\n"; } } else { my $return = binmode STDIN, ':raw'; if ( $return ) { print SET_ANY_EVENT_MOUSE_1003; } else { $mouse = 0; warn "binmode STDIN, :raw: $!\n"; warn "mouse-mode disabled\n"; } } } Term::ReadKey::ReadMode( 'ultra-raw' ); print HIDE_CURSOR if $hide_cursor; return $mouse; }; sub __reset_mode { my ( $self, $mouse, $hide_cursor ) = @_; print SHOW_CURSOR if $hide_cursor; if ( $mouse ) { binmode STDIN, ':encoding(UTF-8)' or warn "binmode STDIN, :encoding(UTF-8): $!\n"; print UNSET_EXT_MODE_MOUSE_1005 if $mouse == 3; print UNSET_SGR_EXT_MODE_MOUSE_1006 if $mouse == 4; print UNSET_ANY_EVENT_MOUSE_1003; } $self->__reset(); Term::ReadKey::ReadMode( 'restore' ); } sub __get_term_size { #my ( $self ) = @_; my ( $width, $height ) = ( GetTerminalSize() )[ 0, 1 ]; return $width - WIDTH_CURSOR, $height; # $width - WIDTH_CURSOR: don't let items reach the right edge of the terminal; # selecting an item which reaches the right edge of the terminal # messes up the output - maybe because the (hidden) terminal-cursor needs a space } sub __get_cursor_position { my ( $self ) = @_; #$self->{abs_cursor_x} = 0; # unused $self->{abs_cursor_y} = 0; print GET_CURSOR_POSITION; } sub __clear_screen { #my ( $self ) = @_; print CLEAR_SCREEN; } sub __clear_to_end_of_screen { #my ( $self ) = @_; print CLEAR_TO_END_OF_SCREEN; } sub __bold_underline { #my ( $self ) = @_; print BOLD_UNDERLINE; } sub __reverse { #my ( $self ) = @_; print REVERSE; } sub __reset { #my ( $self ) = @_; print RESET; } sub __up { #my ( $self ) = @_; print "\e[${_[1]}A"; } sub __left { #my ( $self ) = @_; print "\e[${_[1]}D"; } sub __right { #my ( $self ) = @_; print "\e[${_[1]}C"; } 1; __END__ Term-Choose-1.511/lib/Term/Choose/Constants.pm0000644000175000001440000001005313237335656017421 0ustar mmuserspackage Term::Choose::Constants; use warnings; use strict; use 5.008003; our $VERSION = '1.511'; use Exporter qw( import ); our @EXPORT_OK = qw( ROW COL LF CR HIDE_CURSOR SHOW_CURSOR WIDTH_CURSOR MAX_ROW_MOUSE_1003 MAX_COL_MOUSE_1003 GET_CURSOR_POSITION SET_ANY_EVENT_MOUSE_1003 SET_EXT_MODE_MOUSE_1005 SET_SGR_EXT_MODE_MOUSE_1006 UNSET_ANY_EVENT_MOUSE_1003 UNSET_EXT_MODE_MOUSE_1005 UNSET_SGR_EXT_MODE_MOUSE_1006 BEEP CLEAR_SCREEN CLEAR_TO_END_OF_SCREEN RESET REVERSE BOLD_UNDERLINE NEXT_get_key CONTROL_SPACE CONTROL_A CONTROL_B CONTROL_C CONTROL_D CONTROL_E CONTROL_F CONTROL_H KEY_BTAB CONTROL_I KEY_TAB KEY_ENTER KEY_ESC KEY_SPACE KEY_h KEY_j KEY_k KEY_l KEY_q KEY_Tilde KEY_BSPACE VK_PAGE_UP VK_PAGE_DOWN VK_END VK_HOME VK_LEFT VK_UP VK_RIGHT VK_DOWN VK_INSERT VK_DELETE MOUSE_WHEELED LEFTMOST_BUTTON_PRESSED RIGHTMOST_BUTTON_PRESSED FROM_LEFT_2ND_BUTTON_PRESSED ); our %EXPORT_TAGS = ( choose => [ qw( ROW COL LF CR WIDTH_CURSOR MAX_ROW_MOUSE_1003 MAX_COL_MOUSE_1003 BEEP NEXT_get_key CONTROL_SPACE CONTROL_A CONTROL_B CONTROL_C CONTROL_D CONTROL_E CONTROL_F CONTROL_H KEY_BTAB CONTROL_I KEY_TAB KEY_ENTER KEY_SPACE KEY_h KEY_j KEY_k KEY_l KEY_q KEY_Tilde KEY_BSPACE VK_PAGE_UP VK_PAGE_DOWN VK_END VK_HOME VK_LEFT VK_UP VK_RIGHT VK_DOWN ) ], linux => [ qw( CLEAR_SCREEN CLEAR_TO_END_OF_SCREEN RESET REVERSE BOLD_UNDERLINE HIDE_CURSOR SHOW_CURSOR WIDTH_CURSOR GET_CURSOR_POSITION SET_ANY_EVENT_MOUSE_1003 SET_EXT_MODE_MOUSE_1005 SET_SGR_EXT_MODE_MOUSE_1006 UNSET_ANY_EVENT_MOUSE_1003 UNSET_EXT_MODE_MOUSE_1005 UNSET_SGR_EXT_MODE_MOUSE_1006 NEXT_get_key KEY_BTAB KEY_ESC VK_PAGE_UP VK_PAGE_DOWN VK_END VK_HOME VK_LEFT VK_UP VK_RIGHT VK_DOWN VK_INSERT VK_DELETE ) ], win32 => [ qw( NEXT_get_key CONTROL_SPACE VK_PAGE_UP VK_PAGE_DOWN VK_END VK_HOME VK_LEFT VK_UP VK_RIGHT VK_DOWN VK_INSERT VK_DELETE MOUSE_WHEELED LEFTMOST_BUTTON_PRESSED RIGHTMOST_BUTTON_PRESSED FROM_LEFT_2ND_BUTTON_PRESSED ) ] ); use constant { ROW => 0, COL => 1, }; use constant { LF => "\n", CR => "\r", BEEP => "\a", CLEAR_SCREEN => "\e[H\e[J", CLEAR_TO_END_OF_SCREEN => "\e[0J", RESET => "\e[0m", BOLD_UNDERLINE => "\e[1m\e[4m", REVERSE => "\e[7m", HIDE_CURSOR => "\e[?25l", SHOW_CURSOR => "\e[?25h", WIDTH_CURSOR => 1, }; use constant { GET_CURSOR_POSITION => "\e[6n", SET_ANY_EVENT_MOUSE_1003 => "\e[?1003h", SET_EXT_MODE_MOUSE_1005 => "\e[?1005h", SET_SGR_EXT_MODE_MOUSE_1006 => "\e[?1006h", UNSET_ANY_EVENT_MOUSE_1003 => "\e[?1003l", UNSET_EXT_MODE_MOUSE_1005 => "\e[?1005l", UNSET_SGR_EXT_MODE_MOUSE_1006 => "\e[?1006l", MAX_ROW_MOUSE_1003 => 223, MAX_COL_MOUSE_1003 => 223, MOUSE_WHEELED => 0x0004, LEFTMOST_BUTTON_PRESSED => 0x0001, RIGHTMOST_BUTTON_PRESSED => 0x0002, FROM_LEFT_2ND_BUTTON_PRESSED => 0x0004, }; use constant { NEXT_get_key => -1, CONTROL_SPACE => 0x00, CONTROL_A => 0x01, CONTROL_B => 0x02, CONTROL_C => 0x03, CONTROL_D => 0x04, CONTROL_E => 0x05, CONTROL_F => 0x06, CONTROL_H => 0x08, KEY_BTAB => 0x08, CONTROL_I => 0x09, KEY_TAB => 0x09, KEY_ENTER => 0x0d, KEY_ESC => 0x1b, KEY_SPACE => 0x20, KEY_h => 0x68, KEY_j => 0x6a, KEY_k => 0x6b, KEY_l => 0x6c, KEY_q => 0x71, KEY_Tilde => 0x7e, KEY_BSPACE => 0x7f, VK_PAGE_UP => 33, VK_PAGE_DOWN => 34, VK_END => 35, VK_HOME => 36, VK_LEFT => 37, VK_UP => 38, VK_RIGHT => 39, VK_DOWN => 40, VK_INSERT => 45, # unused VK_DELETE => 46, # unused }; 1; __END__ Term-Choose-1.511/lib/Term/Choose/Win32.pm0000644000175000001440000001351013237335735016346 0ustar mmuserspackage Term::Choose::Win32; use warnings; use strict; use 5.008003; our $VERSION = '1.511'; use Win32::Console qw( STD_INPUT_HANDLE ENABLE_MOUSE_INPUT ENABLE_PROCESSED_INPUT STD_OUTPUT_HANDLE RIGHT_ALT_PRESSED LEFT_ALT_PRESSED RIGHT_CTRL_PRESSED LEFT_CTRL_PRESSED SHIFT_PRESSED FOREGROUND_INTENSITY BACKGROUND_INTENSITY ); use Term::Choose::Constants qw( :win32 ); sub SHIFTED_MASK () { RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED | RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED | SHIFT_PRESSED } sub new { return bless {}, $_[0]; } sub __get_key_OS { my ( $self, $mouse ) = @_; my @event = $self->{input}->Input; my $event_type = shift @event; return NEXT_get_key if ! defined $event_type; if ( $event_type == 1 ) { my ( $key_down, $repeat_count, $v_key_code, $v_scan_code, $char, $ctrl_key_state ) = @event; return NEXT_get_key if ! $key_down; if ( $char ) { if ( $char == 32 && $ctrl_key_state & ( RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED ) ) { return CONTROL_SPACE; } else { return $char; } } else{ if ( $ctrl_key_state & SHIFTED_MASK ) { return NEXT_get_key; } elsif ( $v_key_code == VK_PAGE_UP ) { return VK_PAGE_UP } elsif ( $v_key_code == VK_PAGE_DOWN ) { return VK_PAGE_DOWN } elsif ( $v_key_code == VK_END ) { return VK_END } elsif ( $v_key_code == VK_HOME ) { return VK_HOME } elsif ( $v_key_code == VK_LEFT ) { return VK_LEFT } elsif ( $v_key_code == VK_UP ) { return VK_UP } elsif ( $v_key_code == VK_RIGHT ) { return VK_RIGHT } elsif ( $v_key_code == VK_DOWN ) { return VK_DOWN } elsif ( $v_key_code == VK_INSERT ) { return VK_INSERT } # unused elsif ( $v_key_code == VK_DELETE ) { return VK_DELETE } # unused else { return NEXT_get_key } } } elsif ( $mouse && $event_type == 2 ) { my( $x, $y, $button_state, $control_key, $event_flags ) = @event; my $button; if ( ! $event_flags ) { if ( $button_state & LEFTMOST_BUTTON_PRESSED ) { $button = 1; } elsif ( $button_state & RIGHTMOST_BUTTON_PRESSED ) { $button = 3; } elsif ( $button_state & FROM_LEFT_2ND_BUTTON_PRESSED ) { $button = 2; } else { return NEXT_get_key; } } elsif ( $event_flags & MOUSE_WHEELED ) { $button = $button_state >> 24 ? 5 : 4; } else { return NEXT_get_key; } return [ $self->{abs_cursor_y}, $button, $x, $y ]; } else { return NEXT_get_key; } } sub __set_mode { my ( $self, $mouse, $hide_cursor ) = @_; $self->{input} = Win32::Console->new( STD_INPUT_HANDLE ); $self->{old_in_mode} = $self->{input}->Mode(); $self->{input}->Mode( !ENABLE_PROCESSED_INPUT ) if ! $mouse; $self->{input}->Mode( !ENABLE_PROCESSED_INPUT|ENABLE_MOUSE_INPUT ) if $mouse; $self->{output} = Win32::Console->new( STD_OUTPUT_HANDLE ); $self->{def_attr} = $self->{output}->Attr(); $self->{fg_color} = $self->{def_attr} & 0x7; $self->{bg_color} = $self->{def_attr} & 0x70; $self->{inverse} = ( $self->{bg_color} >> 4 ) | ( $self->{fg_color} << 4 ); $self->{output}->Cursor( -1, -1, -1, 0 ) if $hide_cursor; return $mouse; } sub __reset_mode { my ( $self, $mouse, $hide_cursor ) = @_; # no use for $mouse on win32 if ( defined $self->{input} ) { if ( defined $self->{old_in_mode} ) { $self->{input}->Mode( $self->{old_in_mode} ); delete $self->{old_in_mode}; } $self->{input}->Flush; # workaround Bug #33513: delete $self->{input}{handle}; # } if ( defined $self->{output} ) { $self->__reset; $self->{output}->Cursor( -1, -1, -1, 1 ) if $hide_cursor; #$self->{output}->Free(); delete $self->{output}{handle}; # ? } } sub __get_term_size { my ( $self ) = @_; my ( $term_width, $term_height ) = Win32::Console->new()->Size(); return $term_width - 1, $term_height; } sub __get_cursor_position { my ( $self ) = @_; ( $self->{abs_cursor_x}, $self->{abs_cursor_y} ) = $self->{output}->Cursor(); } sub __set_cursor_position { my ( $self, $col, $row ) = @_; $self->{output}->Cursor( $col, $row ); } sub __clear_screen { my ( $self ) = @_; $self->{output}->Cls( $self->{def_attr} ); } sub __clear_to_end_of_screen { my ( $self ) = @_; my ( $width, $height ) = $self->{output}->Size(); $self->__get_cursor_position(); $self->{output}->FillAttr( $self->{bg_color} | $self->{bg_color}, $width * $height, $self->{abs_cursor_x}, $self->{abs_cursor_y} ); } sub __bold_underline { my ( $self ) = @_; $self->{output}->Attr( $self->{def_attr} | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY ); } sub __reverse { my ( $self ) = @_; $self->{output}->Attr( $self->{inverse} ); } sub __reset { my ( $self ) = @_; $self->{output}->Attr( $self->{def_attr} ); } sub __up { #my ( $self, $rows_up ) = @_; my ( $col, $row ) = $_[0]->__get_cursor_position; $_[0]->__set_cursor_position( $col, $row - $_[1] ); } sub __left { #my ( $self, $cols_left ) = @_; my ( $col, $row ) = $_[0]->__get_cursor_position; $_[0]->__set_cursor_position( $col - $_[1], $row ); } sub __right { #my ( $self, $cols_right ) = @_; my ( $col, $row ) = $_[0]->__get_cursor_position; $_[0]->__set_cursor_position( $col + $_[1], $row ); } 1; __END__ Term-Choose-1.511/lib/Term/Choose.pm0000644000175000001440000015766413237601474015463 0ustar mmuserspackage Term::Choose; use warnings; use strict; use 5.008003; our $VERSION = '1.511'; use Exporter 'import'; our @EXPORT_OK = qw( choose ); use Carp qw( croak carp ); use Term::Choose::Constants qw( :choose ); use Term::Choose::LineFold qw( line_fold print_columns cut_to_printwidth ); no warnings 'utf8'; my $Plugin_Package; BEGIN { if ( $^O eq 'MSWin32' ) { require Term::Choose::Win32; $Plugin_Package = 'Term::Choose::Win32'; } else { require Term::Choose::Linux; $Plugin_Package = 'Term::Choose::Linux'; } } sub new { my $class = shift; my ( $opt ) = @_; croak "new: called with " . @_ . " arguments - 0 or 1 arguments expected" if @_ > 1; my $self = bless {}, $class; if ( defined $opt ) { croak "new: the (optional) argument must be a HASH reference" if ref $opt ne 'HASH'; $self->__validate_and_add_options( $opt ); } $self->{plugin} = $Plugin_Package->new(); return $self; } sub DESTROY { my ( $self ) = @_; $self->__reset_term(); } sub __defaults { my ( $self ) = @_; my $prompt = defined $self->{wantarray} ? 'Your choice:' : 'Close with ENTER'; return { prompt => $prompt, beep => 0, clear_screen => 0, #default => undef, empty => '', hide_cursor => 1, index => 0, justify => 0, keep => 5, layout => 1, #lf => undef, #ll => undef, #mark => undef, #max_height => undef, #max_width => undef, mouse => 0, #no_spacebar => undef, order => 1, pad => 2, page => 1, undef => '', }; } sub __undef_to_defaults { my ( $self ) = @_; my $defaults = $self->__defaults(); for my $option ( keys %$defaults ) { $self->{$option} = $defaults->{$option} if ! defined $self->{$option}; } } sub __valid_options { return { beep => '[ 0 1 ]', clear_screen => '[ 0 1 ]', hide_cursor => '[ 0 1 ]', index => '[ 0 1 ]', order => '[ 0 1 ]', page => '[ 0 1 ]', justify => '[ 0 1 2 ]', layout => '[ 0 1 2 3 ]', mouse => '[ 0 1 2 3 4 ]', keep => '[ 1-9 ][ 0-9 ]*', ll => '[ 1-9 ][ 0-9 ]*', max_height => '[ 1-9 ][ 0-9 ]*', max_width => '[ 1-9 ][ 0-9 ]*', default => '[ 0-9 ]+', pad => '[ 0-9 ]+', pad_one_row => '[ 0-9 ]+', # removed ### lf => 'ARRAY', mark => 'ARRAY', no_spacebar => 'ARRAY', empty => 'Str', prompt => 'Str', undef => 'Str', }; }; sub __validate_and_add_options { my ( $self, $opt ) = @_; return if ! defined $opt; my $valid = $self->__valid_options(); my $sub = ( caller( 1 ) )[3]; $sub =~ s/^.+::(?:__)?([^:]+)\z/$1/; $sub .= ':'; for my $key ( keys %$opt ) { if ( ! exists $valid->{$key} ) { croak "$sub '$key' is not a valid option name"; } next if ! defined $opt->{$key}; if ( $valid->{$key} eq 'ARRAY' ) { croak "$sub $key => the passed value has to be an ARRAY reference." if ref $opt->{$key} ne 'ARRAY'; { no warnings 'uninitialized'; for ( @{$opt->{$key}} ) { /^[0-9]+\z/ or croak "$sub $key => $_ is an invalid array element"; } } if ( $key eq 'lf' ) { croak "$sub $key => too many array elements." if @{$opt->{$key}} > 2; } } elsif ( $valid->{$key} eq 'Str' ) { croak "$sub $key => references are not valid values." if ref $opt->{$key} ne ''; } elsif ( $opt->{$key} !~ m/^$valid->{$key}\z/x ) { croak "$sub $key => '$opt->{$key}' is not a valid value."; } $self->{$key} = $opt->{$key}; } } sub __init_term { my ( $self ) = @_; $self->{mouse} = $self->{plugin}->__set_mode( $self->{mouse}, $self->{hide_cursor} ); } sub __reset_term { my ( $self, $from_choose ) = @_; if ( $from_choose ) { print CR; my $up = $self->{i_row} + $self->{nr_prompt_lines}; $self->{plugin}->__up( $up ) if $up; $self->{plugin}->__clear_to_end_of_screen(); } if ( defined $self->{plugin} ) { $self->{plugin}->__reset_mode( $self->{mouse}, $self->{hide_cursor} ); } if ( defined $self->{backup_opt} ) { my $backup_opt = delete $self->{backup_opt}; for my $key ( keys %$backup_opt ) { $self->{$key} = $backup_opt->{$key}; } } } sub __get_key { my ( $self ) = @_; my $key = $self->{plugin}->__get_key_OS( $self->{mouse} ); return $key if ref $key ne 'ARRAY'; return $self->__mouse_info_to_key( @$key ); } sub config { # DEPRECATED 10.02.2018 my $self = shift; my ( $opt ) = @_; croak "config: called with " . @_ . " arguments - 0 or 1 arguments expected" if @_ > 1; if ( defined $opt ) { croak "config: the argument must be a HASH reference" if ref $opt ne 'HASH'; $self->__validate_and_add_options( $opt ); } } sub choose { if ( ref $_[0] ne 'Term::Choose' ) { return Term::Choose->new()->__choose( @_ ); } my $self = shift; return $self->__choose( @_ ); } sub __choose { my $self = shift; my ( $orig_list_ref, $opt ) = @_; croak "choose: called with " . @_ . " arguments - 1 or 2 arguments expected" if @_ < 1 || @_ > 2; croak "choose: the first argument must be an ARRAY reference" if ref $orig_list_ref ne 'ARRAY'; if ( defined $opt ) { croak "choose: the (optional) second argument must be a HASH reference" if ref $opt ne 'HASH'; $self->{backup_opt} = { map{ $_ => $self->{$_} } keys %$opt }; $self->__validate_and_add_options( $opt ); } if ( ! @$orig_list_ref ) { return; } # ### if ( defined $self->{pad_one_row} ) { print 'Please remove the invalid option "pad_one_row" (see "Changes"/1.509).' . "\n"; print 'Continue with ENTER '; my $p = ; print "\n"; } # ### local $\ = undef; local $, = undef; local $| = 1; $self->{wantarray} = wantarray; $self->__undef_to_defaults(); $self->__copy_orig_list( $orig_list_ref ); $self->__length_longest(); # $self->{col_width} = $self->{length_longest} + $self->{pad}; local $SIG{'INT'} = sub { # my $signame = shift; exit 1; }; $self->__init_term(); $self->__write_first_screen(); GET_KEY: while ( 1 ) { my $key = $self->__get_key(); if ( ! defined $key ) { $self->__reset_term( 1 ); carp "EOT: $!"; return; } my ( $new_width, $new_height ) = $self->{plugin}->__get_term_size(); if ( $new_width != $self->{term_width} || $new_height != $self->{term_height} ) { if ( $self->{ll} ) { return -1; } $self->__copy_orig_list( $orig_list_ref ); $self->{default} = $self->{rc2idx}[$self->{pos}[ROW]][$self->{pos}[COL]]; if ( $self->{wantarray} && @{$self->{marked}} ) { $self->{mark} = $self->__marked_rc2idx(); } print CR; my $up = $self->{i_row} + $self->{nr_prompt_lines}; $self->{plugin}->__up( $up ) if $up; $self->{plugin}->__clear_to_end_of_screen(); $self->__write_first_screen(); next GET_KEY; } next GET_KEY if $key == NEXT_get_key; next GET_KEY if $key == KEY_Tilde; # $self->{rc2idx} holds the new list (AoA) formatted in "__size_and_layout" appropriate to the chosen layout. # $self->{rc2idx} does not hold the values directly but the respective list indexes from the original list. # If the original list would be ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' ) and the new formatted list should be # a d g # b e h # c f # then the $self->{rc2idx} would look like this # 0 3 6 # 1 4 7 # 2 5 # So e.g. the second value in the second row of the new list would be $self->{list}[ $self->{rc2idx}[1][1] ]. # On the other hand the index of the last row of the new list would be $#{$self->{rc2idx}} # or the index of the last column in the first row would be $#{$self->{rc2idx}[0]}. if ( $key == KEY_j || $key == VK_DOWN ) { if ( ! $self->{rc2idx}[$self->{pos}[ROW]+1] || ! $self->{rc2idx}[$self->{pos}[ROW]+1][$self->{pos}[COL]] ) { $self->__beep(); } else { $self->{pos}[ROW]++; if ( $self->{pos}[ROW] <= $self->{p_end} ) { $self->__wr_cell( $self->{pos}[ROW] - 1, $self->{pos}[COL] ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } else { $self->{p_begin} = $self->{p_end} + 1; $self->{p_end} = $self->{p_end} + $self->{avail_height}; $self->{p_end} = $#{$self->{rc2idx}} if $self->{p_end} > $#{$self->{rc2idx}}; $self->__wr_screen(); } } } elsif ( $key == KEY_k || $key == VK_UP ) { if ( $self->{pos}[ROW] == 0 ) { $self->__beep(); } else { $self->{pos}[ROW]--; if ( $self->{pos}[ROW] >= $self->{p_begin} ) { $self->__wr_cell( $self->{pos}[ROW] + 1, $self->{pos}[COL] ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } else { $self->{p_end} = $self->{p_begin} - 1; $self->{p_begin} = $self->{p_begin} - $self->{avail_height}; $self->{p_begin} = 0 if $self->{p_begin} < 0; $self->__wr_screen(); } } } elsif ( $key == KEY_TAB || $key == CONTROL_I ) { if ( $self->{pos}[ROW] == $#{$self->{rc2idx}} && $self->{pos}[COL] == $#{$self->{rc2idx}[$self->{pos}[ROW]]} ) { $self->__beep(); } else { if ( $self->{pos}[COL] < $#{$self->{rc2idx}[$self->{pos}[ROW]]} ) { $self->{pos}[COL]++; $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] - 1 ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } else { $self->{pos}[ROW]++; if ( $self->{pos}[ROW] <= $self->{p_end} ) { $self->{pos}[COL] = 0; $self->__wr_cell( $self->{pos}[ROW] - 1, $#{$self->{rc2idx}[$self->{pos}[ROW] - 1]} ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } else { $self->{p_begin} = $self->{p_end} + 1; $self->{p_end} = $self->{p_end} + $self->{avail_height}; $self->{p_end} = $#{$self->{rc2idx}} if $self->{p_end} > $#{$self->{rc2idx}}; $self->{pos}[COL] = 0; $self->__wr_screen(); } } } } elsif ( $key == KEY_BSPACE || $key == CONTROL_H || $key == KEY_BTAB ) { if ( $self->{pos}[COL] == 0 && $self->{pos}[ROW] == 0 ) { $self->__beep(); } else { if ( $self->{pos}[COL] > 0 ) { $self->{pos}[COL]--; $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] + 1 ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } else { $self->{pos}[ROW]--; if ( $self->{pos}[ROW] >= $self->{p_begin} ) { $self->{pos}[COL] = $#{$self->{rc2idx}[$self->{pos}[ROW]]}; $self->__wr_cell( $self->{pos}[ROW] + 1, 0 ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } else { $self->{p_end} = $self->{p_begin} - 1; $self->{p_begin} = $self->{p_begin} - $self->{avail_height}; $self->{p_begin} = 0 if $self->{p_begin} < 0; $self->{pos}[COL] = $#{$self->{rc2idx}[$self->{pos}[ROW]]}; $self->__wr_screen(); } } } } elsif ( $key == KEY_l || $key == VK_RIGHT ) { if ( $self->{pos}[COL] == $#{$self->{rc2idx}[$self->{pos}[ROW]]} ) { $self->__beep(); } else { $self->{pos}[COL]++; $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] - 1 ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } } elsif ( $key == KEY_h || $key == VK_LEFT ) { if ( $self->{pos}[COL] == 0 ) { $self->__beep(); } else { $self->{pos}[COL]--; $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] + 1 ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } } elsif ( $key == CONTROL_B || $key == VK_PAGE_UP ) { if ( $self->{p_begin} <= 0 ) { $self->__beep(); } else { $self->{p_begin} = $self->{avail_height} * ( int( $self->{pos}[ROW] / $self->{avail_height} ) - 1 );; $self->{p_end} = $self->{p_begin} + $self->{avail_height} - 1; $self->{pos}[ROW] -= $self->{avail_height}; $self->__wr_screen(); } } elsif ( $key == CONTROL_F || $key == VK_PAGE_DOWN ) { if ( $self->{p_end} >= $#{$self->{rc2idx}} ) { $self->__beep(); } else { $self->{p_begin} = $self->{avail_height} * ( int( $self->{pos}[ROW] / $self->{avail_height} ) + 1 ); $self->{p_end} = $self->{p_begin} + $self->{avail_height} - 1; $self->{p_end} = $#{$self->{rc2idx}} if $self->{p_end} > $#{$self->{rc2idx}}; $self->{pos}[ROW] += $self->{avail_height}; if ( $self->{pos}[ROW] >= $#{$self->{rc2idx}} ) { if ( $#{$self->{rc2idx}} == $self->{p_begin} || ! $self->{rest} || $self->{pos}[COL] <= $self->{rest} - 1 ) { if ( $self->{pos}[ROW] != $#{$self->{rc2idx}} ) { $self->{pos}[ROW] = $#{$self->{rc2idx}}; } if ( $self->{rest} && $self->{pos}[COL] > $self->{rest} - 1 ) { $self->{pos}[COL] = $#{$self->{rc2idx}[$self->{pos}[ROW]]}; } } else { $self->{pos}[ROW] = $#{$self->{rc2idx}} - 1; } } $self->__wr_screen(); } } elsif ( $key == CONTROL_A || $key == VK_HOME ) { if ( $self->{pos}[COL] == 0 && $self->{pos}[ROW] == 0 ) { $self->__beep(); } else { $self->{pos}[ROW] = 0; $self->{pos}[COL] = 0; $self->{p_begin} = 0; $self->{p_end} = $self->{p_begin} + $self->{avail_height} - 1; $self->{p_end} = $#{$self->{rc2idx}} if $self->{p_end} > $#{$self->{rc2idx}}; $self->__wr_screen(); } } elsif ( $key == CONTROL_E || $key == VK_END ) { if ( $self->{order} == 1 && $self->{rest} ) { if ( $self->{pos}[ROW] == $#{$self->{rc2idx}} - 1 && $self->{pos}[COL] == $#{$self->{rc2idx}[$self->{pos}[ROW]]} ) { $self->__beep(); } else { $self->{p_begin} = @{$self->{rc2idx}} - ( @{$self->{rc2idx}} % $self->{avail_height} || $self->{avail_height} ); $self->{pos}[ROW] = $#{$self->{rc2idx}} - 1; $self->{pos}[COL] = $#{$self->{rc2idx}[$self->{pos}[ROW]]}; if ( $self->{p_begin} == $#{$self->{rc2idx}} ) { $self->{p_begin} = $self->{p_begin} - $self->{avail_height}; $self->{p_end} = $self->{p_begin} + $self->{avail_height} - 1; } else { $self->{p_end} = $#{$self->{rc2idx}}; } $self->__wr_screen(); } } else { if ( $self->{pos}[ROW] == $#{$self->{rc2idx}} && $self->{pos}[COL] == $#{$self->{rc2idx}[$self->{pos}[ROW]]} ) { $self->__beep(); } else { $self->{p_begin} = @{$self->{rc2idx}} - ( @{$self->{rc2idx}} % $self->{avail_height} || $self->{avail_height} ); $self->{p_end} = $#{$self->{rc2idx}}; $self->{pos}[ROW] = $#{$self->{rc2idx}}; $self->{pos}[COL] = $#{$self->{rc2idx}[$self->{pos}[ROW]]}; $self->__wr_screen(); } } } elsif ( $key == KEY_q || $key == CONTROL_D ) { $self->__reset_term( 1 ); return; } elsif ( $key == CONTROL_C ) { $self->__reset_term( 1 ); print STDERR "^C\n"; exit 1; } elsif ( $key == KEY_ENTER ) { my $index = $self->{index} || $self->{ll}; if ( ! defined $self->{wantarray} ) { $self->__reset_term( 1 ); return; } elsif ( $self->{wantarray} ) { $self->{marked}[$self->{pos}[ROW]][$self->{pos}[COL]] = 1; my $chosen = $self->__marked_rc2idx(); $self->__reset_term( 1 ); return $index ? @$chosen : @{$orig_list_ref}[@$chosen]; } else { my $i = $self->{rc2idx}[$self->{pos}[ROW]][$self->{pos}[COL]]; my $chosen = $index ? $i : $orig_list_ref->[$i]; $self->__reset_term( 1 ); return $chosen; } } elsif ( $key == KEY_SPACE ) { if ( $self->{wantarray} ) { my $locked = 0; if ( $self->{no_spacebar} ) { for my $no_spacebar ( @{$self->{no_spacebar}} ) { if ( $self->{rc2idx}[$self->{pos}[ROW]][$self->{pos}[COL]] == $no_spacebar ) { ++$locked; last; } } } if ( $locked ) { $self->__beep(); } else { $self->{marked}[$self->{pos}[ROW]][$self->{pos}[COL]] = ! $self->{marked}[$self->{pos}[ROW]][$self->{pos}[COL]]; $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } } } elsif ( $key == CONTROL_SPACE ) { if ( $self->{wantarray} ) { if ( $self->{pos}[ROW] == 0 ) { for my $i ( 0 .. $#{$self->{rc2idx}} ) { for my $j ( 0 .. $#{$self->{rc2idx}[$i]} ) { $self->{marked}[$i][$j] = ! $self->{marked}[$i][$j]; } } } else { for my $i ( $self->{p_begin} .. $self->{p_end} ) { for my $j ( 0 .. $#{$self->{rc2idx}[$i]} ) { $self->{marked}[$i][$j] = ! $self->{marked}[$i][$j]; } } } if ( defined $self->{no_spacebar} ) { $self->__marked_idx2rc( $self->{no_spacebar}, 0 ); } $self->__wr_screen(); } else { $self->__beep(); } } else { $self->__beep(); } } } sub __marked_idx2rc { my ( $self, $list_of_indexes, $boolean ) = @_; my $last_list_idx = $#{$self->{list}}; if ( $self->{current_layout} == 3 ) { for my $idx ( @$list_of_indexes ) { next if $idx > $last_list_idx; $self->{marked}[$idx][0] = $boolean; } return; } my ( $row, $col ); my $cols_per_row = @{$self->{rc2idx}[0]}; if ( $self->{order} == 0 ) { for my $idx ( @$list_of_indexes ) { next if $idx > $last_list_idx; $row = int( $idx / $cols_per_row ); $col = $idx % $cols_per_row; $self->{marked}[$row][$col] = $boolean; } } elsif ( $self->{order} == 1 ) { my $rows_per_col = @{$self->{rc2idx}}; my $end_last_full_col = $rows_per_col * ( $self->{rest} || $cols_per_row ); for my $idx ( @$list_of_indexes ) { next if $idx > $last_list_idx; if ( $idx <= $end_last_full_col ) { $row = $idx % $rows_per_col; $col = int( $idx / $rows_per_col ); } else { my $rows_per_col_short = $rows_per_col - 1; $row = ( $idx - $end_last_full_col ) % $rows_per_col_short; $col = int( ( $idx - $self->{rest} ) / $rows_per_col_short ); } $self->{marked}[$row][$col] = $boolean; } } } sub __marked_rc2idx { my ( $self ) = @_; my $idx = []; if ( $self->{order} == 1 ) { for my $col ( 0 .. $#{$self->{rc2idx}[0]} ) { for my $row ( 0 .. $#{$self->{rc2idx}} ) { if ( $self->{marked}[$row][$col] ) { push @$idx, $self->{rc2idx}[$row][$col]; } } } } else { for my $row ( 0 .. $#{$self->{rc2idx}} ) { for my $col ( 0 .. $#{$self->{rc2idx}[$row]} ) { if ( $self->{marked}[$row][$col] ) { push @$idx, $self->{rc2idx}[$row][$col]; } } } } return $idx; } sub __beep { my ( $self ) = @_; print BEEP if $self->{beep}; } sub __copy_orig_list { my ( $self, $orig_list_ref ) = @_; $self->{list} = [ @$orig_list_ref ]; if ( $self->{ll} ) { for ( @{$self->{list}} ) { $_ = $self->{undef} if ! defined $_; } } else { for ( @{$self->{list}} ) { if ( ! $_ ) { $_ = $self->{undef} if ! defined $_; $_ = $self->{empty} if $_ eq ''; } if ( ref ) { $_ = sprintf "%s(0x%x)", ref $_, $_; } s/\p{Space}/ /g; # replace, but don't squash sequences of spaces s/\p{C}//g; } } } sub __length_longest { my ( $self ) = @_; my $list = $self->{list}; if ( $self->{ll} ) { $self->{length_longest} = $self->{ll}; $self->{length} = [ ( $self->{length_longest} ) x @$list ]; } else { my $len = []; my $longest = 0; for my $i ( 0 .. $#$list ) { $len->[$i] = $self->__print_columns( $list->[$i] ); $longest = $len->[$i] if $len->[$i] > $longest; } $self->{length_longest} = $longest; $self->{length} = $len; } } sub __write_first_screen { my ( $self ) = @_; ( $self->{term_width}, $self->{term_height} ) = $self->{plugin}->__get_term_size(); ( $self->{avail_width}, $self->{avail_height} ) = ( $self->{term_width}, $self->{term_height} ); if ( $self->{length_longest} > $self->{avail_width} && $^O ne 'MSWin32' ) { $self->{avail_width} += WIDTH_CURSOR; # + WIDTH_CURSOR: use also the last terminal column if there is only one print-column; # with only one print-column the output doesn't get messed up if an item # reaches the right edge of the terminal on a non-MSWin32-OS } if ( $self->{max_width} && $self->{avail_width} > $self->{max_width} ) { $self->{avail_width} = $self->{max_width}; } if ( $self->{mouse} == 2 ) { $self->{avail_width} = MAX_COL_MOUSE_1003 if $self->{avail_width} > MAX_COL_MOUSE_1003; $self->{avail_height} = MAX_ROW_MOUSE_1003 if $self->{avail_height} > MAX_ROW_MOUSE_1003; } if ( $self->{avail_width} < 1 ) { $self->{avail_width} = 1; } $self->__prepare_promptline(); $self->{pp_row} = $self->{page} ? 1 : 0; $self->{avail_height} -= $self->{nr_prompt_lines} + $self->{pp_row}; if ( $self->{avail_height} < $self->{keep} ) { $self->{avail_height} = $self->{term_height} >= $self->{keep} ? $self->{keep} : $self->{term_height}; } if ( $self->{max_height} && $self->{max_height} < $self->{avail_height} ) { $self->{avail_height} = $self->{max_height}; } $self->__size_and_layout(); if ( $self->{page} ) { $self->__prepare_page_number(); } $self->{avail_height_idx} = $self->{avail_height} - 1; $self->{p_begin} = 0; $self->{p_end} = $self->{avail_height_idx} > $#{$self->{rc2idx}} ? $#{$self->{rc2idx}} : $self->{avail_height_idx}; $self->{i_row} = 0; $self->{i_col} = 0; $self->{pos} = [ 0, 0 ]; $self->{marked} = []; if ( $self->{wantarray} && defined $self->{mark} ) { $self->__marked_idx2rc( $self->{mark}, 1 ); } if ( defined $self->{default} && $self->{default} <= $#{$self->{list}} ) { $self->__set_default_cell(); } if ( $self->{clear_screen} ) { $self->{plugin}->__clear_screen(); } if ( $self->{prompt} ne '' ) { print $self->{prompt_copy}; } $self->__wr_screen(); if ( $self->{mouse} ) { $self->{plugin}->__get_cursor_position(); } $self->{cursor_row} = $self->{i_row}; } sub __prepare_promptline { my ( $self ) = @_; if ( $self->{prompt} eq '' ) { $self->{nr_prompt_lines} = 0; return; } my $init = $self->{lf}[0] ? $self->{lf}[0] : 0; my $subseq = $self->{lf}[1] ? $self->{lf}[1] : 0; $self->{prompt_copy} = line_fold( $self->{prompt}, $self->{avail_width}, ' ' x $init, ' ' x $subseq ); $self->{prompt_copy} .= "\n\r"; $self->{nr_prompt_lines} = $self->{prompt_copy} =~ s/\n/\n\r/g; } sub __size_and_layout { my ( $self ) = @_; my $layout = $self->{layout}; $self->{rc2idx} = []; if ( $self->{length_longest} > $self->{avail_width} ) { $self->{avail_col_width} = $self->{avail_width}; $layout = 3; } else { $self->{avail_col_width} = $self->{length_longest}; } $self->{current_layout} = $layout; my $all_in_first_row = ''; if ( $layout == 0 || $layout == 1 ) { for my $idx ( 0 .. $#{$self->{list}} ) { $all_in_first_row .= $self->{list}[$idx]; $all_in_first_row .= ' ' x $self->{pad} if $idx < $#{$self->{list}}; if ( $self->__print_columns( $all_in_first_row ) > $self->{avail_width} ) { $all_in_first_row = ''; last; } } } if ( $all_in_first_row ) { $self->{rc2idx}[0] = [ 0 .. $#{$self->{list}} ]; } elsif ( $layout == 3 ) { for my $idx ( 0 .. $#{$self->{list}} ) { $self->{rc2idx}[$idx][0] = $idx; } } else { my $tmp_avail_width = $self->{avail_width} + $self->{pad}; # auto_format if ( $layout == 1 || $layout == 2 ) { my $tmc = int( @{$self->{list}} / $self->{avail_height} ); $tmc++ if @{$self->{list}} % $self->{avail_height}; $tmc *= $self->{col_width}; if ( $tmc < $tmp_avail_width ) { $tmc = int( $tmc + ( ( $tmp_avail_width - $tmc ) / 1.5 ) ) if $layout == 1; $tmc = int( $tmc + ( ( $tmp_avail_width - $tmc ) / 4 ) ) if $layout == 2; $tmp_avail_width = $tmc; } } # order my $cols_per_row = int( $tmp_avail_width / $self->{col_width} ); $cols_per_row = 1 if $cols_per_row < 1; $self->{rest} = @{$self->{list}} % $cols_per_row; if ( $self->{order} == 1 ) { my $rows = int( ( @{$self->{list}} - 1 + $cols_per_row ) / $cols_per_row ); my @rearranged_idx; my $begin = 0; my $end = $rows - 1; for my $c ( 0 .. $cols_per_row - 1 ) { --$end if $self->{rest} && $c >= $self->{rest}; $rearranged_idx[$c] = [ $begin .. $end ]; $begin = $end + 1; $end = $begin + $rows - 1; } for my $r ( 0 .. $rows - 1 ) { my @temp_idx; for my $c ( 0 .. $cols_per_row - 1 ) { next if $r == $rows - 1 && $self->{rest} && $c >= $self->{rest}; push @temp_idx, $rearranged_idx[$c][$r]; } push @{$self->{rc2idx}}, \@temp_idx; } } else { my $begin = 0; my $end = $cols_per_row - 1; $end = $#{$self->{list}} if $end > $#{$self->{list}}; push @{$self->{rc2idx}}, [ $begin .. $end ]; while ( $end < $#{$self->{list}} ) { $begin += $cols_per_row; $end += $cols_per_row; $end = $#{$self->{list}} if $end > $#{$self->{list}}; push @{$self->{rc2idx}}, [ $begin .. $end ]; } } } } sub __set_default_cell { my ( $self ) = @_; LOOP: for my $i ( 0 .. $#{$self->{rc2idx}} ) { for my $j ( 0 .. $#{$self->{rc2idx}[$i]} ) { if ( $self->{default} == $self->{rc2idx}[$i][$j] ) { $self->{pos} = [ $i, $j ]; last LOOP; } } } $self->{p_begin} = $self->{avail_height} * int( $self->{pos}[ROW] / $self->{avail_height} ); $self->{p_end} = $self->{p_begin} + $self->{avail_height} - 1; $self->{p_end} = $#{$self->{rc2idx}} if $self->{p_end} > $#{$self->{rc2idx}}; } sub __goto { my ( $self, $newrow, $newcol ) = @_; if ( $newrow > $self->{i_row} ) { print CR, LF x ( $newrow - $self->{i_row} ); $self->{i_row} += ( $newrow - $self->{i_row} ); $self->{i_col} = 0; } elsif ( $newrow < $self->{i_row} ) { $self->{plugin}->__up( $self->{i_row} - $newrow ); $self->{i_row} -= ( $self->{i_row} - $newrow ); } if ( $newcol > $self->{i_col} ) { $self->{plugin}->__right( $newcol - $self->{i_col} ); $self->{i_col} += ( $newcol - $self->{i_col} ); } elsif ( $newcol < $self->{i_col} ) { $self->{plugin}->__left( $self->{i_col} - $newcol ); $self->{i_col} -= ( $self->{i_col} - $newcol ); } } sub __prepare_page_number { my ( $self ) = @_; if ( $#{$self->{rc2idx}} / ( $self->{avail_height} + $self->{pp_row} ) > 1 ) { my $total_pp = int( $#{$self->{rc2idx}} / $self->{avail_height} ) + 1; my $total_pp_w = length $total_pp; $self->{footer_fmt} = '--- Page %0' . $total_pp_w . 'd/' . $total_pp . ' ---'; if ( length( sprintf $self->{footer_fmt}, $total_pp ) > $self->{avail_width} ) { $self->{footer_fmt} = '%0' . $total_pp_w . 'd/' . $total_pp; if ( length( sprintf $self->{footer_fmt}, $total_pp ) > $self->{avail_width} ) { $total_pp_w = $self->{avail_width} if $total_pp_w > $self->{avail_width}; $self->{footer_fmt} = '%0' . $total_pp_w . '.' . $total_pp_w . 's'; } } } else { $self->{avail_height} += $self->{pp_row}; $self->{pp_row} = 0; } } sub __wr_screen { my ( $self ) = @_; $self->__goto( 0, 0 ); $self->{plugin}->__clear_to_end_of_screen(); if ( $self->{pp_row} ) { $self->__goto( $self->{avail_height_idx} + $self->{pp_row}, 0 ); my $pp_line = sprintf $self->{footer_fmt}, int( $self->{p_begin} / $self->{avail_height} ) + 1; print $pp_line; $self->{i_col} += length $pp_line; } for my $row ( $self->{p_begin} .. $self->{p_end} ) { for my $col ( 0 .. $#{$self->{rc2idx}[$row]} ) { $self->__wr_cell( $row, $col ); } } $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } sub __wr_cell { my( $self, $row, $col ) = @_; my $is_current_pos = $row == $self->{pos}[ROW] && $col == $self->{pos}[COL]; my $idx = $self->{rc2idx}[$row][$col]; if ( $#{$self->{rc2idx}} == 0 && $#{$self->{rc2idx}[0]} > 0 ) { my $lngth = 0; if ( $col > 0 ) { for my $cl ( 0 .. $col - 1 ) { my $i = $self->{rc2idx}[$row][$cl]; $lngth += $self->__print_columns( $self->{list}[$i] ); $lngth += $self->{pad}; } } $self->__goto( $row - $self->{p_begin}, $lngth ); $self->{plugin}->__bold_underline() if $self->{marked}[$row][$col]; $self->{plugin}->__reverse() if $is_current_pos; print $self->{list}[$idx]; $self->{i_col} += $self->__print_columns( $self->{list}[$idx] ); } else { $self->__goto( $row - $self->{p_begin}, $col * $self->{col_width} ); $self->{plugin}->__bold_underline() if $self->{marked}[$row][$col]; $self->{plugin}->__reverse() if $is_current_pos; print $self->__unicode_sprintf( $idx ); $self->{i_col} += $self->{avail_col_width}; } $self->{plugin}->__reset() if $self->{marked}[$row][$col] || $is_current_pos; } # Term::Choose_HAE overwrites __valid_options, __defaults, choose, # __copy_orig_list, __wr_cell, __print_columns, __unicode_trim sub __print_columns { #my $self = $_[0]; print_columns( $_[1] ); } sub __unicode_trim { #my $self = $_[0]; cut_to_printwidth( $_[1], $_[2] ); } sub __unicode_sprintf { my ( $self, $idx ) = @_; my $unicode; my $str_length = $self->{length}[$idx]; if ( $str_length > $self->{avail_col_width} ) { if ( $self->{avail_col_width} > 3 ) { $unicode = $self->__unicode_trim( $self->{list}[$idx], $self->{avail_col_width} - 3 ) . '...'; } else { $unicode = $self->__unicode_trim( $self->{list}[$idx], $self->{avail_col_width} ); } } elsif ( $str_length < $self->{avail_col_width} ) { if ( $self->{justify} == 0 ) { $unicode = $self->{list}[$idx] . " " x ( $self->{avail_col_width} - $str_length ); } elsif ( $self->{justify} == 1 ) { $unicode = " " x ( $self->{avail_col_width} - $str_length ) . $self->{list}[$idx]; } elsif ( $self->{justify} == 2 ) { my $all = $self->{avail_col_width} - $str_length; my $half = int( $all / 2 ); $unicode = " " x $half . $self->{list}[$idx] . " " x ( $all - $half ); } } else { $unicode = $self->{list}[$idx]; } return $unicode; } sub __mouse_info_to_key { my ( $self, $abs_cursor_y, $button, $abs_mouse_x, $abs_mouse_y ) = @_; if ( $button == 4 ) { return VK_PAGE_UP; } elsif ( $button == 5 ) { return VK_PAGE_DOWN; } my $abs_y_top_row = $abs_cursor_y - $self->{cursor_row}; if ( $abs_mouse_y < $abs_y_top_row ) { return NEXT_get_key; } my $mouse_row = $abs_mouse_y - $abs_y_top_row; my $mouse_col = $abs_mouse_x; if ( $mouse_row > $#{$self->{rc2idx}} ) { return NEXT_get_key; } my $matched_col; my $end_last_col = 0; my $row = $mouse_row + $self->{p_begin}; COL: for my $col ( 0 .. $#{$self->{rc2idx}[$row]} ) { my $end_this_col; if ( $#{$self->{rc2idx}} == 0 ) { my $idx = $self->{rc2idx}[$row][$col]; $end_this_col = $end_last_col + $self->__print_columns( $self->{list}[$idx] ) + $self->{pad}; } else { # $end_this_col = $end_last_col + $self->{col_width}; } if ( $col == 0 ) { $end_this_col -= int( $self->{pad} / 2 ); } if ( $col == $#{$self->{rc2idx}[$row]} && $end_this_col > $self->{avail_width} ) { $end_this_col = $self->{avail_width}; } if ( $end_last_col < $mouse_col && $end_this_col >= $mouse_col ) { $matched_col = $col; last COL; } $end_last_col = $end_this_col; } if ( ! defined $matched_col ) { return NEXT_get_key; } my $return_char = ''; if ( $button == 1 ) { $return_char = KEY_ENTER; } elsif ( $button == 3 ) { $return_char = KEY_SPACE; } else { return NEXT_get_key; } if ( $row != $self->{pos}[ROW] || $matched_col != $self->{pos}[COL] ) { my $not_pos = $self->{pos}; $self->{pos} = [ $row, $matched_col ]; $self->__wr_cell( $not_pos->[0], $not_pos->[1] ); $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] ); } return $return_char; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Term::Choose - Choose items from a list interactively. =head1 VERSION Version 1.511 =cut =head1 SYNOPSIS Functional interface: use Term::Choose qw( choose ); my $array_ref = [ qw( one two three four five ) ]; my $choice = choose( $array_ref ); # single choice print "$choice\n"; my @choices = choose( [ 1 .. 100 ], { justify => 1 } ); # multiple choice print "@choices\n"; choose( [ 'Press ENTER to continue' ], { prompt => '' } ); # no choice Object-oriented interface: use Term::Choose; my $array_ref = [ qw( one two three four five ) ]; my $new = Term::Choose->new(); my $choice = $new->choose( $array_ref ); # single choice print "$choice\n"; my @choices = $new->choose( [ 1 .. 100 ] ); # multiple choice print "@choices\n"; my $stopp = Term::Choose->new( { prompt => '' } ); $stopp->choose( [ 'Press ENTER to continue' ] ); # no choice =head1 DESCRIPTION Choose interactively from a list of items. C provides a functional interface (L) and an object-oriented interface (L). =head1 EXPORT Nothing by default. use Term::Choose qw( choose ); =head1 METHODS =head2 new $new = Term::Choose->new( [ \%options] ); This constructor returns a new C object. To set the different options it can be passed a reference to a hash as an optional argument. For detailed information about the options see L. =head2 config DEPRECATED $new->config( \%options ); The C method is meant to set the different options. The options are passed as a hash reference. Options set with C overwrite options set with the C method. For detailed information about the different options, their allowed and default values see L. =head2 choose The method C allows the user to choose from a list. The first argument is an array reference which holds the list of the available choices. As a second and optional argument it can be passed a reference to a hash where the keys are the option names and the values the option values. Options set with C overwrite options set with C or C. Before leaving C restores the overwritten options. $choice = $new->choose( $array_ref [, \%options] ); @choices= $new->choose( $array_ref [, \%options] ); $new->choose( $array_ref [, \%options] ); When in the documentation is mentioned "array" or "list" or "elements" or "items" (of the array/list) than these refer to this array passed as a reference as the first argument. For more information how to use C and its return values see L. =head1 SUBROUTINES =head2 choose The function C allows the user to choose from a list. It takes the same arguments as the method L. $choice = choose( $array_ref [, \%options] ); @choices= choose( $array_ref [, \%options] ); choose( $array_ref [, \%options] ); See the L section for more details about the different options and how to set them. See also the following section L. =head1 USAGE AND RETURN VALUES =over =item * If C is called in a I, the user can choose an item by using the L and confirming with C. C then returns the chosen item. =item * If C is called in an I, the user can also mark an item with the C. C then returns - when C is pressed - the list of marked items including the highlighted item. In I C (or C) inverts the choices: marked items are unmarked and unmarked items are marked. If the cursor is on the first row, C inverts the choices for the whole list else C inverts the choices for the current page. =item * If C is called in an I, the user can move around but mark nothing; the output shown by C can be closed with C. Called in void context C returns nothing. If the first argument refers to an empty array, C returns nothing. =back If the items of the list don't fit on the screen, the user can scroll to the next (previous) page(s). If the window size is changed, then as soon as the user enters a keystroke C rewrites the screen. C returns C or an empty list in list context if the C key (or C) is pressed. With a I mode enabled (and if supported by the terminal) the item can be chosen with the left mouse key, in list context the right mouse key can be used instead the C key. =head2 Keys to move around =over =item * the C keys (or the C keys) to move up and down or to move to the right and to the left, =item * the C key (or C) to move forward, the C key (or C or C) to move backward, =item * the C key (or C) to go back one page, the C key (or C) to go forward one page, =item * the C key (or C) to jump to the beginning of the list, the C key (or C) to jump to the end of the list. =back =head2 Modifications for the output For the output on the screen the array elements are modified. All the modifications are made on a copy of the original array so C returns the chosen elements as they were passed to the function without modifications. Modifications: =over =item * If an element is not defined the value from the option I is assigned to the element. =item * If an element holds an empty string the value from the option I is assigned to the element. =item * White-spaces in elements are replaced with simple spaces. $element =~ s/\p{Space}/ /g; =item * If the length of an element is greater than the width of the screen the element is cut. $element = substr( $element, 0, $allowed_length - 3 ) . '...';* * It is used a function to cut strings which uses C from L to determine the string length. =back The following should be without meaning if you comply with the requirements. =over =item * Characters which match the Unicode character property C are removed. $element =~ s/\p{C}//g; C characters are removed by this substitution so it is not possible to color the output with ANSI escape sequences. For colored output see L. =item * If an element is a reference it will be replaced with a string: the reference type followed with the hexadecimal value of the reference enclosed in parentheses. if ( ref $element ) { $element = sprintf "%s(0x%x)", ref $element, $element; } =item * The category of C C is disabled. no warnings 'utf8'; =back =head1 OPTIONS Options which expect a number as their value expect integers. =head2 beep 0 - off (default) 1 - on =head2 clear_screen 0 - off (default) 1 - clears the screen before printing the choices =head2 default With the option I it can be selected an element, which will be highlighted as the default instead of the first element. I expects a zero indexed value, so e.g. to highlight the third element the value would be I<2>. If the passed value is greater than the index of the last array element the first element is highlighted. Allowed values: 0 or greater (default: undefined) =head2 empty Sets the string displayed on the screen instead an empty string. default: "" =head2 hide_cursor 0 - keep the terminals highlighting of the cursor position 1 - hide the terminals highlighting of the cursor position (default) =head2 index 0 - off (default) 1 - return the index of the chosen element instead of the chosen element respective the indices of the chosen elements instead of the chosen elements. =head2 justify 0 - elements ordered in columns are left justified (default) 1 - elements ordered in columns are right justified 2 - elements ordered in columns are centered =head2 keep I prevents that all the terminal rows are used by the prompt lines. Setting I ensures that at least I terminal rows are available for printing list rows. If the terminal height is less than I I is set to the terminal height. Allowed values: 1 or greater (default: 5) =head2 layout From broad to narrow: 0 > 1 > 2 > 3 =over =item * 0 - layout off .----------------------. .----------------------. .----------------------. .----------------------. | .. .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | | | .. .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | | | | | .. .. .. .. .. | | .. .. .. .. .. .. .. | | | | | | | | .. .. .. .. .. .. .. | | | | | | | | .. .. .. .. .. .. .. | | | | | | | | .. .. .. .. .. .. .. | '----------------------' '----------------------' '----------------------' '----------------------' =item * 1 - layout "H" (default) .----------------------. .----------------------. .----------------------. .----------------------. | .. .. .. .. .. .. .. | | .. .. .. .. .. | | .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | | | .. .. .. .. .. | | .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | | | .. .. | | .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | | | | | .. .. .. .. .. .. | | .. .. .. .. .. .. .. | | | | | | .. .. .. | | .. .. .. .. .. .. .. | | | | | | | | .. .. .. .. .. .. .. | '----------------------' '----------------------' '----------------------' '----------------------' =item * 2 - layout "V" .----------------------. .----------------------. .----------------------. .----------------------. | .. .. | | .. .. .. | | .. .. .. .. | | .. .. .. .. .. .. .. | | .. .. | | .. .. .. | | .. .. .. .. | | .. .. .. .. .. .. .. | | .. | | .. .. .. | | .. .. .. .. | | .. .. .. .. .. .. .. | | | | .. .. | | .. .. .. | | .. .. .. .. .. .. .. | | | | | | .. .. .. | | .. .. .. .. .. .. .. | | | | | | | | .. .. .. .. .. .. .. | '----------------------' '----------------------' '----------------------' '----------------------' =item * 3 - all in a single column .----------------------. .----------------------. .----------------------. .----------------------. | .. | | .. | | .. | | .. | | .. | | .. | | .. | | .. | | .. | | .. | | .. | | .. | | | | .. | | .. | | .. | | | | | | .. | | .. | | | | | | | | .. | '----------------------' '----------------------' '----------------------' '----------------------' =back =head2 lf If I lines are folded the option I allows one to insert spaces at beginning of the folded lines. The option I expects a reference to an array with one or two elements: - the first element (C) sets the number of spaces inserted at beginning of paragraphs - a second element (C) sets the number of spaces inserted at the beginning of all broken lines apart from the beginning of paragraphs Allowed values for the two elements are: 0 or greater. See C and C in L. (default: undefined) =head2 ll If all elements have the same length, the length can be passed with this option. If I is set, then C doesn't calculate the length of the longest element itself but uses the value passed with this option. I refers here to the number of print columns the element will use on the terminal. A way to determine the number of print columns is the use of C from L. The length of undefined elements depends on the value of the option I. If the option I is set, only undefined values are replaced. The replacements described in L are not applied. If elements contain unsupported characters the output might break if the width (number of print columns) of the replacement character does not correspond to the width of the replaced character - for example when a unsupported non-spacing character is replaced by a replacement character with a normal width. If I is set to a value less than the length of the elements, the output could break. If the value of I is greater than the screen width, the elements will be trimmed to fit into the screen. If I is set, C returns (in list or scalar context) always the indexes of the chosen items regardless of how I is set. If I is set and the window size has changed, choose returns immediately C<-1>. Allowed values: 1 or greater (default: undefined) =head2 mark I expects as its value a reference to an array. The elements of the array are list indexes. C preselects the list-elements correlating to these indexes. This option has only meaning in list context. Elements greater than the last index of the list are ignored. (default: undefined) =head2 max_height If defined sets the maximal number of rows used for printing list items. If the available height is less than I I is set to the available height. Height in this context means print rows. I overwrites I if I is set to a value less than I. Allowed values: 1 or greater (default: undefined) =head2 max_width If defined, sets the maximal output width to I if the terminal width is greater than I. To prevent the "auto-format" to use a width less than I set I to 0. Width refers here to the number of print columns. Allowed values: 1 or greater (default: undefined) =head2 mouse For MSWin32 see also the end of this section. 0 - no mouse mode (default) 1 - mouse mode 1003 enabled 2 - mouse mode 1003 enabled; the output width is limited to 223 print-columns and the height to 223 rows (mouse mode 1003 doesn't work above 223) 3 - extended mouse mode (1005) - uses utf8 4 - extended SGR mouse mode (1006) If a mouse mode is enabled layers for C are changed. Then before leaving C as a cleanup C is marked as C with C<:encoding(UTF-8)>. This doesn't apply if the OS is MSWin32. If the OS is MSWin32 there is no difference between the mouse modes 1, 3, and 4 - the all enable the mouse with the help of L. =head2 no_spacebar I expects as its value a reference to an array. The elements of the array are indexes of the list which should not be markable with the C or with the right mouse key. This option has only meaning in list context. If an element is preselected with the option I and also marked as not selectable with the option I, the user can not remove the preselection of this element. I elements greater than the last index of the list are ignored. (default: undefined) =head2 order If the output has more than one row and more than one column: 0 - elements are ordered horizontally 1 - elements are ordered vertically (default) Default may change in a future release. =head2 pad Sets the number of whitespaces between columns. (default: 2) Allowed values: 0 or greater =head2 page 0 - off 1 - print the page number on the bottom of the screen if there is more then one page. (default) =head2 prompt If I is undefined a default prompt-string will be shown. If the I value is an empty string ("") no prompt-line will be shown. default in list and scalar context: C default in void context: C =head2 undef Sets the string displayed on the screen instead an undefined element. default: "" =head1 ERROR HANDLING =head2 croak C dies if passed invalid arguments. =head2 carp If after pressing a key L::ReadKey returns C C warns with C and returns I or an empty list in list context. =head1 REQUIREMENTS =head2 Perl version Requires Perl version 5.8.3 or greater. =head2 Decoded strings C expects decoded strings as array elements. =head2 Encoding layer for STDOUT For a correct output it is required an appropriate encoding layer for STDOUT matching the terminal's character set. =head2 Monospaced font It is required a terminal that uses a monospaced font which supports the printed characters. =head2 Escape sequences It is required a terminal that supports ANSI escape sequences. If the option "hide_cursor" is enabled, it is also required the support for the following escape sequences: "\e[?25l" Hide Cursor "\e[?25h" Show Cursor If a I mode is enabled "\e[?1003h", "\e[?1005h", "\e[?1006h" Enable Mouse Tracking "\e[?1003l", "\e[?1005l", "\e[?1006l" Disable Mouse Tracking are used to enable/disable the different I modes. If the OS is MSWin32 L is used, to emulate the behavior of the escape sequences. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Term::Choose =head1 AUTHOR Matthäus Kiem =head1 CREDITS Based on the C function from the L module. Thanks to the L and the people form L for the help. =head1 LICENSE AND COPYRIGHT Copyright (C) 2012-2018 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. =cut Term-Choose-1.511/MANIFEST0000644000175000001440000000231213237602053013326 0ustar mmusersChanges lib/Term/Choose.pm lib/Term/Choose/Constants.pm lib/Term/Choose/LineFold.pm lib/Term/Choose/Linux.pm lib/Term/Choose/Win32.pm LICENSE Makefile.PL MANIFEST This list of files README t/00_load/00-load.t t/01_arguments/01_new.t t/01_arguments/01_new_invalid.t t/01_arguments/02_config.t t/01_arguments/02_config_invalid.t t/01_arguments/Data_Test_Arguments.pm xt/00_get_key_linux.t xt/01_option.t xt/02_option_error.t xt/cntr_choose.t xt/critic.t xt/get_key_linux.pl xt/manifest.t xt/perl_minimum_version.t xt/perlcriticrc xt/pod-coverage.t xt/pod.t xt/pod_defaults.t xt/prereqs.t xt/spelling.t xt/synopsis.t xt/version1.t xt/version2.t xt/whitespaces.t xt/Y3_choose_function.t xt/Y3_choose_function_invalid.t xt/Y3_choose_method.t xt/Y3_choose_method_invalid.t xt/Y_choose_function_arguments.pl xt/Y_choose_function_invalid_arguments.pl xt/Y_choose_method_arguments.pl xt/Y_choose_method_invalid_arguments.pl xt/Y_Data_Test_Arguments.pm xt/year_copyright.t xt/Z0_clone_win.t xt/Z1_hide_cursor.t xt/Z2_choose.t xt/Z_choose.pl xt/Z_Data_Test_Choose.pm META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Term-Choose-1.511/Changes0000644000175000001440000005460313237521450013503 0ustar mmusersRevision history for Term::Choose 1.511 2018-02-10 - Bugfix: don't link the original list to a self hash element. - Deprecation: method "config". - Update documentation. 1.510 2018-02-04 - Bugfix: don't overwrite option "layout" - 'cut_to_printwidth': don't copy parameter. 1.509 2018-01-04 - Removed the option "pad_one_row". 1.508 2018-01-04 - Improved language in POD [RT #123890 gregoa]. - Bugix in "all_in_one_row". 1.507 2017-08-09 - Refactoring `line_fold`. 1.506 2017-04-26 - Code refactoring. - Update year copyright. 1.505 2016-08-14 - Don't hide "Term::Choose::Constants" on Pause [https://github.com/kuerbis/Term-Choose_HAE/issues/2 stesachse]. 1.504 2016-03-21 - If ll is set, choose returns always indexes. - If ll is set and the window size has changed, choose returns immediately -1. 1.503 2016-03-11 - Announcement of future new behavior of the option "ll". 1.502 2016-02-29 - Don't hide "Term::Choose::LineFold" from Pause [https://github.com/kuerbis/Term-Choose-Util/issues/2 stepht]. - Code refactoring. 1.501 2016-02-22 - Bugfix in "idx_to_marked". 1.500 2016-02-21 - Update "line_fold". - Bugfix in "cut_to_printwidth". 1.209_02 2016-02-15 - Bugfix in "line_fold" - handle trailing newlines. 1.209_01 2016-02-14 - New module "Term::Choose::LineLineFold". 1.209 2016-01-30 - "mark" and "no_spacebar" - indexes out of range: now dies with an appropriate error message. - Bugfix: with only one row a string can still be to long if there is only one string. - If the option "ll" is enabled: empty strings are no longer replaced. - Code refactoring - Code cleanup. - Update documentation. 1.208 2015-10-21 - Update documentation. 1.207 2015-10-05 - Make "Term::Choose::Constants" visible, so it is available for "Term::Choose_HAE". 1.206 2015-10-02 - Stable release - no changes. 1.205_04 2015-09-26 - Code refactoring. 1.205_03 2015-09-22 - Bugfix "i_col". - Code refactoring. 1.205_02 2015-09-19 - Code refactoring. 1.205_01 2015-09-18 - Code refactoring. 1.205 2015-09-09 - Code refactoring. 1.204 2015-09-09 - Code refactoring. 1.203 2015-09-09 - Reserve one space for the (hidden) terminal cursor: Terminalwidth - 1. 1.202 2015-07-02 - Removed redundant documentation. 1.201 2015-04-27 - Moved "Expect"-tests to the "xt"-folder. 1.200_01 2015-04-25 - One new test and one test modified. 1.200 2015-03-27 - "Ctrl-SpaceBar": all if cursor on first row else current page. 1.120 2015-03-11 - Bugfix in Win32 "__clear_screen". 1.119 2015-02-05 - use constant. - Update year copyright. 1.118 2014-12-08 - Perl minimum version: "5.8.3". - Update build requirements. 1.117 2014-11-20 - Stable release. - Make tests which use "Expect" optional. 1.116_03 2014-11-03 - Bugfix "marked". 1.116_02 2014-11-02 - Keep the cursor position when the screen is resized. - Code refactoring. 1.116_01 2014-10-30 - New option "mark". - Don't reset the marked items if the screen is resized. - Update documentation. 1.116 2014-09-06 - Stable release - no changes. 1.115_01 2014-09-05 - Perl minimum version from "5.10.0" to "5.8.0". - Update documentation. 1.115 2014-09-03 - Stable release - no changes. 1.114_04 2014-08-24 - Bugfix in reset screen. 1.114_03 2014-08-19 - Modified tests. 1.114_02 2014-08-19 - Modified test. 1.114_01 2014-08-14 - Update tests. - Removed option "limit". - Update documentation. 1.114 2014-08-13 - Re-enabled "limit". - Announcement: "limit will be removed". - Removed developer tests. - Update documentation. 1.113_10 2014-08-12 - Removed option "limit". - Update tests. 1.113_09 2014-08-11 - Update tests. 1.113_08 2014-08-09 - Update tests. 1.113_07 2014-08-07 - Update tests. - Perl minimum version "5.10.0". - Removed warning: empty list. 1.113_06 2014-08-06 - Update tests. - Removed "Build.PL". 1.113_05 2014-08-05 - Update tests. 1.113_04 2014-08-05 - Update tests. 1.113_03 2014-08-03 - Update keycodes. - Update tests. 1.113_02 2014-08-03 - Developer test. 1.113_01 2014-08-02 - Added developer tests. - Invalid options are now fatal. - Removed "Win32::Console::ANSI". - Update documentation. - Removed POD from "Term::Choose::Linux", "Term::Choose::Win32" and "Term::Choose::Constants". 1.113 2014-08-02 - Announcement: invalid options will become fatal. - Announcement: "Win32::Console::ANSI" will be removed. - Code refactoring: prepare the announced changes. - Removed developer tests. - Update documentation. 1.112_03 2014-08-01 - Code refactoring. - Replaced test. 1.112_02 2014-07-31 - Bugfix: argument checking if "choose" is called as function. - Modified test. 1.112_01 2014-07-31 - New test. 1.112 2014-07-29 - Removed undocumented behavior. - Update documentation. 1.111 2014-07-15 - It is now possible to disable the 'print "\e(U"' with the TC_KEEP_WINDOWS_MAPPING environment variable. - Announcement: "\e(U" will be removed in a future release. - Update documentation. 1.110 2014-06-28 - Improved argument validation: don't allow references as values for the options "prompt", "empty" and "undef". - Changed the workaround concerning the "\e(U" escape sequence in "Term::Choose::Win32". - Renamed variables and hash keys. 1.109 2014-05-22 - Bugfix warning "invalid option name". - Bugfix option "max_width / improvement layout. - Removed the period at the end of the error messages. - Improved documentation. 1.108 2014-04-17 - Fixed error in variable name in "Term::Choose::Win32". 1.107 2014-04-09 - Documentation: update and bugfix. 1.106 2014-04-09 - Use "Win32::Console" directly to get the terminal size. - Update documentation. - Update Makefile.PL. 1.105 2014-03-18 - Code refactoring and cleanup. 1.104 2014-03-13 - Bugfix cleanup. 1.103 2014-03-08 - Added experimental option "no_spacebar". - Update documentation. 1.102 2014-03-07 - Bugfix option "limit". - Code refactoring. 1.101 2014-03-06 - Change behavior of layout 2. - Fixed documentation. 1.100 2014-03-06 - Rewritten in OO. - OS specific code: plugins "Term::Choose::Linux" and "Term::Choose::Win32". 1.075_01 2014-02-27 - Increased version number to get "prerequisite" warning. 1.074_01 2014-02-26 - Rewritten in OO. - Outsourced OS specific code to "Term::Choose::Linux" and "Term::Choose::Win32". 1.074 2014-02-13 - Added "use warnings;". - Added LICENSE file. - Added release test "year_copyright.t" - Update documentation. 1.073 2014-01-26 - Update release test "compare_Choose_Win32.t" to sync with Term::Choose::Win32 version 0.020. 1.072 2014-01-24 - Prevent references from breaking the output. - Update README. - Update license. 1.071 2014-01-21 - Keep track of the terminal size instead of using "SIGWINCH". - Update documentation. 1.070 2014-01-18 - Default value for option "limit" from 100_000 to not set (undef). - Removed the artificial general upper limit for options with no specific upper limit. - Update documentation. 1.069 2014-01-04 - Update copyright. - Removed example. A bugfixed version of the example-script is now located in the "App::DBBrowser" distribution and is called "db-browser". 1.068 2013-12-25 - Increased the minimum required Perl version from "5.10.0" to "5.10.1". - Update documentation. - Update example. 1.067 2013-12-23 - Bugfix documentation. - Update example. 1.066 2013-12-18 - Update documentation. - Example: bugfix and update. 1.065 2013-12-13 - Removed the deprecated option name "screen_width". - Modified behavior "relative position". - The minimum required version of "Unicode::GCString" is now "2013.10". - Replaced "s/\P{Print}/\x{fffd}/g" with "s/\p{C}//g". - Added "no warnings utf8". - Updated documentation. - Example: bugfixes, updates and refactoring. - Example: Removed the option "Length". 1.064 2013-09-24 - Update/bugfix in: keep relative position when moving page-wise. 1.063 2013-09-23 - Keep the relative row position when moving page-wise. 1.062 2013-09-18 - Code refactoring. 1.061 2013-09-07 - Added option "max_height". - Renamed option "screen_width" to "max_width". - Updated documentation. 1.060 2013-09-06 - Allow installation on Win32 - Term::Choose::Win32 now depends on Term::Choose. - Bugfix example. 1.059 2013-09-04 - Code refactoring. - Updated documentation. - Bugfix example. 1.058 2013-08-25 - Code refactoring. - Imporved documentation. - Updated example. 1.057 2013-08-10 - Example: fixed bug. 1.056 2013-08-10 - Example: update and bug fix. 1.055 2013-06-21 - Example: bug fix. 1.054 2013-06-21 - Removed "experimental" from option "lf" and from option "ll". - Updated documentation. - Example: bug fixes. 1.053 2013-06-17 - Fixed bug: replaced "\N{LINE FEED}" with "\n" (in "_prepare_promptline"). Before Perl v5.16 an occurrence of \N{CHARNAME} doesn't load "charnames" module automatically. 1.052 2013-06-14 - Modified experimental option "lf". - Update documentation. 1.051 2013-06-10 - Fixed bug (size_changed). - Added option "keep". - Removed experimental option "st". - Added experimental option "lf". - Update documentation. 1.050 2013-06-05 - Removed experimental option "head". - Update documentation. - Example: changed local_readline. - Example: bugfix. 1.049 2013-06-03 - Announcements. - Code refactoring. - Update documentation. - Update example. 1.048 2013-05-29 - Code refactoring: reuse the length of strings calculated in "_length_longest". - Removed deprecated option name "keep". - Update documentation. - Removed option "max-depth" from the example. - Update example. 1.047 2013-05-26 - Added experimental option "st". - Code cleanup. - Update documentation. - Update example. 1.046 2013-05-25 - Added support for multi-line prompt. - Added "Text::LineFold" as a required module. - Keep at least 4 list lines. - Code cleanup. - Update documentation. - Example: update and bug fix. 1.045 2013-05-24 - Added extended SGR mouse mode (1006) support. - The mouse wheel scrolls now page-wise instead of line-wise. - Updated documentation. - Updated example. 1.044 2013-05-23 - Experimental option "keep" is now called "head". - Updated documentation. - Example: update and bug bixes. 1.043 2013-05-20 - Replaced "given/when". - Updated documentation. - Example: update and bug fix. 1.042 2013-05-16 - Added the experimental option "keep". - Non printable characters are replaced with "\x{fffd}" instead of a dot. - Buildin "ref" is used instead of "Scalar::Util::reftype" to check arguments. - Removed deprecated option name "length_longest". - Code refactoring. - Example: update and bug fixes. 1.041 2013-05-12 -"_init_scr" is now OO, so that DESTROY does the cleanup. - Added $SIG{'INT'} handler. - Code cleanup. - Fixed bug in example (stringify gcstring). 1.040 2013-05-10 - Removed experimental option "cp_list". -"s/\p{Cntrl}//g;" --> "s/\P{Print}/./g;" - Refactoring "_unicode_cut" (now called "_unicode_trim"). - Strings trimmed with "_unicode_sprintf" don't end with "...". - Code refactoring. - Update documentation. - Update example. 1.039 2013-05-05 - Switched from "Text::CharWidth" back to "Unicode::GCString" ("Unicode::GCString" supports Unicode Version 6.2). - The minimum required version of "Unicode::GCString" is now "2012.10". - Example: update. - Example: adaption to work again with "Unicode::GCString". 1.038 2013-05-02 -Added experimental option "cp_list". -Updated documentation. 1.037 2013-04-29 - Example: fixed bugs. - Example: added progess bar threshold (option). - Example: changed the "binary filter"/ removed the option "Binary filter". 1.036 2013-04-24 - Switched from "Unicode::GCString/columns" to "Text::CharWidth::mbswidth" to determine print columns (faster). - Update documentation. 1.035 2013-04-23 - Refactoring "_unicode_cut" (Text::WideChar::Util::mbtrunc). - Refactoring "_unicode_sprintf" (truncated strings end with "..."). 1.034 2013-04-23 - Code refactoring. - Code cleanup. - Update documentation. 1.033 2013-04-17 - Bugfix (KEY_END). - Bugfix and code cleanup in "_getch". - Reset "$|" before leaving "choose". - Updated documentation. - Example: update. - Example: "binary filter" disabled by default 1.032 2013-04-11 - Removed "autodie" from the tests - perl 5.10.0 doesn't provide autodie. - Fixed "prompt" bug in "_wr_screen". 1.031 2013-04-09 - Option "prompt": the value '' (empty string) means now no promptline. - Skip checking string-length in layout "3" if "length_longest" <= "maxcols". - The opton "length_longest" is now called also "ll". - Changed mininum Perl version from "5.10.1" to "5.10.0". - Code cleanup. - Updated documentation. - Updated example. 1.030 2013-04-04 - Removed the undocumented appending of "(multiple choice ...)" to the promptstring in listcontext. - Code cleanup. - Updated documentation. - Example: Added option "expand". 1.029 2013-04-01 - Added experimental feature: "Ctrl-SpaceBar" inverts the choices. - "choose": set "$\" and "$," to "undef". - Code refactoring. - Removed deprecated options from documentation. - Example: Modified "binary filter". 1.028 2013-03-07 - Fixed bug in "_handle_mouse" (all_in_one_row). - Updated "_handle_mouse". - Options: replaced "mouse_mode" with "mouse". - Options: replaced "empty_string" with "empty". - Code refactoring. - Code cleanup. - Imporved documentation. - Example: bug fixes. - Example: updated function "choose_a_number". 1.027 2013-03-05 - Removed "utf8" pragma: only ASCII sourcecode and "utf8::upgrade" does not need "use utf8". - Example: added option "sssc_mode". 1.026 2013-03-02 - Code refactoring. - Improved documentation. - Example: update. 1.025 2013-02-19 - Option "pad_one_row" defaults to the value of the option "pad". - Modified "croak" messages. - Code refactoring. - Updated documentation. - Updated example. 1.024 2013-02-09 - "Home-key" and "End-key": removed status "experimental". - Updated documentation. - Example: bug fixes. - Example: code refactoring. 1.023 2013-02-06 - Added support for the "Home-key" and the "End-key" (experimental). - Updated documentation. - Example: code refactoring. 1.022 2013-01-31 - Example: update and bug fixes. 1.021 2013-01-28 - Removed deprecated options "right_justify" and "vertical". - Updated documentation. - Updated copyright. - Example: switched back to "File::Find". - Example: added postgres. 1.020 2013-01-02 - Added option "index". - Updated documentation. - Updated example. 1.019 2012-12-26 - The "layout" "1" starts more broadly now (if more than one row). - Options: replaced "right_justify" with "justify" (with new value "centered"). - Options: replaced "vertical" with "order". - Updated documentation. - Updated example. 1.018 2012-11-28 - warn "EOT" if "_getch" returns "undef". - Example: added "Union". - Example: update and bug fixes. 1.017 2012-11-15 - Fixed bug in "if size_changed". - Added: Check "ReadKey"/"_getch" if return value is defined. - Added: "Ctrl+D" behaves as the "q" key. - Code cleanup. - Build.PL/Makefile.PL: "die 'No support for OS' if $^O eq 'MSWin32';". - Example: updated and reduced dependencies. 1.016 2012-11-11 - Code refactoring (clear_screen). - Removed "Choose/GC.pm". - Code cleanup. - Improved documentation. - Example: added "Join Tables". - Example: update and bug fixes. 1.015 2012-10-22 - Code cleanup. - Improved documentation. - Example: update and bug fixes. 1.014 2012-10-10 - Code cleanup. - Updated example. 1.013 2012-10-08 - Unicode::GCString: moved from "eval" to "utf8::upgrade". - Improved documentation. - Updated example. 1.012 2012-10-04 - Term::Choose with Unicode support and Term::Choose::GC removed. - Changed "eval" bracketing. - Example: removed "delete" option. - Example: fixed bugs. 1.011 2012-10-02 - Removed/replaced "smartmatch" operators. - Improved documentation. - Example: update and bug fixes. - Example: from "File::Find" to "File::Find::Rule". 1.010 2012-09-26 - Example: update and bug fixes. 1.009 2012-09-25 - Removed deprecated option names "max_list" and "cursor". - Updated documentation. - Example: bug fix and update. 1.008 2012-09-24 - Option "page" now enabled by default. - Option "cursor" is now called "default". - Option "max_list" is now called "limit". - Improved documentation. - Updated example. 1.007 2012-09-07 - Fixed bug in "_size_and_layout" (if "vertical" == 0). - Fixed bug in "_write_first_screen" (condition for calling "_set_this_cell"). - Code refactoring. - Some changes of the allowed option values. - Updated example. - Updated documentation. 1.006 2012-09-06 - Added option "page". - Code refactoring. - Fixed bugs and updated example. - Updated documentation. 1.005 2012-09-01 - Added option "cursor". - Fixed mouse_mode bugs. - Updated documentation. 1.004 2012-08-29 - "_size_and_layout" back to the old position after "_print_promptline". - Code refactoring. - Improved documentation. 1.003 2012-08-28 - Check for existing SIGWINCH handler. - Code refactoring. - Removed $arg->{step} from "_print_promptline" (GC) ("_print_promptline" not available if $arg->{prompt} == 0). - Updated example. - Improved documentation. 1.002 2012-08-23 - Updated Example. - Code refactoring. - Improved documentation. 1.001 2012-08-12 - $VERSION: switched from dotted-integers to decimal numbers ("0.7.16" -> "1.001"). - Changed the maximal allowed value for the option "length_longest" from 999_999_999 to 999. - Updated documentation. 0.7.16 2012-08-12 - From "$XSIG{WINCH}[4]" (Signals::XSIG) to "local $SIG{WINCH}". - Updated "Page Up"/"Page Down". - Removed option "extra_key". - Updated documentation. 0.7.15 2012-08-09 - Added "Page Up" and "Page Down" keys (experimental). 0.7.14 2012-08-08 - Added option "length_longest". - Updated documentation. - Code refactoring. 0.7.13 2012-08-05 - Removed option "length_longest". 0.7.12 2012-08-05 - Code refactoring - "_size_and_layout": don't copy the list but use indexes. - Added option "length_longest". - Changed "_unicode_cut" and "_unicode_sprintf" - Changed optionname "vertical_order" to "vertical". - Changed the order of the values from the option "layout". - Updated example. - Improved documentation. 0.7.11 2012-07-31 - "_size_and_layout": back to version 0.7.9. 0.7.10 2012-07-30 - Code refactoring - "_size_and_layout": don't copy the list. - Fixed bug in example. - Improved documentation. 0.7.9 2012-07-29 - Form "and,or,not" to "&&,||,!". - Minor code changes. - Updated example. - Improved documentation. 0.7.8 2012-07-27 - Added example. - Minor code changes. 0.7.7 2012-07-24 - Fixed bug in _unicode_cut. - Improved documentation. 0.7.6 2012-07-23 - Added Term::Choose::GC. - Code refactoring. - Improved documentation. 0.7.5 2012-07-21 - Don't print control characters. - Improved Documentation. 0.7.4 2012-07-19 - Minor code changes. - Improved Documentation. 0.7.3 2012-07-17 - Make calling "choose" in void context more normal. - Modified error messages. - "max_list": exceeding "max_list" now warns and cuts the used list to max_list instead of dying. - Added bug section. - Improved documentation. 0.7.2 2012-07-14 - Press a key after warnings "not a valid value for option" or "no such option" to continue. - Consideration of the case of calling "choose" in a void context. - Code cleanup. - Documentation cleanup. 0.7.1 2012-07-13 - First release on cpan. Term-Choose-1.511/Makefile.PL0000644000175000001440000000312013223360074014144 0ustar mmusersuse 5.008003; use warnings; use strict; use ExtUtils::MakeMaker; my %prereqs_os_specific; if ( $^O eq 'MSWin32' ) { %prereqs_os_specific = ( 'Win32::Console' => 0, ); } else { %prereqs_os_specific = ( 'Term::ReadKey' => 0, ); } WriteMakefile( PL_FILES => {}, MIN_PERL_VERSION => '5.008003', LICENSE => 'perl', META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', web => 'https://github.com/kuerbis/Term-Choose', url => 'https://github.com/kuerbis/Term-Choose.git', }, }, }, AUTHOR => 'Matthaeus Kiem ', NAME => 'Term::Choose', ABSTRACT_FROM => 'lib/Term/Choose.pm', VERSION_FROM => 'lib/Term/Choose.pm', EXE_FILES => [], BUILD_REQUIRES => { 'lib' => 0, 'File::Spec::Functions' => 0, 'FindBin' => 0, 'Test::More' => 0, 'Test::Fatal' => 0, }, PREREQ_PM => { 'constant' => 0, 'strict' => 0, 'warnings' => 0, 'Carp' => 0, 'Exporter' => 0, 'Unicode::GCString' => 0, %prereqs_os_specific, }, test => { TESTS => 't/*/*.t', }, dist => { COMPRESS => 'gzip', SUFFIX => '.gz', TARFLAGS => '--format=gnu -cvf', }, clean => { FILES => 'Term-Choose-*', }, ); Term-Choose-1.511/LICENSE0000644000175000001440000004366113215670411013215 0ustar mmusersThis software is copyright (c) 2018 by Matthäus Kiem. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2018 by Matthäus Kiem. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2018 by Matthäus Kiem. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Term-Choose-1.511/t/0000755000175000001440000000000013237602053012442 5ustar mmusersTerm-Choose-1.511/t/01_arguments/0000755000175000001440000000000013237602053014747 5ustar mmusersTerm-Choose-1.511/t/01_arguments/01_new_invalid.t0000644000175000001440000000277312626746534017762 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use Test::Fatal; use Term::Choose; use FindBin qw( $RealBin ); use lib $RealBin; use Data_Test_Arguments; my $exception; my $regex = qr/^new:/; $exception = exception { my $new = Term::Choose->new( {}, {} ) }; ok( $exception =~ $regex, "\$new = Term::Choose->new( {}, {} ) => $exception" ); $exception = exception { my $new = Term::Choose->new( 'a' ) }; ok( $exception =~ $regex, "\$new = Term::Choose->new( 'a' ) => $exception" ); $exception = exception { my $new = Term::Choose->new( { hello => 1, world => 2 } ) }; ok( $exception =~ $regex, "\$new = Term::Choose->new( { hello => 1, world => 2 } ) => $exception" ); my %new; my $n = 1; # ? my $invalid_values = Data_Test_Arguments::invalid_values(); for my $opt ( sort keys %$invalid_values ) { for my $val ( @{$invalid_values->{$opt}} ) { my $exception = exception { $new{$n++} = Term::Choose->new( { $opt => $val } ) }; ok( $exception =~ $regex, "\$new = Term::Choose->new( { $opt => $val } ) => $exception" ); } } my $mixed_invalid_1 = Data_Test_Arguments::mixed_invalid_1(); $exception = exception { $new{$n++} = Term::Choose->new( $mixed_invalid_1 ) }; ok( $exception =~ $regex, "\$new = Term::Choose->new( { >>> } ) => $exception" ); my $mixed_invalid_2 = Data_Test_Arguments::mixed_invalid_2(); $exception = exception { $new{$n++} = Term::Choose->new( $mixed_invalid_2 ) }; ok( $exception =~ $regex, "\$new = Term::Choose->new( { <<< } ) => $exception" ); done_testing(); Term-Choose-1.511/t/01_arguments/02_config_invalid.t0000644000175000001440000000253312626746534020431 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use Test::Fatal; use Term::Choose; use FindBin qw( $RealBin ); use lib $RealBin; use Data_Test_Arguments; my $exception; my $new = Term::Choose->new(); my $regex = qr/^config:/; $exception = exception { $new->config( {}, {} ) }; ok( $exception =~ $regex, "\$new->config( {}, {} ) => $exception" ); $exception = exception { $new->config( 'a' ) }; ok( $exception =~ $regex, "\$new->config( 'a' ) => $exception" ); $exception = exception { $new->config( { hello => 1, world => 2 } ) }; ok( $exception =~ $regex, "\$new->config( { hello => 1, world => 2 } ) => $exception" ); my $invalid_values = Data_Test_Arguments::invalid_values(); for my $opt ( sort keys %$invalid_values ) { for my $val ( @{$invalid_values->{$opt}} ) { my $exception = exception { $new->config( { $opt => $val } ) }; ok( $exception =~ $regex, "\$new->config( { $opt => $val } ) => $exception" ); } } my $mixed_invalid_1 = Data_Test_Arguments::mixed_invalid_1(); $exception = exception { $new->config( $mixed_invalid_1 ) }; ok( $exception =~ $regex, "\$new->config( { >>> } ) => $exception" ); my $mixed_invalid_2 = Data_Test_Arguments::mixed_invalid_2(); $exception = exception { $new->config( $mixed_invalid_2 ) }; ok( $exception =~ $regex, "\$new->config( { <<< } ) => $exception" ); done_testing(); Term-Choose-1.511/t/01_arguments/02_config.t0000644000175000001440000000231212626746534016716 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use Test::Fatal; use Term::Choose; use FindBin qw( $RealBin ); use lib $RealBin; use Data_Test_Arguments; my $new = Term::Choose->new(); my $exception; $exception = exception { $new->config() }; ok( ! defined $exception, '$new->config()' ); $exception = exception { $new->config( {} ) }; ok( ! defined $exception, '$new->config( {} )' ); my $valid_values = Data_Test_Arguments::valid_values(); my $new1 = Term::Choose->new( { order => 1, layout => 2, mouse => 3 } ); # ? for my $opt ( sort keys %$valid_values ) { for my $val ( @{$valid_values->{$opt}}, undef ) { my $exception = exception { $new1->config( { $opt => $val } ) }; my $value = defined $val ? $val : 'undef'; ok( ! defined $exception, "\$new->config( { $opt => $value } )" ); } } my $mixed_options_1 = Data_Test_Arguments::mixed_options_1(); $exception = exception { $new1->config( $mixed_options_1 ) }; ok( ! defined $exception, "\$new->config( { >>> } )" ); my $mixed_options_2 = Data_Test_Arguments::mixed_options_2(); $exception = exception { $new1->config( $mixed_options_2 ) }; ok( ! defined $exception, "\$new->config( { <<< } )" ); done_testing(); Term-Choose-1.511/t/01_arguments/Data_Test_Arguments.pm0000644000175000001440000001071713223365701021211 0ustar mmuserspackage # hide Data_Test_Arguments; use 5.008003; use warnings; use strict; sub valid_values { return { beep => [ 0, 1 ], clear_screen => [ 0, 1 ], hide_cursor => [ 0, 1 ], index => [ 0, 1 ], justify => [ 0, 1, 2 ], layout => [ 0, 1, 2, 3 ], mouse => [ 0, 1, 2, 3, 4 ], order => [ 0, 1 ], page => [ 0, 1 ], # '[ 1-9 ][ 0-9 ]*' keep => [ 1, 2, 100, 999999, undef ], ll => [ 1, 2, 100, 999999, undef ], max_height => [ 1, 2, 100, 999999, undef ], max_width => [ 1, 2, 100, 999999, undef ], # '[ 0-9 ]+' default => [ 0, 1, 2, 100, 999999, undef ], pad => [ 0, 1, 2, 100, 999999, undef ], # '' empty => [ 0, 'Hello' x 50, '', ' ', 'abc', 'world', undef ], prompt => [ 0, 'Hello' x 50, '', ' ', 'abc', 'world', undef ], undef => [ 0, 'Hello' x 50, '', ' ', 'abc', 'world', undef ], # ARRAY max 2 int lf => [ [ 2, 4 ], [ 8 ], [], undef ], # ARRAY int mark => [ [ 0, 1, 2, 100, 999999 ], [ 1 ], undef ], no_spacebar => [ [ 0, 1, 2, 100, 999999 ], [ 1 ], undef ], }; } sub mixed_options_1 { return { beep => 0, clear_screen => undef, hide_cursor => 1, index => 0, justify => 0, layout => 0, mouse => 0, order => 1, page => 0, keep => 1, ll => 1, max_height => 19, max_width => 19, default => 9, pad => 3, empty => '', prompt => '', undef => '', lf => [ 1 ], no_spacebar => [ 0 ], mark => [ 3, 4 ] }; } sub mixed_options_2 { return { mark => [ 0 ], no_spacebar => [ 11, 0, 8 ], lf => [ 1, 1 ], undef => '', prompt => 'prompt_line', empty => '', pad => 3, default => 9, max_width => 19, max_height => 119, ll => 15, keep => 1, page => 1, order => 1, mouse => 0, layout => 3, justify => 0, index => 0, hide_cursor => 1, clear_screen => undef, beep => 0 }; } ################################################################################################## sub invalid_values { my @invalid = ( -1, 2, 2 .. 10, 999999, '01', '', 'a', { 1, 1 }, [ 1 ], [ 2 ] ); return{ beep => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], clear_screen => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], hide_cursor => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], index => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], justify => [ grep { ! /^[ 0 1 2 ]\z/x } @invalid ], layout => [ grep { ! /^[ 0 1 2 3 ]\z/x } @invalid ], mouse => [ grep { ! /^[ 0 1 2 3 4 ]\z/x } @invalid ], order => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], page => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], keep => [ grep { ! /^[ 1-9 ][ 0-9 ]*\z/x } @invalid ], ll => [ grep { ! /^[ 1-9 ][ 0-9 ]*\z/x } @invalid ], max_height => [ grep { ! /^[ 1-9 ][ 0-9 ]*\z/x } @invalid ], max_width => [ grep { ! /^[ 1-9 ][ 0-9 ]*\z/x } @invalid ], default => [ grep { ! /^[ 0-9 ]+\z/x } @invalid ], pad => [ grep { ! /^[ 0-9 ]+\z/x } @invalid ], # '' empty => [ { 1, 1 }, [ 1 ], {}, [], [ 2 ] ], prompt => [ { 1, 1 }, [ 1 ], {}, [], [ 2 ] ], undef => [ { 1, 1 }, [ 1 ], {}, [], [ 2 ] ], # ARRAY max 2 int lf => [ -2, -1, 0, 1, '', 'a', { 1, 1 }, {}, [ 1, 2, 3, ], [ 'a', 'b' ], [ -3, -4 ] ], # ARRAY int mark => [ -2, -1, 0, 1, '', 'a', { 1, 1 }, {}, [ 'a', 'b' ], [ -3, -4 ] ], no_spacebar => [ -2, -1, 0, 1, '', 'a', { 1, 1 }, {}, [ 'a', 'b' ], [ -3, -4 ] ], }; } sub mixed_invalid_1 { return { beep => -1, clear_screen => 2, hide_cursor => 3, index => 4, justify => '@', layout => 5, mouse => {}, order => 1, page => 0, keep => -1, ll => -1, max_height => 0, max_width => 0, default => [], pad => 'a', empty => [], prompt => {}, undef => [], lf => 4, no_spacebar => 4, mark => 'o' }; } sub mixed_invalid_2 { return { mark => '', no_spacebar => 'a', lf => 'b', undef => [], prompt => {}, empty => {}, pad => 'd', default => 'e', max_width => -1, max_height => -2, ll => -4, keep => -5, page => -6, order => -7, mouse => 'k', layout => 'e', justify => [], index => {}, hide_cursor => -1, clear_screen => [], beep => 10 }; } 1; __END__ Term-Choose-1.511/t/01_arguments/01_new.t0000644000175000001440000000245612626746534016252 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use Test::Fatal; use Term::Choose; use FindBin qw( $RealBin ); use lib $RealBin; use Data_Test_Arguments; my $new1; my $exception = exception { $new1 = Term::Choose->new() }; ok( ! defined $exception, '$new = Term::Choose->new()' ); ok( $new1, '$new = Term::Choose->new()' ); my $new; $exception = exception { $new = Term::Choose->new( {} ) }; ok( ! defined $exception, '$new = Term::Choose->new( {} )' ); my %new; my $n = 1; # ? my $valid_values = Data_Test_Arguments::valid_values(); for my $opt ( sort keys %$valid_values ) { for my $val ( @{$valid_values->{$opt}}, undef ) { my $exception = exception { $new{$n++} = Term::Choose->new( { $opt => $val } ) }; my $value = defined $val ? $val : 'undef'; ok( ! defined $exception, "\$new = Term::Choose->new( { $opt => $value } )" ); } } my $mixed_options_1 = Data_Test_Arguments::mixed_options_1(); $exception = exception { $new{$n++} = Term::Choose->new( $mixed_options_1 ) }; ok( ! defined $exception, "\$new = Term::Choose->new( { >>> } )" ); my $mixed_options_2 = Data_Test_Arguments::mixed_options_2(); $exception = exception { $new{$n++} = Term::Choose->new( $mixed_options_2 ) }; ok( ! defined $exception, "\$new = Term::Choose->new( { <<< } )" ); done_testing(); Term-Choose-1.511/t/00_load/0000755000175000001440000000000013237602053013660 5ustar mmusersTerm-Choose-1.511/t/00_load/00-load.t0000644000175000001440000000031112626746534015212 0ustar mmusersuse 5.008003; use strict; use warnings; use Test::More tests => 1; BEGIN { use_ok( 'Term::Choose' ) || print "Bail out!\n"; } diag( "Testing Term::Choose $Term::Choose::VERSION, Perl $], $^X" ); Term-Choose-1.511/README0000644000175000001440000000107113215670423013060 0ustar mmusersTerm-Choose =========== INFO Choose from a list. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc Term::Choose LICENSE AND COPYRIGHT Copyright (C) 2012-2018 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. Term-Choose-1.511/xt/0000755000175000001440000000000013237602053012632 5ustar mmusersTerm-Choose-1.511/xt/Y_choose_function_arguments.pl0000755000175000001440000000103612626746534020752 0ustar mmusers#!/usr/bin/env perl use 5.008003; use warnings; use strict; use Term::Choose qw( choose ); use FindBin qw( $RealBin ); use lib $RealBin; use Y_Data_Test_Arguments; choose( [] ); choose( [], {} ); my $valid_values = Y_Data_Test_Arguments::valid_values(); for my $opt ( sort keys %$valid_values ) { for my $val ( @{$valid_values->{$opt}}, undef ) { choose( [], { $opt => $val } ); } } choose( [], Y_Data_Test_Arguments::mixed_options_1() ); choose( [], Y_Data_Test_Arguments::mixed_options_2() ); print "\n"; Term-Choose-1.511/xt/year_copyright.t0000644000175000001440000000141212626746534016063 0ustar mmusersuse 5.010000; use warnings; use strict; use Test::More tests => 1; use Time::Piece; my $t = localtime; my $this_year = $t->year; my @files = ( 'README', 'LICENSE', 'lib/Term/Choose.pm', ); my $author = 'Matth..?us Kiem'; my $error = 0; my $diag = ''; for my $file ( @files ) { open my $fh, '<', $file or die $!; while ( my $line = <$fh> ) { if ( $line =~ /copyright(?: \(c\))? .*$author/i ) { if ( $line !~ /copyright(?: \(c\))? 20\d\d-\Q$this_year\E /i && $line !~ /copyright(?: \(c\))? \Q$this_year\E /i ) { $diag .= sprintf( "%15s - line %d: %s\n", $file, $., $line ); $error++; } } } close $fh; } ok( $error == 0, "Copyright year" ) or diag( $diag ); diag( "\n" ); Term-Choose-1.511/xt/pod-coverage.t0000644000175000001440000000032512626746534015410 0ustar mmusersuse 5.010000; use strict; use warnings; use Test::More; use Test::Pod::Coverage; use Pod::Coverage; use lib 'lib'; use Term::Choose; #all_pod_coverage_ok(); plan tests => 1; pod_coverage_ok( 'Term::Choose' ); Term-Choose-1.511/xt/01_option.t0000644000175000001440000000705713223366025014641 0ustar mmusersuse 5.010000; use warnings; use strict; use utf8; use Test::More; use Test::Fatal; use lib 'lib'; use Term::Choose qw( choose ); no warnings 'redefine'; sub Term::Choose::__get_key { sleep 0.01; return 0x0d }; close STDIN or plan skip_all => "Close STDIN $!"; my $stdin = "eingabe\n"; open STDIN, "<", \$stdin or plan skip_all => "STDIN $!"; close STDOUT or plan skip_all => "Close STDOUT $!"; close STDERR or plan skip_all => "Close STDERR $!"; my ( $tmp_stdout, $tmp_stderr ); open STDOUT, '>', \$tmp_stdout or plan skip_all => "STDOUT $!"; open STDERR, '>', \$tmp_stderr or plan skip_all => "STDERR $!"; my $choices = [ '', 0, undef, 1, 2, 3, 'aa' .. 'zz', '☻☮☺', "\x{263a}\x{263b}", '한글', 'æða' ]; my $d; my $int = { beep => [ 0, 1 ], clear_screen => [ 0, 1 ], hide_cursor => [ 0, 1 ], index => [ 0, 1 ], justify => [ 0, 1, 2 ], layout => [ 0, 1, 2, 3 ], mouse => [ 0, 1, 2, 3, 4 ], order => [ 0, 1 ], page => [ 0, 1 ], }; for my $opt ( sort keys %$int ) { for my $val ( @{$int->{$opt}}, undef ) { ok( ! defined( exception { $d = choose( $choices, { $opt => $val } ) } ) ); } } my $one_or_greater = { keep => '[ 1-9 ][ 0-9 ]*', ll => '[ 1-9 ][ 0-9 ]*', max_height => '[ 1-9 ][ 0-9 ]*', max_width => '[ 1-9 ][ 0-9 ]*', }; my @val_one_or_greater = ( 1, 2, 100, 999999, undef ); for my $opt ( sort keys %$one_or_greater ) { for my $val ( @val_one_or_greater ) { ok( ! defined( exception { $d = choose( $choices, { $opt => $val } ) } ) ); } } my $zero_or_greater = { default => '[ 0-9 ]+', pad => '[ 0-9 ]+', }; my @val_zero_or_greater = ( 0, 1, 2, 100, 999999, undef ); for my $opt ( sort keys %$zero_or_greater ) { for my $val ( @val_zero_or_greater ) { ok( ! defined( exception { $d = choose( $choices, { $opt => $val } ) } ) ); } } my $string = { empty => '', prompt => '', undef => '', }; my @val_string = ( 0, 'Hello' x 50, '', ' ', '☻☮☺', "\x{263a}\x{263b}", '한글', undef, 'æða' ); my $fail; for my $opt ( sort keys %$string ) { for my $val ( @val_string ) { ok( ! defined( $fail = exception { $d = choose( $choices, { $opt => $val } ) } ), $fail // 'OK' ); } } my $lf = { lf => 'ARRAY', }; my @val_lf = ( [ 2, 4 ], [ 8 ], [], undef ); for my $opt ( sort keys %$lf ) { for my $val ( @val_lf ) { ok( ! defined( exception { $d = choose( $choices, { $opt => $val } ) } ) ); } } my $no_spacebar = { no_spacebar => 'ARRAY', }; my @val_no_spacebar = ( [ 0, 1, 2, 100, 999999 ], [ 1 ], undef ); for my $opt ( sort keys %$no_spacebar ) { for my $val ( @val_no_spacebar ) { ok( ! defined( exception { $d = choose( $choices, { $opt => $val } ) } ) ); } } ok( ! defined( exception { $d = choose( $choices, { beep => 0, clear_screen => undef, hide_cursor => 1, index => 0, justify => 0, layout => 0, mouse => 0, order => 1, page => 0, keep => 1, ll => 1, max_height => 19, max_width => 19, default => 9, pad => 3, empty => '', prompt => '', undef => '', lf => [ 1 ], no_spacebar => [ 0 ] } ) } ) ); ok( ! defined( exception { $d = choose( [ 'aaa' .. 'zzz' ], { no_spacebar => [ 11, 0, 8 ], lf => [ 1, 1 ], undef => '', prompt => 'prompt_line', empty => '', pad => 3, default => 9, max_width => 19, max_height => 119, ll => 15, keep => 1, page => 1, order => 1, mouse => 0, layout => 3, justify => 0, index => 0, hide_cursor => 1, clear_screen => undef, beep => 0 } ) } ) ); done_testing(); __DATA__ Term-Choose-1.511/xt/Y_choose_method_arguments.pl0000755000175000001440000000111712626746534020405 0ustar mmusers#!/usr/bin/env perl use 5.008003; use warnings; use strict; use Term::Choose; use FindBin qw( $RealBin ); use lib $RealBin; use Y_Data_Test_Arguments; my $new = Term::Choose->new(); $new->choose( [] ); $new->choose( [], {} ); my $valid_values = Y_Data_Test_Arguments::valid_values(); for my $opt ( sort keys %$valid_values ) { for my $val ( @{$valid_values->{$opt}}, undef ) { $new->choose( [], { $opt => $val } ); } } $new->choose( [], Y_Data_Test_Arguments::mixed_options_1() ); $new->choose( [], Y_Data_Test_Arguments::mixed_options_2() ); print "\n"; Term-Choose-1.511/xt/critic.t0000644000175000001440000000307312626746534014315 0ustar mmusersuse 5.010000; use warnings; use strict; use Test::Perl::Critic ( -profile => 'xt/perlcriticrc', -exclude => [ qw( BuiltinFunctions::ProhibitComplexMappings CodeLayout::RequireTidyCode CodeLayout::RequireTrailingCommas ControlStructures::ProhibitCascadingIfElse ControlStructures::ProhibitDeepNests ControlStructures::ProhibitPostfixControls Documentation::RequirePodLinksIncludeText Documentation::RequirePodSections InputOutput::ProhibitExplicitStdin InputOutput::ProhibitInteractiveTest InputOutput::ProhibitOneArgSelect InputOutput::RequireBracedFileHandleWithPrint InputOutput::RequireEncodingWithUTF8Layer NamingConventions::Capitalization References::ProhibitDoubleSigils RegularExpressions::ProhibitEnumeratedClasses RegularExpressions::RequireDotMatchAnything RegularExpressions::RequireExtendedFormatting RegularExpressions::RequireLineBoundaryMatching Subroutines::ProhibitExcessComplexity Subroutines::ProhibitSubroutinePrototypes Subroutines::ProhibitUnusedPrivateSubroutines Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn ValuesAndExpressions::ProhibitEmptyQuotes ValuesAndExpressions::ProhibitInterpolationOfLiterals ValuesAndExpressions::ProhibitMagicNumbers ValuesAndExpressions::ProhibitNoisyQuotes Variables::ProhibitPunctuationVars Variables::RequireLocalizedPunctuationVars ) ], ); all_critic_ok(); Term-Choose-1.511/xt/Y_choose_method_invalid_arguments.pl0000755000175000001440000000254712626746534022123 0ustar mmusers#!/usr/bin/env perl use 5.008003; use warnings; use strict; use Term::Choose; use FindBin qw( $RealBin ); use lib $RealBin; use Y_Data_Test_Arguments; my $new = Term::Choose->new(); eval { $new->choose( ); 1 } and die '$new->choose();'; eval { $new->choose( undef ); 1 } and die '$new->choose( undef );'; eval { $new->choose( {} ); 1 } and die '$new->choose( {} );'; eval { $new->choose( undef, {} ); 1 } and die '$new->choose( undef, {} );'; eval { $new->choose( 'a' ); 1 } and die '$new->choose( "a" );'; eval { $new->choose( 1, {} ); 1 } and die '$new->choose( 1, {} );'; eval { $new->choose( [], [] ); 1 } and die '$new->choose( [], [] );'; eval { $new->choose( [], 'b' ); 1 } and die '$new->choose( [], "b" );'; eval { $new->choose( [], { hello => 1, world => 2 } ); 1 } and die '$new->choose( [], { hello => 1, world => 2 } );'; my $valid_values = Y_Data_Test_Arguments::invalid_values(); for my $opt ( sort keys %$valid_values ) { for my $val ( @{$valid_values->{$opt}} ) { eval { $new->choose( [], { $opt => $val } ); 1 } and die "\$new->choose( { $opt => $val } );"; } } eval { $new->choose( [], Y_Data_Test_Arguments::mixed_invalid_1() ); 1 } and die '$new->choose( >>> );'; eval { $new->choose( [], Y_Data_Test_Arguments::mixed_invalid_2() ); 1 } and die '$new->choose( <<< );'; print "\n"; Term-Choose-1.511/xt/manifest.t0000644000175000001440000000014212626746534014640 0ustar mmusersuse 5.010000; use strict; use warnings; use Test::More; use Test::CheckManifest; ok_manifest(); Term-Choose-1.511/xt/Y3_choose_function_invalid.t0000644000175000001440000000226112626746534020304 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use FindBin qw( $RealBin ); use File::Spec::Functions qw( catfile ); BEGIN { if ( $^O eq 'MSWin32' ) { plan skip_all => "MSWin32: Expect not available."; } #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; #} } eval "use Expect"; if ( $@ ) { plan skip_all => $@; } my $exp; eval { $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->set_winsize( 24, 80, undef, undef ); my $command = $^X; my $script = catfile $RealBin, 'Y_choose_function_invalid_arguments.pl'; my @parameters = ( $script ); -r $script or die "$script is NOT readable"; $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; 1; } or plan skip_all => $@; my $expected = ''; my $ret = $exp->expect( 2, [ qr/(?:match(); $result = '' if ! defined $result; ok( $result eq $expected, "expected: '$expected', got: '$result'" ); $exp->hard_close(); done_testing(); Term-Choose-1.511/xt/Y3_choose_method_invalid.t0000644000175000001440000000223712626746534017742 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use FindBin qw( $RealBin ); use File::Spec::Functions qw( catfile ); BEGIN { if ( $^O eq 'MSWin32' ) { plan skip_all => "MSWin32: Expect not available."; } #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; #} } eval "use Expect"; if ( $@ ) { plan skip_all => $@; } my $exp; eval { $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->set_winsize( 24, 80, undef, undef ); my $command = $^X; my $script = catfile $RealBin, 'Y_choose_method_invalid_arguments.pl'; my @parameters = ( $script ); -r $script or die "$script is NOT readable"; $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; 1; } or plan skip_all => $@; my $expected = ''; my $ret = $exp->expect( 2, [ qr/.+/ ] ); ok( $ret, 'matched something' ); my $result = $exp->match(); $result = '' if ! defined $result; ok( $result eq $expected, "expected: '$expected', got: '$result'" ); $exp->hard_close(); done_testing(); Term-Choose-1.511/xt/Y3_choose_method.t0000644000175000001440000000223012626746534016225 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use FindBin qw( $RealBin ); use File::Spec::Functions qw( catfile ); BEGIN { if ( $^O eq 'MSWin32' ) { plan skip_all => "MSWin32: Expect not available."; } #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; #} } eval "use Expect"; if ( $@ ) { plan skip_all => $@; } my $exp; eval { $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->set_winsize( 24, 80, undef, undef ); my $command = $^X; my $script = catfile $RealBin, 'Y_choose_method_arguments.pl'; my @parameters = ( $script ); -r $script or die "$script is NOT readable"; $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; 1; } or plan skip_all => $@; my $expected = ''; my $ret = $exp->expect( 2, [ qr/.+/ ] ); ok( $ret, 'matched something' ); my $result = $exp->match(); $result = '' if ! defined $result; ok( $result eq $expected, "expected: '$expected', got: '$result'" ); $exp->hard_close(); done_testing(); Term-Choose-1.511/xt/Y_choose_function_invalid_arguments.pl0000755000175000001440000000230312626746534022456 0ustar mmusers#!/usr/bin/env perl use 5.008003; use warnings; use strict; use Term::Choose qw( choose ); use FindBin qw( $RealBin ); use lib $RealBin; use Y_Data_Test_Arguments; eval { choose( ); 1 } and die 'choose();'; eval { choose( undef ); 1 } and die 'choose( undef );'; eval { choose( {} ); 1 } and die 'choose( {} );'; eval { choose( undef, {} ); 1 } and die 'choose( undef, {} );'; eval { choose( 'a' ); 1 } and die 'choose( "a" );'; eval { choose( 1, {} ); 1 } and die 'choose( 1, {} );'; eval { choose( [], [] ); 1 } and die 'choose( [], [] );'; eval { choose( [], 'b' ); 1 } and die 'choose( [], "b" );'; eval { choose( [], { hello => 1, world => 2 } ); 1 } and die 'choose( [], { hello => 1, world => 2 } );'; my $valid_values = Y_Data_Test_Arguments::invalid_values(); for my $opt ( sort keys %$valid_values ) { for my $val ( @{$valid_values->{$opt}} ) { eval { choose( [], { $opt => $val } ); 1 } and die "choose( { $opt => $val } );"; } } eval { choose( [], Y_Data_Test_Arguments::mixed_invalid_1() ); 1 } and die 'choose( >>> );'; eval { choose( [], Y_Data_Test_Arguments::mixed_invalid_2() ); 1 } and die 'choose( <<< );'; print "\n"; Term-Choose-1.511/xt/Z1_hide_cursor.t0000644000175000001440000000265212626746534015722 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use FindBin qw( $RealBin ); use File::Spec::Functions qw( catfile ); BEGIN { if ( $^O eq 'MSWin32' ) { plan skip_all => "MSWin32: Expect not available."; } #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; #} } eval "use Expect"; if ( $@ ) { plan skip_all => $@; } use lib $RealBin; use Z_Data_Test_Choose; my $type = 'hide_cursor'; my $exp; eval { $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->set_winsize( 24, 80, undef, undef ); my $command = $^X; my $script = catfile $RealBin, 'Z_choose.pl'; my @parameters = ( $script, $type ); -r $script or die "$script is NOT readable"; $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; 1; } or plan skip_all => $@; my $a_ref = Z_Data_Test_Choose::return_test_data( $type ); my $ref = shift @$a_ref; my $expected = $ref->{expected}; my $ret = $exp->expect( 2, [ 'Your choice: ' => sub { $exp->send( "\r" ); 'exp_continue'; } ], [ $expected => sub {} ], ); ok( $ret, 'matched something' ); my $result = $exp->match(); $result = '' if ! defined $result; ok( $result eq $expected, "expected: '$expected', got: '$result'" ); $exp->hard_close(); done_testing(); Term-Choose-1.511/xt/prereqs.t0000644000175000001440000000022612626746534014516 0ustar mmusersuse 5.010000; use warnings; use strict; use Test::More; use Test::Prereq; prereq_ok( undef, undef, [ qw( Data_Test_Arguments Data_Test_Choose ) ] ); Term-Choose-1.511/xt/pod_defaults.t0000644000175000001440000000436713223366143015504 0ustar mmusersuse 5.010000; use strict; use warnings; no if $] >= 5.018, warnings => "experimental::smartmatch"; use Test::More; my @long = ( qw( pad empty undef ll default max_height max_width lf keep no_spacebar mark ) ); my @simple = ( qw( justify layout order clear_screen page mouse beep hide_cursor index ) ); # prompt my @all = ( @long, @simple ); my @deprecated = ( qw() ); plan tests => 2 + scalar @all; my $file = 'lib/Term/Choose.pm'; my $fh; my %option_default; open $fh, '<', $file or die $!; while ( my $line = <$fh> ) { if ( $line =~ /^sub __defaults \{/ .. $line =~ /^\}/ ) { if ( $line =~ m|^\s+#?\s*(\w+)\s+=>\s(\S+),| ) { my $op = $1; next if $op eq 'prompt'; next if $op ~~ @deprecated; $option_default{$op} = $2; $option_default{$op} =~ s/^undef\z/undefined/; $option_default{$op} =~ s/^["']([^'"]+)["']\z/$1/; } } } close $fh; my %pod_default; my %pod; for my $key ( @all ) { next if $key ~~ @deprecated; open $fh, '<', $file or die $!; while ( my $line = <$fh> ) { if ( $line =~ /^=head2\s\Q$key\E/ ... $line =~ /^=head/ ) { chomp $line; next if $line =~ /^\s*\z/; push @{$pod{$key}}, $line; } } close $fh; } for my $key ( @simple ) { next if $key ~~ @deprecated; my $opt; for my $line ( @{$pod{$key}} ) { if ( $line =~ /(\d).*\(default\)/ ) { $pod_default{$key} = $1; last; } } } for my $key ( @long ) { next if $key ~~ @deprecated; for my $line ( @{$pod{$key}} ) { if ( $line =~ /default:\s["']([^'"]+)["'](?:\)|\s*)/ ) { $pod_default{$key} = $1; last; } if ( $line =~ /default:\s(\w+)(?:\)|\s*)/ ) { $pod_default{$key} = $1; last; } } } is( scalar @all, scalar keys %option_default, 'scalar @all == scalar keys %option_default' ); is( scalar keys %pod_default, scalar keys %option_default, 'scalar keys %pod_default == scalar keys %option_default' ); for my $key ( sort keys %option_default ) { next if $key ~~ @deprecated; is( $option_default{$key}, $pod_default{$key}, "option $key: default value in pod matches default value in code" ); } Term-Choose-1.511/xt/Y_Data_Test_Arguments.pm0000644000175000001440000001072113223366321017356 0ustar mmuserspackage # hide Y_Data_Test_Arguments; use 5.008003; use warnings; use strict; sub valid_values { return { beep => [ 0, 1 ], clear_screen => [ 0, 1 ], hide_cursor => [ 0, 1 ], index => [ 0, 1 ], justify => [ 0, 1, 2 ], layout => [ 0, 1, 2, 3 ], mouse => [ 0, 1, 2, 3, 4 ], order => [ 0, 1 ], page => [ 0, 1 ], # '[ 1-9 ][ 0-9 ]*' keep => [ 1, 2, 100, 999999, undef ], ll => [ 1, 2, 100, 999999, undef ], max_height => [ 1, 2, 100, 999999, undef ], max_width => [ 1, 2, 100, 999999, undef ], # '[ 0-9 ]+' default => [ 0, 1, 2, 100, 999999, undef ], pad => [ 0, 1, 2, 100, 999999, undef ], # '' empty => [ 0, 'Hello' x 50, '', ' ', 'abc', 'world', undef ], prompt => [ 0, 'Hello' x 50, '', ' ', 'abc', 'world', undef ], undef => [ 0, 'Hello' x 50, '', ' ', 'abc', 'world', undef ], # ARRAY max 2 int lf => [ [ 2, 4 ], [ 8 ], [], undef ], # ARRAY int mark => [ [ 0, 1, 2, 100, 999999 ], [ 1 ], undef ], no_spacebar => [ [ 0, 1, 2, 100, 999999 ], [ 1 ], undef ], }; } sub mixed_options_1 { return { beep => 0, clear_screen => undef, hide_cursor => 1, index => 0, justify => 0, layout => 0, mouse => 0, order => 1, page => 0, keep => 1, ll => 1, max_height => 19, max_width => 19, default => 9, pad => 3, empty => '', prompt => '', undef => '', lf => [ 1 ], no_spacebar => [ 0 ], mark => [ 3, 4 ] }; } sub mixed_options_2 { return { mark => [ 0 ], no_spacebar => [ 11, 0, 8 ], lf => [ 1, 1 ], undef => '', prompt => 'prompt_line', empty => '', pad => 3, default => 9, max_width => 19, max_height => 119, ll => 15, keep => 1, page => 1, order => 1, mouse => 0, layout => 3, justify => 0, index => 0, hide_cursor => 1, clear_screen => undef, beep => 0 }; } ################################################################################################## sub invalid_values { my @invalid = ( -1, 2, 2 .. 10, 999999, '01', '', 'a', { 1, 1 }, [ 1 ], [ 2 ] ); return{ beep => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], clear_screen => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], hide_cursor => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], index => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], justify => [ grep { ! /^[ 0 1 2 ]\z/x } @invalid ], layout => [ grep { ! /^[ 0 1 2 3 ]\z/x } @invalid ], mouse => [ grep { ! /^[ 0 1 2 3 4 ]\z/x } @invalid ], order => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], page => [ grep { ! /^[ 0 1 ]\z/x } @invalid ], keep => [ grep { ! /^[ 1-9 ][ 0-9 ]*\z/x } @invalid ], ll => [ grep { ! /^[ 1-9 ][ 0-9 ]*\z/x } @invalid ], max_height => [ grep { ! /^[ 1-9 ][ 0-9 ]*\z/x } @invalid ], max_width => [ grep { ! /^[ 1-9 ][ 0-9 ]*\z/x } @invalid ], default => [ grep { ! /^[ 0-9 ]+\z/x } @invalid ], pad => [ grep { ! /^[ 0-9 ]+\z/x } @invalid ], # '' empty => [ { 1, 1 }, [ 1 ], {}, [], [ 2 ] ], prompt => [ { 1, 1 }, [ 1 ], {}, [], [ 2 ] ], undef => [ { 1, 1 }, [ 1 ], {}, [], [ 2 ] ], # ARRAY max 2 int lf => [ -2, -1, 0, 1, '', 'a', { 1, 1 }, {}, [ 1, 2, 3, ], [ 'a', 'b' ], [ -3, -4 ] ], # ARRAY int mark => [ -2, -1, 0, 1, '', 'a', { 1, 1 }, {}, [ 'a', 'b' ], [ -3, -4 ] ], no_spacebar => [ -2, -1, 0, 1, '', 'a', { 1, 1 }, {}, [ 'a', 'b' ], [ -3, -4 ] ], }; } sub mixed_invalid_1 { return { beep => -1, clear_screen => 2, hide_cursor => 3, index => 4, justify => '@', layout => 5, mouse => {}, order => 1, page => 0, keep => -1, ll => -1, max_height => 0, max_width => 0, default => [], pad => 'a', empty => [], prompt => {}, undef => [], lf => 4, no_spacebar => 4, mark => 'o' }; } sub mixed_invalid_2 { return { mark => '', no_spacebar => 'a', lf => 'b', undef => [], prompt => {}, empty => {}, pad => 'd', default => 'e', max_width => -1, max_height => -2, ll => -4, keep => -5, page => -6, order => -7, mouse => 'k', layout => 'e', justify => [], index => {}, hide_cursor => -1, clear_screen => [], beep => 10 }; } 1; __END__ Term-Choose-1.511/xt/Z_Data_Test_Choose.pm0000644000175000001440000004160313223366374016645 0ustar mmuserspackage # hide Z_Data_Test_Choose; use 5.008003; use warnings; use strict; sub key_seq { return { CONTROL_at => "\x{00}", CONTROL_Space => "\x{00}", CONTROL_C => "\x{03}", CONTROL_D => "\x{04}", CONTROL_H => "\x{08}", BTAB => "\x{08}", BSPACE => "\x{7f}", BTAB_Z => "\e[Z", BTAB_OZ => "\eOZ", CONTROL_I => "\x{09}", TAB => "\x{09}", CONTROL_M => "\x{0d}", ENTER => "\x{0d}", SPACE => "\x{20}", Key_q => "\x{71}", Key_k => "\x{6b}", UP => "\e[A", UP_O => "\eOA", Key_j => "\x{6a}", DOWN => "\e[B", DOWN_O => "\eOB", Key_l => "\x{6c}", RIGHT => "\e[C", RIGHT_O => "\eOC", Key_h => "\x{68}", LEFT => "\e[D", LEFT_O => "\eOD", CONTROL_B => "\x{02}", PAGE_UP => "\e[5~", CONTROL_F => "\x{06}", PAGE_DOWN => "\e[6~", CONTROL_A => "\x{01}", HOME => "\e[H", CONTROL_E => "\x{05}", END => "\e[F", } } my $simple = [ { list => [ 2 ], used_keys => [ qw( ENTER ) ], expected => "<2>", options => { prompt => 'Your choice: ', order => 0, layout => 0, hide_cursor => 0 }, }, ]; my $hide_cursor = [ { list => [ 1 .. 199 ], used_keys => [ qw( ENTER ) ], expected => "<1>", options => { prompt => 'Your choice: ', order => 0, layout => 0, hide_cursor => 1, clear_screen => 0 } }, ]; # CONTROL_C # KEY_q CONTROL_D my $k_list = [ 0 .. 1999 ]; my $k_options = { default => 1007, order => 0, layout => 0, hide_cursor => 0 }; my $seq_test = [ #{ list => $k_list, used_keys => [ qw( ENTER ) ], expected => "<1007>", options => $k_options, }, #{ list => $k_list, used_keys => [ qw( CONTROL_M ) ], expected => "<1007>", options => $k_options, }, { list => $k_list, used_keys => [ qw( RIGHT ) ], expected => "<1008>", options => $k_options, }, { list => $k_list, used_keys => [ qw( RIGHT_O ) ], expected => "<1008>", options => $k_options, }, { list => $k_list, used_keys => [ qw( Key_l ) ], expected => "<1008>", options => $k_options, }, { list => $k_list, used_keys => [ qw( LEFT ) ], expected => "<1006>", options => $k_options, }, { list => $k_list, used_keys => [ qw( LEFT_O ) ], expected => "<1006>", options => $k_options, }, { list => $k_list, used_keys => [ qw( Key_h ) ], expected => "<1006>", options => $k_options, }, { list => $k_list, used_keys => [ qw( DOWN ) ], expected => "<1020>", options => $k_options, }, { list => $k_list, used_keys => [ qw( DOWN_O ) ], expected => "<1020>", options => $k_options, }, { list => $k_list, used_keys => [ qw( Key_j ) ], expected => "<1020>", options => $k_options, }, { list => $k_list, used_keys => [ qw( UP ) ], expected => "<994>", options => $k_options, }, { list => $k_list, used_keys => [ qw( UP_O ) ], expected => "<994>", options => $k_options, }, { list => $k_list, used_keys => [ qw( Key_k ) ], expected => "<994>", options => $k_options, }, { list => $k_list, used_keys => [ qw( TAB ) ], expected => "<1008>", options => $k_options, }, { list => $k_list, used_keys => [ qw( CONTROL_I ) ], expected => "<1008>", options => $k_options, }, { list => $k_list, used_keys => [ qw( BSPACE ) ], expected => "<1006>", options => $k_options, }, { list => $k_list, used_keys => [ qw( CONTROL_H ) ], expected => "<1006>", options => $k_options, }, { list => $k_list, used_keys => [ qw( BTAB ) ], expected => "<1006>", options => $k_options, }, { list => $k_list, used_keys => [ qw( BTAB_Z ) ], expected => "<1006>", options => $k_options, }, { list => $k_list, used_keys => [ qw( BTAB_OZ ) ], expected => "<1006>", options => $k_options, }, { list => $k_list, used_keys => [ qw( HOME ) ], expected => "<0>", options => $k_options, }, { list => $k_list, used_keys => [ qw( CONTROL_A ) ], expected => "<0>", options => $k_options, }, { list => $k_list, used_keys => [ qw( END ) ], expected => "<1999>", options => $k_options, }, { list => $k_list, used_keys => [ qw( CONTROL_E ) ], expected => "<1999>", options => $k_options, }, { list => $k_list, used_keys => [ qw( PAGE_DOWN ) ], expected => "<1293>", options => $k_options, }, { list => $k_list, used_keys => [ qw( CONTROL_F ) ], expected => "<1293>", options => $k_options, }, { list => $k_list, used_keys => [ qw( PAGE_UP ) ], expected => "<721>", options => $k_options, }, { list => $k_list, used_keys => [ qw( CONTROL_B ) ], expected => "<721>", options => $k_options, }, { list => $k_list, used_keys => [ qw( SPACE ) ], expected => "<1007>", options => $k_options, }, { list => $k_list, used_keys => [ qw( CONTROL_Space ) ],expected => "<@{[858..1143]}>", options => $k_options , }, { list => $k_list, used_keys => [ qw( CONTROL_at ) ], expected => "<@$k_list>", options => { %$k_options, default => 0 }, }, ]; ############################################################################################################## my $keys = { long => [ qw( SPACE END SPACE HOME SPACE CONTROL_E PAGE_UP SPACE CONTROL_B CONTROL_B CONTROL_B CONTROL_B CONTROL_B CONTROL_B SPACE TAB TAB TAB TAB TAB TAB TAB TAB TAB TAB DOWN DOWN DOWN SPACE RIGHT DOWN_O DOWN_O Key_j SPACE LEFT_O LEFT_O Key_h Key_h SPACE PAGE_DOWN CONTROL_F CONTROL_F SPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE CONTROL_H CONTROL_H CONTROL_H CONTROL_H CONTROL_H BTAB BTAB BTAB_Z BTAB_OZ SPACE UP UP UP UP_O UP_O UP_O Key_k Key_k Key_k SPACE RIGHT_O CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I SPACE PAGE_DOWN PAGE_DOWN PAGE_DOWN PAGE_UP PAGE_UP PAGE_UP PAGE_UP PAGE_UP PAGE_UP SPACE END LEFT ENTER ) ], short => [ qw( SPACE END SPACE HOME SPACE CONTROL_E PAGE_UP SPACE SPACE TAB TAB TAB TAB TAB TAB TAB TAB TAB TAB SPACE RIGHT SPACE LEFT_O LEFT_O Key_h Key_h SPACE PAGE_DOWN SPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE BSPACE CONTROL_H CONTROL_H CONTROL_H CONTROL_H CONTROL_H BTAB BTAB BTAB_Z BTAB_OZ SPACE UP UP UP_O UP_O Key_k Key_k SPACE DOWN DOWN_O Key_j SPACE RIGHT_O CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I CONTROL_I SPACE END LEFT ENTER ) ], }; my $list = { long => [ 0 .. 1999 ], short => [ 0 .. 99 ], long_test_index => [ map { s/^\d/chr( $& + 97 )/e; $_ } 0 .. 1999 ], short_test_index => [ map { s/^\d/chr( $& + 97 )/e; $_ } 0 .. 99 ], ll => [ ( "In" . '.' x 7, "scalar" . '.' x 3, "context" . '.' x 2, "returns" . '.' x 2, "the" . '.' x 6, "number" . '.' x 3, "of" . '.' x 7, "elements" . '.' x 1, "so" . '.' x 7, "generated" , "hello" . '.' x 4, "world" . '.' x 4, "12345678" . '.' x 1, "The" . '.' x 6, "black" . '.' x 4, "cat" . '.' x 6, "jumped" . '.' x 3, "from" . '.' x 5, "the" . '.' x 6, "green" . '.' x 4, "tree" . '.' x 5, "abcdefghi" , ) x 2 ], }; my $options = [ { max_height => undef, max_width => undef, layout => 0 }, { max_height => 20, max_width => undef, layout => 0 }, { max_height => undef, max_width => undef, layout => 1 }, { max_height => 20, max_width => undef, layout => 3 }, { max_height => undef, max_width => 61, layout => 2 }, { max_height => 20, max_width => 60, layout => 0 }, { max_height => 20, max_width => 60, layout => 1 }, { max_height => 20, max_width => 60, layout => 2 }, { max_height => 20, max_width => 60, layout => 3 }, { max_height => 20, max_width => 60, layout => 1, prompt => 'Your choice: ', page => 0, pad => 3, order => 1, justify => 2, keep => 8, clear_screen => 1 }, { max_height => 20, max_width => 60, layout => 1, prompt => 'Your choice: ' x 100, page => 0, pad => 3, order => 1, justify => 2, keep => 8, clear_screen => 1 }, { prompt => 'abc 12345678 def' x 50, default => 10, empty =>' ', undef => '--', beep => 1, no_spacebar => [ 11 .. 2000 ], lf => [ 0, 4 ], keep => 16 }, { max_height => 20, max_width => 60, layout => 0, mark => [ 0, 10, 100 ] }, { max_height => 20, max_width => 60, layout => 1, mark => [ 0, 10, 100 ], index => 1 }, { max_height => 20, max_width => 60, layout => 2, mark => [ 0, 10, 35, 100, 1979 ], no_spacebar => [ 35, 1066, 1979 ] }, { max_height => 20, max_width => 60, layout => 3, mark => [ 0, 10, 100 ] }, ]; my $c_opt; $c_opt = 0; my $long = [ { list => $list->{long}, used_keys => $keys->{long}, expected => "<83 92 951 1017 1410 1558 1567 1624 1846 1867 1977 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<69 78 943 1003 1402 1550 1559 1610 1846 1859 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<83 92 951 1017 1410 1558 1567 1624 1846 1867 1977 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<1859 1869 1872 1907 1916 1929 1935 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<1052 1118 1307 1316 1799 1843 1845 1849 1852 1909 1977 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<1066 1126 1315 1324 1799 1857 1859 1863 1866 1917 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<1066 1126 1315 1324 1799 1857 1859 1863 1866 1917 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<1066 1126 1315 1324 1799 1857 1859 1863 1866 1917 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<1859 1869 1872 1907 1916 1929 1935 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<86 89 149 312 748 808 1777 1859 1915 1924 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<170 173 197 396 832 856 1777 1943 1963 1972 1991 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<0 10 1846>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<0 10 100 1066 1126 1315 1324 1799 1857 1859 1863 1866 1917 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long_test_index}, used_keys => $keys->{long}, expected => "<0 10 100 1066 1126 1315 1324 1799 1857 1859 1863 1866 1917 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<0 10 35 100 1126 1315 1324 1799 1857 1859 1863 1866 1917 1979 1999>", options => $options->[$c_opt++], }, { list => $list->{long}, used_keys => $keys->{long}, expected => "<0 10 100 1859 1869 1872 1907 1916 1929 1935 1979 1999>", options => $options->[$c_opt++], }, ]; $c_opt = 0; my $short = [ { list => $list->{short}, used_keys => $keys->{short}, expected => "<80 94>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<80 94>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<7 10 12 67 93 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<64 67 70 89 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<35 38 41 69 85 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<7 10 12 67 93 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<41 44 47 50 91 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<35 38 41 69 85 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<64 67 70 89 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<61 64 67 89 96 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<41 44 47 50 91 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<0 7 93>", expected_w81 => "<0 10 93>", # "<0 7 93>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<0 7 12 67 93 99>", options => $options->[$c_opt++], }, { list => $list->{short_test_index}, used_keys => $keys->{short}, expected => "<0 10 41 44 47 50 91 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<0 10 35 38 41 69 85 99>", options => $options->[$c_opt++], }, { list => $list->{short}, used_keys => $keys->{short}, expected => "<0 10 64 67 70 89 99>", options => $options->[$c_opt++], }, ]; my $option_ll = [ { list => $list->{ll}, used_keys => [ ( 'DOWN' ) x 3, 'SPACE', ( 'RIGHT' ) x 3, 'SPACE', 'HOME', 'ENTER' ], expected => "<0 3 30>", options => { ll => 9, layout => 1 } }, { list => $list->{ll}, used_keys => [ 'END', 'SPACE', 'PAGE_UP', 'SPACE', ( 'UP' ) x 12, 'LEFT', 'ENTER' ], expected => "<9 21 43>", options => { ll => 9, layout => 3 } }, ]; sub return_test_data { my $type = shift; if ( $type eq 'simple' ) { return $simple; } elsif ( $type eq 'hide_cursor' ) { return $hide_cursor; } elsif ( $type eq 'seq_test' ) { return $seq_test; } elsif ( $type eq 'long' ) { return $long; } elsif ( $type eq 'short' ) { return $short; } elsif ( $type eq 'option_ll' ) { return $option_ll; } } 1; __END__ Term-Choose-1.511/xt/cntr_choose.t0000644000175000001440000000111712626746534015343 0ustar mmusersuse 5.010000; use strict; use warnings; use Test::More tests => 1; my $file = 'lib/Term/Choose.pm'; my $test_env = 0; open my $fh1, '<', $file or die $!; while ( my $line = <$fh1> ) { if ( $line =~ /\$\s*SIG\s*{\s*__WARN__\s*}/ ) { $test_env++; } if ( $line =~ /^\s*use\s+warnings\s+FATAL/s ) { $test_env++; } if ( $line =~ /(?:^\s*|\s+)use\s+Log::Log4perl/ ) { $test_env++; } if ( $line =~ /(?:^\s*|\s+)use\s+Data::Dumper/ ) { $test_env++; } } close $fh1; is( $test_env, 0, "OK - test environment in $file disabled." ); Term-Choose-1.511/xt/Z_choose.pl0000755000175000001440000000064012626746534014761 0ustar mmusers#!/usr/bin/env perl use warnings; use strict; use 5.008003; use Term::Choose qw( choose ); use FindBin qw( $RealBin ); use lib $RealBin; use Z_Data_Test_Choose; my $type = shift; my $a_ref = Z_Data_Test_Choose::return_test_data( $type ); for my $ref ( @$a_ref ) { my $opt = $ref->{options}; my $list = $ref->{list}; my @choice = choose( $list, $opt ); print "<@choice>\n"; } Term-Choose-1.511/xt/Y3_choose_function.t0000644000175000001440000000225012626746534016574 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use FindBin qw( $RealBin ); use File::Spec::Functions qw( catfile ); BEGIN { if ( $^O eq 'MSWin32' ) { plan skip_all => "MSWin32: Expect not available."; } #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; #} } eval "use Expect"; if ( $@ ) { plan skip_all => $@; } my $exp; eval { $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->set_winsize( 24, 80, undef, undef ); my $command = $^X; my $script = catfile $RealBin, 'Y_choose_function_arguments.pl'; my @parameters = ( $script ); -r $script or die "$script is NOT readable"; $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; 1; } or plan skip_all => $@; my $expected = ''; my $ret = $exp->expect( 2, [ qr/(?:match(); $result = '' if ! defined $result; ok( $result =~ $expected, "expected: '$expected', got: '$result'" ); $exp->hard_close(); done_testing(); Term-Choose-1.511/xt/pod.t0000644000175000001440000000013512626746534013616 0ustar mmusersuse 5.010000; use strict; use warnings; use Test::More; use Test::Pod; all_pod_files_ok(); Term-Choose-1.511/xt/00_get_key_linux.t0000644000175000001440000000537112626746534016210 0ustar mmusersuse 5.010000; use warnings; use strict; use Test::More; use FindBin qw( $RealBin ); use File::Spec::Functions qw( catfile ); BEGIN { if ( $^O eq 'MSWin32' ) { plan skip_all => "MSWin32: Expect not available."; } #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; #} } eval "use Expect"; if ( $@ ) { plan skip_all => "Expect required for $0."; } eval "use Term::ReadKey"; if ( $@ ) { plan skip_all => $@; } use Term::Choose::Constants qw( :linux ); my $script = catfile $RealBin, 'get_key_linux.pl'; eval { my $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->slave->set_winsize( 24, 80, undef, undef ); -r $script or die "$script is NOT readable $!"; $exp->spawn( $script ) or die "Spawn '$script' NOT ok $!"; 1; } or plan skip_all => $@; for my $char ( qw( h j k l q ), ' ', "\t" ) { my $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->slave->set_winsize( 24, 80, undef, undef ); $exp->spawn( $script ); $exp->send( $char ); my $expected = '<' . ord( $char ) . '>'; my $ret = $exp->expect( 3, [ qr/...+/ ] ); ok( $ret, 'matched something' ); my $result = $exp->match() // ''; ok( $result eq $expected, "expected: '$expected', got: '$result'" ); $exp->soft_close(); } for my $char ( "\cA", "\cB", "\cC", "\cD", "\cE", "\cF", "\cH", "\cI", "\c@" ) { my $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->slave->set_winsize( 24, 80, undef, undef ); $exp->spawn( $script ); $exp->send( $char ); my $expected = '<' . ord( $char ) . '>'; my $ret = $exp->expect( 3, [ qr/...+/ ] ); ok( $ret, 'matched something' ); my $result = $exp->match() // ''; ok( $result eq $expected, "expected: '$expected', got: '$result'" ); $exp->soft_close(); } my $array = [ [ [ "\e[A", "\eOA" ], VK_UP ], [ [ "\e[B", "\eOB" ], VK_DOWN ], [ [ "\e[C", "\eOC" ], VK_RIGHT ], [ [ "\e[D", "\eOD" ], VK_LEFT ], [ [ "\e[F", "\eOF" ], VK_END ], [ [ "\e[H", "\eOH" ], VK_HOME ], [ [ "\e[Z", "\eOZ" ], KEY_BTAB ], [ [ "\e[5~" ], VK_PAGE_UP ], [ [ "\e[6~" ], VK_PAGE_DOWN ], ]; for my $elem ( @$array ) { for my $seq ( @{$elem->[0]} ) { my $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->slave->set_winsize( 24, 80, undef, undef ); $exp->spawn( $script ); $exp->send( $seq ); my $expected = '<' . $elem->[1] . '>'; my $ret = $exp->expect( 3, [ qr/...+/ ] ); ok( $ret, 'matched something' ); my $result = $exp->match() // ''; ok( $result eq $expected, "expected: '$expected', got: '$result'" ); $exp->soft_close(); } } done_testing(); Term-Choose-1.511/xt/perl_minimum_version.t0000644000175000001440000000327012626746534017301 0ustar mmusersuse 5.010000; use warnings; use strict; use Perl::MinimumVersion; use Perl::Version; use File::Find; use Test::More tests => 2; my $make_minimum; open my $fh_m, '<', 'Makefile.PL' or die $!; while ( my $line = <$fh_m> ) { if ( $line =~ /^\s*MIN_PERL_VERSION\s*=>\s*'([^']+)',/ ) { my $version = Perl::Version->new( $1 ); my $numified = $version->numify; $make_minimum = $numified; last; } } close $fh_m or die $!; my $pod_minimum; open my $fh_p, '<', 'lib/Term/Choose.pm' or die $!; while ( my $line = <$fh_p> ) { if ( $line =~ /^=head2\s+Perl\s+version/ .. $line =~ /^=head2\s+Modules/ ) { if ( $line =~ /Perl\sversion\s(5\.\d\d?\.\d+)\s/ ) { my $version = Perl::Version->new( $1 ); my $numified = $version->numify; $pod_minimum = $numified; last; } } } close $fh_p or die $!; my @files; for my $dir ( 'lib', 't' ) { find( { wanted => sub { my $file = $File::Find::name; return if ! -f $file; push @files, $file; }, no_chdir => 1, }, $dir ); } my %explicit_minimum; for my $file ( @files ) { my $object = Perl::MinimumVersion->new( $file ); my $min_exp_v = $object->minimum_explicit_version; my $version = Perl::Version->new( $min_exp_v ); my $numified = $version->numify; $explicit_minimum{$numified}++; } my ( $explicit_minimum ) = keys %explicit_minimum; cmp_ok( $make_minimum, '==', $explicit_minimum, 'perl minimum version in Makefile.PL == explicit perl minimum version' ); cmp_ok( $make_minimum, '==', $pod_minimum, 'perl minimum version in Makefile.PL == pod perl minimum version' ); Term-Choose-1.511/xt/Z2_choose.t0000644000175000001440000000730013223365431014653 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use FindBin qw( $RealBin ); use File::Spec::Functions qw( catfile ); BEGIN { if ( $^O eq 'MSWin32' ) { plan skip_all => "MSWin32: Expect not available."; } #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; #} } eval "use Expect"; if ( $@ ) { plan skip_all => $@; } use lib $RealBin; use Z_Data_Test_Choose; my $command = $^X; my $timeout = 5; my $choose_pl = catfile $RealBin, 'Z_choose.pl'; my $key = Z_Data_Test_Choose::key_seq(); { my $type = 'seq_test'; my $rows = 24; my $cols = 80; my @parameters = ( $choose_pl, $type ); my $exp; eval { $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->set_winsize( $rows, $cols, undef, undef ); $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; 1; } or plan skip_all => $@; subtest 'seq_test', sub { my $a_ref = Z_Data_Test_Choose::return_test_data( $type ); for my $ref ( @$a_ref ) { my $pressed_keys = $ref->{used_keys}; my $expected = $ref->{expected}; $exp->send( @{$key}{@$pressed_keys}, $key->{ENTER} ); my $ret = $exp->expect( $timeout, [ qr/<.+>/ ] ); my $result = $exp->match(); $result = '' if ! defined $result; ok( $expected eq $result, "'@{$ref->{used_keys}}' OK: " . sprintf( "%10.10s - %10.10s", $expected, $result ) ); } $exp->hard_close(); done_testing(); } } my @types = ( qw( long short option_ll ) ); my $rows = 24; my $cols = 80; for my $type ( @types ) { my $a_ref = Z_Data_Test_Choose::return_test_data( $type ); my @parameters = ( $choose_pl, $type ); subtest 'choose ' . $type, sub { my $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->set_winsize( $rows, $cols, undef, undef ); $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; for my $ref ( @$a_ref ) { my $pressed_keys = $ref->{used_keys}; my $expected = $ref->{expected}; $exp->send( @{$key}{@$pressed_keys} ); my $ret = $exp->expect( $timeout, [ qr/<.+>/ ] ); my $result = $exp->match(); $result = '' if ! defined $result; ok( $ret, 'matched something' ); ok( $result eq $expected, "expected: '$expected', got: '$result'" ); } $exp->hard_close(); done_testing(); }; } $rows = 24; $cols = 81; for my $type ( @types ) { my $a_ref = Z_Data_Test_Choose::return_test_data( $type ); my @parameters = ( $choose_pl, $type ); subtest 'choose ' . $type, sub { my $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->set_winsize( $rows, $cols, undef, undef ); $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; for my $ref ( @$a_ref ) { my $pressed_keys = $ref->{used_keys}; my $expected = defined $ref->{expected_w81} ? $ref->{expected_w81} : $ref->{expected}; $exp->send( @{$key}{@$pressed_keys} ); my $ret = $exp->expect( $timeout, [ qr/<.+>/ ] ); my $result = $exp->match(); $result = '' if ! defined $result; ok( $ret, 'matched something' ); ok( $result eq $expected, "expected: '$expected', got: '$result'" ); } $exp->hard_close(); done_testing(); }; } done_testing(); Term-Choose-1.511/xt/synopsis.t0000644000175000001440000000016312626746534014724 0ustar mmusersuse 5.010000; use strict; use warnings; use Test::Synopsis; use lib 'lib'; use Term::Choose; all_synopsis_ok(); Term-Choose-1.511/xt/02_option_error.t0000644000175000001440000000654613223366527016064 0ustar mmusersuse 5.010000; use warnings; use strict; use utf8; use Test::More; use Test::Fatal; use lib 'lib'; use Term::Choose qw( choose ); no warnings 'redefine'; sub Term::Choose::__get_key { sleep 0.01; return 0x0d }; close STDIN or plan skip_all => "Close STDIN $!"; my $stdin = "eingabe\n"; open STDIN, "<", \$stdin or plan skip_all => "STDIN $!"; close STDOUT or plan skip_all => "Close STDOUT $!"; close STDERR or plan skip_all => "Close STDERR $!"; my ( $tmp_stdout, $tmp_stderr ); open STDOUT, '>', \$tmp_stdout or plan skip_all => "STDOUT $!"; open STDERR, '>', \$tmp_stderr or plan skip_all => "STDERR $!"; my $choices = [ '', 0, undef, 1, 2, 3, 'aa' .. 'zz', '☻☮☺', "\x{263a}\x{263b}", '한글', 'æða' ]; my $d; my $begin_errormessage = qr/^choose:/; my $int = { beep => '[ 0 1 ]', clear_screen => '[ 0 1 ]', hide_cursor => '[ 0 1 ]', index => '[ 0 1 ]', justify => '[ 0 1 2 ]', layout => '[ 0 1 2 3 ]', mouse => '[ 0 1 2 3 4 ]', order => '[ 0 1 ]', page => '[ 0 1 ]', keep => '[ 1-9 ][ 0-9 ]*', ll => '[ 1-9 ][ 0-9 ]*', max_height => '[ 1-9 ][ 0-9 ]*', max_width => '[ 1-9 ][ 0-9 ]*', default => '[ 0-9 ]+', pad => '[ 0-9 ]+', }; my @wrong = ( -1, 2, 2 .. 10, 999999, '01', '', 'a', { 1, 1 }, [ 1 ], {}, [], [ 2 ] ); for my $opt ( sort keys %$int ) { for my $val ( grep { ! /^$int->{$opt}\z/x } @wrong ) { my $exception = exception { $d = choose( $choices, { $opt => $val } ) }; ok( $exception =~ $begin_errormessage ); } } my $string = { empty => '', prompt => '', undef => '', }; my @wrong_string = ( { 1, 1 }, [ 1 ], {}, [], [ 2 ] ); for my $opt ( sort keys %$string ) { for my $val ( grep { ref } @wrong_string ) { my $exception = exception { $d = choose( $choices, { $opt => $val } ) }; ok( $exception =~ $begin_errormessage ); } } my $lf = { lf => 'ARRAY', }; my @val_lf = ( -2, -1, 0, 1, '', 'a', { 1, 1 }, {} ); for my $opt ( sort keys %$lf ) { for my $val ( @val_lf ) { my $exception = exception { $d = choose( $choices, { $opt => $val } ) }; ok( $exception =~ $begin_errormessage ); } } my $no_spacebar = { no_spacebar => 'ARRAY', }; my @val_no_spacebar = ( -2, -1, 0, 1, '', 'a', { 1, 1 }, {} ); for my $opt ( sort keys %$no_spacebar ) { for my $val ( @val_no_spacebar ) { my $exception = exception { $d = choose( $choices, { $opt => $val } ) }; ok( $exception =~ $begin_errormessage ); } } my $exception = exception { $d = choose( $choices, { beep => -1, clear_screen => 2, hide_cursor => 3, index => 4, justify => '@', layout => 5, mouse => {}, order => 1, page => 0, keep => -1, ll => -1, max_height => 0, max_width => 0, default => [], pad => 'a', empty => [], prompt => {}, undef => [], lf => 4, no_spacebar => 4 } ) }; ok( $exception =~ $begin_errormessage ); $exception = exception { $d = choose( [ 'aaa' .. 'zzz' ], { no_spacebar => 'a', lf => 'b', undef => [], prompt => {}, empty => {}, pad => 'd', default => 'e', max_width => -1, max_height => -2, ll => -4, keep => -5, page => -6, order => -7, mouse => 'k', layout => 'e', justify => [], index => {}, hide_cursor => -1, clear_screen => [], beep => 10 } ) }; ok( $exception =~ $begin_errormessage ); done_testing(); __DATA__ Term-Choose-1.511/xt/Z0_clone_win.t0000644000175000001440000000255312626746534015370 0ustar mmusersuse 5.008003; use warnings; use strict; use Test::More; use FindBin qw( $RealBin ); use File::Spec::Functions qw( catfile ); BEGIN { if ( $^O eq 'MSWin32' ) { plan skip_all => "MSWin32: Expect not available."; } #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; #} } eval "use Expect"; if ( $@ ) { plan skip_all => $@; } use lib $RealBin; use Z_Data_Test_Choose; my $type = 'simple'; my $exp; eval { $exp = Expect->new(); $exp->raw_pty( 1 ); $exp->log_stdout( 0 ); $exp->slave->clone_winsize_from( \*STDIN ); my $command = $^X; my $script = catfile $RealBin, 'Z_choose.pl'; my @parameters = ( $script, $type ); -r $script or die "$script is NOT readable"; $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; 1; } or plan skip_all => $@; my $a_ref = Z_Data_Test_Choose::return_test_data( $type ); my $ref = shift @$a_ref; my $ret = $exp->expect( 2, [ qr/Your choice: .*/ ] ); my $expected = $ref->{expected}; $exp->send( "\r" ); $ret = $exp->expect( 2, [ qr/<.+>/ ] ); ok( $ret, 'matched something' ); my $result = $exp->match(); $result = '' if ! defined $result; ok( $result eq $expected, qq[expected: "$expected", got: "$result"] ); $exp->hard_close(); done_testing(); Term-Choose-1.511/xt/perlcriticrc0000644000175000001440000000027112626746534015260 0ustar mmusersseverity = 5 verbose = 8 [InputOutput::RequireCheckedSyscalls] functions = :builtins exclude_functions = print [TestingAndDebugging::ProhibitNoWarnings] allow = utf8 uninitialized Term-Choose-1.511/xt/spelling.t0000644000175000001440000000035612626746534014656 0ustar mmusersuse 5.010000; use strict; use warnings; use Test::More; use Test::Spelling; add_stopwords(); all_pod_files_spelling_ok(); __DATA__ BackSpace Ctrl EOT Kiem Matthäus PageDown PageUp ReadKey SGR SpaceBar hjkl lf ll stackoverflow Term-Choose-1.511/xt/get_key_linux.pl0000755000175000001440000000026312626746534016057 0ustar mmusers#!/usr/bin/env perl use warnings; use strict; use 5.010000; use Term::Choose::Linux; my $linux = Term::Choose::Linux->new(); my $key = $linux->__get_key_OS( 0 ); say "<$key>"; Term-Choose-1.511/xt/version2.t0000644000175000001440000000500012626746534014577 0ustar mmusersuse 5.010000; use strict; use warnings; use Time::Piece; use Test::More tests => 6; my $v = -1; my $v_pod = -1; my $v_linux = -1; #my $v_pod_linux = -1; my $v_win32 = -1; #my $v_pod_win32 = -1; my $v_const = -1; my $v_changes = -1; my $release_date = -1; open my $fh, '<', 'lib/Term/Choose.pm' or die $!; while ( my $line = <$fh> ) { if ( $line =~ /^our\s\$VERSION\s=\s'(\d\.\d\d\d(?:_\d\d)?)';/ ) { $v = $1; } if ( $line =~ /^=pod/ .. $line =~ /^=cut/ ) { if ( $line =~ /^\s*Version\s+(\S+)/ ) { $v_pod = $1; } } } close $fh; open $fh, '<', 'lib/Term/Choose/Linux.pm' or die $!; while ( my $line = <$fh> ) { if ( $line =~ /^our\s\$VERSION\s=\s'(\d\.\d\d\d(?:_\d\d)?)';/ ) { $v_linux = $1; } # if ( $line =~ /^=pod/ .. $line =~ /^=cut/ ) { # if ( $line =~ /^\s*Version\s+(\S+)/ ) { # $v_pod_linux = $1; # } # } } close $fh; open $fh, '<', 'lib/Term/Choose/Win32.pm' or die $!; while ( my $line = <$fh> ) { if ( $line =~ /^our\s\$VERSION\s=\s'(\d\.\d\d\d(?:_\d\d)?)';/ ) { $v_win32 = $1; } # if ( $line =~ /^=pod/ .. $line =~ /^=cut/ ) { # if ( $line =~ /^\s*Version\s+(\S+)/ ) { # $v_pod_win32 = $1; # } # } } close $fh; open $fh, '<', 'lib/Term/Choose/Constants.pm' or die $!; while ( my $line = <$fh> ) { if ( $line =~ /^our\s\$VERSION\s=\s'(\d\.\d\d\d(?:_\d\d)?)';/ ) { $v_const = $1; } # if ( $line =~ /^=pod/ .. $line =~ /^=cut/ ) { # if ( $line =~ /^\s*Version\s+(\S+)/ ) { # $v_pod_const = $1; # } # } } close $fh; open my $fh_ch, '<', 'Changes' or die $!; while ( my $line = <$fh_ch> ) { if ( $line =~ /^\s*(\d+\.\d\d\d(?:_\d\d)?)\s+(\d\d\d\d-\d\d-\d\d)\s*\z/ ) { $v_changes = $1; $release_date = $2; last; } } close $fh_ch; my $t = localtime; my $today = $t->ymd; is( $v, $v_pod, 'Version in POD Term::Choose OK' ); is( $v, $v_linux, 'Version in Term::Choose::Linux OK' ); is( $v, $v_win32, 'Version in Term::Choose::Win32 OK' ); is( $v, $v_const, 'Version in Term::Choose::Constants OK' ); #is( $v, $v_pod_linux, 'Version in POD Term::Choose::Linux OK' ); #is( $v, $v_pod_win32, 'Version in POD Term::Choose::Win32 OK' ); is( $v, $v_changes, 'Version in "Changes" OK' ); is( $release_date, $today, 'Release date in Changes is date from today' ); Term-Choose-1.511/xt/whitespaces.t0000644000175000001440000000040112626746534015347 0ustar mmusersuse 5.010000; use strict; use warnings; use Test::Whitespaces { dirs => [ 'lib', 't', 'xt', 'example', ], files => [ 'README', 'Makefile.PL', 'Build.PL', 'Changes', ], }; Term-Choose-1.511/xt/version1.t0000644000175000001440000000033712626746534014606 0ustar mmusersuse 5.010000; use strict; use warnings; use Test::More; use Test::Version qw( version_ok ), { # is_strict => 1, has_version => 1, }; #version_all_ok( 'lib' ); version_ok( 'lib/Term/Choose.pm' ); done_testing;