Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion lib/tty/reader/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Reader
class Console
ESC = "\e"
CSI = "\e["
XTERM = "\eO"

TIMEOUT = 0.1

Expand All @@ -31,7 +32,7 @@ def initialize(input)
@input = input
@mode = Mode.new(input)
@keys = Keys.ctrl_keys.merge(Keys.keys)
@escape_codes = [[ESC.ord], CSI.bytes.to_a]
@escape_codes = [[ESC.ord], CSI.bytes.to_a, XTERM.bytes.to_a]
end

# Get a character from console with echo
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/read_keypress_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
expect(answer).to eq("ㄱ")
end

TTY::Reader::Keys.keys.each do |code, name|
it "reads #{Shellwords.escape(code)} as a #{name} key press" do
reader = described_class.new(input: input, output: out, env: env)
input << code
input.rewind

answer = reader.read_keypress

expect(answer).to eq(code)
end
end

context "when Ctrl+C pressed" do
it "defaults to raising InputInterrupt" do
reader = described_class.new(input: input, output: out, env: env)
Expand Down