Perl 是否有一个模块允许我在终端上通过上下键进行选择?

Perl 是否有一个模块允许我在终端上通过上下键进行选择?,perl,terminal,Perl,Terminal,是否有一个模块允许我使用上下键进行选择: 我不必像这里这样写我的选择,但我可以使用向上/向下键选择我最喜欢的颜色,然后按“回车”。如果您想在终端窗口中显示菜单,请尝试。它显示选项列表,并允许用户使用鼠标或箭头键选择一个或多个选项。如果我将Clui.pm(Term::Clui)中的布局功能替换为此布局功能 #!/usr/bin/env perl use warnings; use 5.12.0; use Term::UI; use Term::ReadLine; my $term = Term

是否有一个模块允许我使用上下键进行选择:

我不必像这里这样写我的选择,但我可以使用向上/向下键选择我最喜欢的颜色,然后按“回车”。

如果您想在终端窗口中显示菜单,请尝试。它显示选项列表,并允许用户使用鼠标或箭头键选择一个或多个选项。

如果我将Clui.pm(Term::Clui)中的布局功能替换为此布局功能

#!/usr/bin/env perl
use warnings; 
use 5.12.0;
use Term::UI;
use Term::ReadLine;

my $term = Term::ReadLine->new( 'brand' );
my @choices = ( qw( blue red green black white ) );
my $reply = $term->get_reply(
        prompt => 'What is your favorite color?',
        choices => \@choices,
        default => 'blue',
);
say $reply;

它做了我想要的(没有彻底的测试,也没有阅读整个源代码)

如果你真的想要完全的终端控制,你可以大骂一顿:这不是我想要的(假设我没有忽略什么):我希望每个选项都有一个新行,然后用上下键进行选择。要获得此行为,我必须在choose函数之前放置“@list=map{$\(”x(
tput cols
-(length($\)))}@list;”。
my $no_col = 1;
sub layout { 
    my @list = @_;
    $this_cell = 0; 
    my $irow = 1; 
    my $icol = 0;  
    for my $i ( 0 .. $#list ) {
        if ( not $no_col ) {
            $l[$i] = length( $list[$i] ) + 2;
            if ( $l[$i] > $maxcols - 1 ) {
                $l[$i] = $maxcols - 1; 
            }
            if ( ( $icol + $l[$i] ) >= $maxcols ) {
                $irow++; 
                $icol = 0;
            }
            $irow[$i] = $irow;
        }
        elsif ( $no_col ) {
            $irow[$i] = $irow++;
        }
        return $irow if $irow > $maxrows;
        $icol[$i] = $icol;
        $this_cell = $i if $list[$i] eq $choice;
        if ( not $no_col ) {
            $icol += $l[$i];
        }
    }
    return $irow if not $no_col;
    return --$irow if $no_col;
}