#!/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;
是否有一个模块可以让我选择上下键:
我不必像这里一样写下我的选择,但我可以使用上/下键到我喜欢的颜色的行,然后按“输入”。
答案 0 :(得分:2)
如果要在终端窗口中显示菜单,请尝试Term::Clui。它显示一个选项列表,让用户使用鼠标或箭头键选择一个或多个。
答案 1 :(得分:0)
如果我用这个布局函数替换Clui.pm(Term :: Clui)中的布局函数
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;
}
它做我想要的(没有彻底的测试,也没有阅读整个源代码)