It slurps the filenames from standard input, then reads random sample paragraphs from some of them, prints random paragraphs a line at a time, and repeats. My simplified version that's partway between jethro's script and mine looks like this:find $HOME -name \*.txt | textual-slideshow.pl $*
And it has the same problem as my script, not surprisingly. The problem clearly has to do with running in an environment where stdin is redirected. So I tried to fix that by closing STDIN and reopening it after reading the filenames. That didn't help. I tried adding an explicit STDIN argument to the ReadMode and ReadKey calls; that didn't help either. This is what I've got now, and it also has the same problem as my original script or the above modification of jethro's script:#! /usr/bin/perl use Term::ReadKey; use Time::HiRes qw(time); my @slurp_stdin = <>; ReadMode 3; while (1) { my $key; my $wait_until = time + 3; while ( time < $wait_until ) { $key = ReadKey( -1 ); if ( defined $key ) { print STDERR "keystroke $key\t"; } } print "Something\n"; }
This repeatedly prints "Something"; but when I press keys, I don't get the "keystroke (key value)" message, only the value of the key. My full original script is at http://jimhenry.conlang.org/scripts/textual-slideshow.zip.#! /usr/bin/perl -w use Term::ReadKey; use Time::HiRes qw(time); my @slurp_stdin = <STDIN>; close STDIN; open STDIN, "-"; while (1) { my $key; my $wait_until = time + 3; while ( time < $wait_until ) { ReadMode 3, STDIN; # 'noecho'; $key = ReadKey( -1, STDIN ); if ( defined $key ) { print STDERR "keystroke $key\t"; } ReadMode 0, STDIN; } print "Something\n"; }
In reply to Re^2: Problem with ReadKey
by jimhenry
in thread Problem with ReadKey
by jimhenry
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |