我正在将Perl6 Terminal :: Print模块用于基于控制台的应用程序。
运行良好-但是,现在我需要提示用户输入一串文本。
执行此操作的好方法是什么?
答案 0 :(得分:8)
以下是使用Terminal::Print::RawInput
来获取文件名作为用户输入的示例:
use v6;
use Terminal::Print;
use Terminal::Print::RawInput;
my $screen = Terminal::Print.new;
# saves current screen state, blanks screen, and hides cursor
$screen.initialize-screen;
$screen.print-string(9, 23, "Enter filename: ");
my $in-supply = raw-input-supply;
my $filename;
react {
whenever $in-supply -> $c {
done if $c.ord ~~ 3|13; # Enter pressed or CTRL-C pressed
my $char = $c.ord < 32 ?? '' !! $c;
$filename ~= $char;
print $char;
}
}
sleep .1;
$screen.shutdown-screen;
say "Filename entered: '$filename'";