Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IO#getch to read one char in raw mode #54

Merged
merged 3 commits into from
Sep 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions lib/reline/ansi.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'io/console'

class Reline::ANSI
RAW_KEYSTROKE_CONFIG = {
[27, 91, 65] => :ed_prev_history, # ↑
Expand All @@ -24,14 +26,8 @@ def self.getc
unless @@buf.empty?
return @@buf.shift
end
c = nil
loop do
result = select([@@input], [], [], 0.1)
next if result.nil?
c = @@input.read(1)
break
end
c&.ord
c = @@input.raw(&:getbyte)
(c == 0x16 && @@input.raw(min: 0, tim: 0, &:getbyte)) || c
end

def self.ungetc(c)
Expand Down