JEG2 / highline

A higher level command-line oriented interface.
Other
1.29k stars 137 forks source link

answering in multiple lines #208

Closed guyisra closed 7 years ago

guyisra commented 7 years ago

I couldn't find a way to get an input that spans multiple lines, is it even possible?

something like

HighLine.new.ask 'Your life story: ' and you would write text like a text editor (or similar)

is it possible with highline?

thanks

abinoam commented 7 years ago

I don't think so. But I'll check it out.

abinoam commented 7 years ago

@guyisra

We can think about adding multiline support at HighLine itself. But I think I'll not have the time to implement it by now.

But, you can get multiline input as you would do within any Ruby script.

Something around the lines of:

#!/usr/bin/env ruby

# From: http://stackoverflow.com/a/13840066/875229

# HighLine uses gets or readline to gather input
# So it uses the same separator rules as other Ruby scripts
# A possible hack would be ...

require 'highline'

puts HighLine::VERSION

cli = HighLine.new

puts "Your current separator character is: #{$/.inspect}"
puts "Saving it for later..."

old_sep = $/

puts "Setting separator to the three letters EOF"

$/ = "EOF"

answer = cli.ask "Write a multiline short history about your day."

puts "Your answer was: #{answer}"

puts "Restoring separator to #{old_sep.inspect}"

$/ = old_sep

Do you think this would solve your problem? If so, please close this issue. But, feel free to discuss it futher. And thank you for reporting it. I think is something others may have a use to.

abinoam commented 7 years ago

Hi @guyisra,

I'm closing this issue as stall. But, feel free to reopen it if you find it necessary.