Two important parts of my proposal:
1. system ("stty raw -echo") #, to instantly get any typed character in combination with 2. using STDIN.getc with string-var, which serves as an input buffer for retyping user input.
9 (& boolean variable incoming_message) .
( , , .)
x .
:
$ ruby simultaneous_input_and_output.rb
Hello World!9
The incoming message is: true
Hello World!9x
You entered:
Hello World!9x
End!
$input_buffer = "";
incoming_message = false
begin
system("stty raw -echo")
begin
str = STDIN.getc
print str.chr
$input_buffer = $input_buffer + str.chr
if str.chr == '9'
incoming_message = true
end
if incoming_message
puts "\nThe incoming message is: " + incoming_message.to_s
print $input_buffer
incoming_message = false
end
end while (str.chr != 'x')
ensure
system("stty -raw echo")
end
puts "\n\nYou entered:"
puts $input_buffer
puts "End!"
P.S.:
( "stty raw -echo" ) . (User Jay)
?