From: Wybo Dekker Date: 2005-06-17T23:28:54+09:00 Subject: Re: stubborn program using readline On Fri, 17 Jun 2005, Jonathan Paisley wrote: > On Fri, 17 Jun 2005 08:41:22 +0900, Wybo Dekker wrote: > > > On Thu, 16 Jun 2005, Logan Capaldo wrote: > > > >> Theory: readline reads from STDIN correct? using rltest < rltest means > >> that STDIN gets EOF, which means STDIN is closed which means readlien > >> can't read anything from it. > > > > No, readline should not necessarily read from STDIN. It can read from the > > console, /dev/tty or so. > > Since you always want to readline from the terminal, try that: > > tty = open("/dev/tty","a+") > tty.readline That's too simple: it does not use the readline library with its editing and completion facilities. What I need is a translation of this simple Perl example into Ruby - I think Ruby can't do this: #!/usr/bin/perl -w # showline - read lines from stdin (either file or pipe), # then let user interrogate lines by number use Term::ReadLine; push(@x,$_) while <>; print scalar(@x)," lines\n"; $t=new Term::ReadLine 'vpp'; while (1) { $_ = $t->readline("type line number (0 to stop): "); PROMPT: { /^\d+$/ or do { print "Not a positive number\n"; last PROMPT}; $_ > @x and do { print "No such line\n"; last PROMPT}; $_ and do { print "line $_: $x[$_-1]"; last PROMPT}; die "thanks!\n"; } } Typical run: $ showline