Why “puts” output is indented in Ruby?
Question
Given the following Ruby program:
def getch
begin
system("stty raw -echo")
ch = STDIN.getc
puts "[#{ch}]"
ch
ensure
system("stty -raw echo")
end
end
print "Press a key: "
getch
puts "Have a nice day!"
and the following run:
$ ruby a.rb
Press a key: [t]
Have a nice day!
Why "Have a nice day!" is indented? Why the output is not like that:
$ ruby a.rb
Press a key: [t]
Have a nice day!
?
La solution
Ok, adding opost
should fix it. Change you third line to look like this:
system("stty raw opost -echo")
I hope this is the answer you are looking for.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow