summaryrefslogtreecommitdiff
path: root/lib/reline/ansi.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-08 21:04:46 +0900
committeraycabta <aycabta@gmail.com>2019-12-23 02:11:22 +0900
commit679bc4f9cb6a5471df903436c6240ca2157986dd (patch)
treec17093e058ffe7e9a3debf382c8e82cf9f8c0959 /lib/reline/ansi.rb
parent3a18e43caac4ce31702c9b79de3b6e8af05ef173 (diff)
[ruby/reline] Use IO#raw to read one byte
https://github.com/ruby/reline/commit/be17740e82
Diffstat (limited to 'lib/reline/ansi.rb')
-rw-r--r--lib/reline/ansi.rb23
1 files changed, 4 insertions, 19 deletions
diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb
index 6246a27107..8d83da854c 100644
--- a/lib/reline/ansi.rb
+++ b/lib/reline/ansi.rb
@@ -1,3 +1,5 @@
+require 'io/console'
+
class Reline::ANSI
RAW_KEYSTROKE_CONFIG = {
[27, 91, 65] => :ed_prev_history, # ↑
@@ -30,7 +32,7 @@ class Reline::ANSI
unless @@buf.empty?
return @@buf.shift
end
- c = @@input.getbyte
+ c = @@input.raw(intr: true, &:getbyte)
(c == 0x16 && @@input.raw(min: 0, tim: 0, &:getbyte)) || c
end
@@ -127,29 +129,12 @@ class Reline::ANSI
def self.prep
retrieve_keybuffer
int_handle = Signal.trap('INT', 'IGNORE')
- begin
- otio = IO.popen(%w[stty -g], in: @@input, &:read).chomp
- rescue ArgumentError
- else
- setting = %w'-echo -icrnl cbreak -ixoff -iexten'
- stty = IO.popen(%w[stty -a], in: @@input, &:read)
- if /-parenb\b/ =~ stty
- setting << 'pass8'
- end
- system("stty", *setting, in: @@input)
- end
Signal.trap('INT', int_handle)
- otio
+ nil
end
def self.deprep(otio)
int_handle = Signal.trap('INT', 'IGNORE')
- if otio
- begin
- system("stty #{otio}", in: @@input, err: File::NULL)
- rescue ArgumentError
- end
- end
Signal.trap('INT', int_handle)
Signal.trap('WINCH', @@old_winch_handler) if @@old_winch_handler
end