Skip to content

getch '\n' on windows #3

Closed
Closed

Description

@Kalin-Rudnicki
require 'io/console'

loop do
    puts($stdin.getch.inspect)
end

# KeyPresses:
# A => "A"
# B => "B"
# \n => nothing...
# C => "\n"
# D => returns twice "C" "D"

Activity

  1. nobu commented on Nov 20, 2019

    @nobu
    Member

    I cannot reproduce it.
    What key do you press for \n?

  2. orgads commented on Dec 1, 2019

    @orgads

    Here too, on Win10. See also JEG2/highline#244

    I press Enter.

  3. orgads commented on Dec 1, 2019

    @orgads
    ruby -v
    ruby 2.5.6p201 (2019-08-28 revision 67796) [x64-mingw32]
    
  4. orgads commented on Dec 2, 2019

    @orgads

    Same on Win7.

  5. nobu commented on Dec 2, 2019

    @nobu
    Member

    The io-console bundled with 2.5 is quite old.
    Could you try more recent versions?

  6. orgads commented on Dec 3, 2019

    @orgads

    With the latest gem release it's the same, but with master here it kinda works. I get \r when pressing Enter (why not \n?)

    Not sure if this is intended, but if I press Ctrl-C with the existing version I get char 3, but with master I get an Interrupt exception.

  7. orgads commented on Dec 3, 2019

    @orgads

    I bisected the issue, and it was fixed in fae7933, which is included in 0.5.0.

    Can you please push 0.5.0 to rubygems.org?

  8. orgads commented on Dec 3, 2019

    @orgads

    On linux (debian) Enter produces \r as well, but Ctrl-C gives \u0003 and does not raise an exception.

  9. nobu commented on Dec 4, 2019

    @nobu
    Member

    Fixed Ctrl-C issue on Windows now, thank you for the pointing out.
    \r(= Ctrl-M) is the expected code for Enter.
    It is translated to \n by console drivers when it is in "cooked" mode, and getch bypasses it.

  10. orgads commented on Dec 9, 2019

    @orgads

    You may close this issue.

    Can you please also publish binary packages for mingw to rubygems?

  11. nobu commented on Dec 10, 2019

    @nobu
    Member

    We have dropped the binary gem support at 972ceb0.
    c.f. ruby/bigdecimal#148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions