HighLine and Readline

A

Ari Brown

Hey,

Good
In my quest for buffer a user's input serverside, I have found an
answer (which is rather easy).
Oh, and I got HighLine working over sockets.

I need to use HighLine::Question with the Readline attribute.

But unfortunately, according to the documentation I found, using the
readline attribute will make readline be a ruby-rebel and use it's
own input and output streams ($stdin and $stdout, I assume).

So my question is this: How can I make the readline attribute use
specific input and output streams?

I'm imaging something like this (it is probably waaaaaaay wrong):

a = HighLine.new(@sock, @sock)
a.ask("monkey? ") {|q| q.readline(@sock, @sock) }

Inspired by the echo attribute.

Thanks,
--------------------------------------------|
If you're not living on the edge,
then you're just wasting space.
 
G

Gregory Brown

Hey,

Good
In my quest for buffer a user's input serverside, I have found an
answer (which is rather easy).
Oh, and I got HighLine working over sockets.

I need to use HighLine::Question with the Readline attribute.

But unfortunately, according to the documentation I found, using the
readline attribute will make readline be a ruby-rebel and use it's
own input and output streams ($stdin and $stdout, I assume).

So my question is this: How can I make the readline attribute use
specific input and output streams?

I'm imaging something like this (it is probably waaaaaaay wrong):

a = HighLine.new(@sock, @sock)
a.ask("monkey? ") {|q| q.readline(@sock, @sock) }

Here's the relevant source, as you can see it ignores your input stream.
I'll leave it to James to comment further, but I'm sure we wouldn't
mind making it easier to handle what you're trying to do if it can be
done easily enough.

#
# Read a line of input from the input stream and process whitespace as
# requested by the Question object.
#
# If Question's _readline_ property is set, that library will be used to
# fetch input. *WARNING*: This ignores the currently set input stream.
#
# Raises EOFError if input is exhausted.
#
def get_line( )
if @question.readline
require "readline" # load only if needed

# capture say()'s work in a String to feed to readline()
old_output = @output
@output = StringIO.new
say(@question)
question = @output.string
@output = old_output

# prep auto-completion
completions = @question.selection.abbrev
Readline.completion_proc = lambda { |string| completions[string] }

# work-around ugly readline() warnings
old_verbose = $VERBOSE
$VERBOSE = nil
answer = @question.change_case(
@question.remove_whitespace(
Readline.readline(question, true) ) )
$VERBOSE = old_verbose

answer
else
raise EOFError, "The input stream is exhausted." if @input.eof?

@question.change_case(@question.remove_whitespace(@input.gets))
end
end
 
J

James Edward Gray II

Here's the relevant source, as you can see it ignores your input
stream.

If you know how to point Readline at another IO, we take patches. ;)

James Edward Gray II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Highline and Chronic 2
HighLine Questions 5
[ANN] HighLine 1.5.1 - Now with Ruby 1.9 support! 1
ANN] HighLine 1.0.1 0
[ANN] HighLine 0.6.1 8
[ANN] HighLine 0.5.0 7
[ANN] HighLine 0.4.0 28
[ANN] HighLine 0.2.0 2

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top