Skip to content

Surprising behavior for character = true resp. character = :getc with stty #53

@stomar

Description

@stomar

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(?):

  1. 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?
  2. 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)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions