in reply to Active STDIN for user typed filepath
Yeah, it's a little funky. But I'm pretty sure it meets your requirements =D#! /usr/bin/perl -w use Term::ReadKey; # make STDOUT hot $| = 1; $string = ''; $done = 0; # get your dir listing opendir($dh, '.'); @dir = sort readdir($dh); closedir $dh; # input loop while (!$done) { # read a key while (defined ($key = ReadKey(-1))) { # if it's a tab, get the next thing in the directory if ($key =~ /\t/) { # treat dir as circular list $cur = shift(@dir); # 'clear' the input print "\b" x (length($string)); print " " x (length($string)); print "\b" x (length($string)); $string = $cur; push(@dir, $cur); } # return means we're done elsif ($key =~ /\r/) { $done = 1; last; } # otherwise add to input string else { $string .= $key; # don't forget to clear to keep things looking normal print "\b" x (length($string) - 1); } print $string; } } print "\nyou have selected: $string\n";
|
|---|