I'm using the Perl6 Terminal::Print module for a console based application.
It's working well - however, now I need to prompt the user for a string of text.
What's a good way to do this?
Here is an example of using Terminal::Print::RawInput
to get a filename as user input:
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'";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With