I am trying to get a single character from the user in a "cleaner" way than with SystemExtensions.get_character, which is not well documented and feels rather like a hack to me (see also issue #50).
While playing around with the echo and character settings, I stumbled over two issues(?):
- The documentation is not very clear (at least to me) about the difference between
character = true and character = :getc. When to choose which? Are they supposed to behave differently or is this only an implementation detail?
- I do not understand the behavior of
character = true in the example code below (newline and indentation; examples one and three behave as expected).
Output:
Your password?
password: 12345
Answer [ynaq]?
key: q (character = true)
Answer [ynaq]? key: q (character = :getc)
Code:
require 'rubygems'
require 'highline/import'
answer = ask("Your password? ") do |q|
q.echo = false
end
puts "password: #{answer}"
key = ask("Answer [ynaq]? ") do |q|
q.echo = false
q.character = true
end
puts "key: #{key} (character = true)"
key = ask("Answer [ynaq]? ") do |q|
q.character = :getc
end
puts "key: #{key} (character = :getc)"
I am trying to get a single character from the user in a "cleaner" way than with
SystemExtensions.get_character, which is not well documented and feels rather like a hack to me (see also issue #50).While playing around with the
echoandcharactersettings, I stumbled over two issues(?):character = trueandcharacter = :getc. When to choose which? Are they supposed to behave differently or is this only an implementation detail?character = truein the example code below (newline and indentation; examples one and three behave as expected).Output:
Code: