Skip to content

Commit

Permalink
Update readline.cr (crystal-lang#5791)
Browse files Browse the repository at this point in the history
  • Loading branch information
wooster0 authored and RX14 committed Mar 8, 2018
1 parent 224d489 commit f0bd6b6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/readline.cr
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ module Readline
end

def bind_key(c : Char, &f : KeyBindingProc)
raise ArgumentError.new "Not a valid ASCII character: '#{c.inspect}'" unless 0 <= c.ord <= 255
raise ArgumentError.new "Not a valid ASCII character: #{c.inspect}" unless c.ascii?

handlers = (@@key_bind_handlers ||= {} of LibReadline::Int => KeyBindingProc)
handlers[c.ord] = f

res = LibReadline.rl_bind_key(c.ord, KeyBindingHandler).to_i32
raise ArgumentError.new "Invalid key: '#{c.inspect}'" unless res == 0
raise ArgumentError.new "Invalid key: #{c.inspect}" unless res == 0
end

def unbind_key(c : Char)
if (handlers = @@key_bind_handlers) && handlers[c.ord]?
handlers.delete(c.ord)
res = LibReadline.rl_unbind_key(c.ord).to_i32
raise Exception.new "Error unbinding key: '#{c.inspect}'" unless res == 0
raise Exception.new "Error unbinding key: #{c.inspect}" unless res == 0
else
raise KeyError.new "Key not bound: '#{c.inspect}'"
raise KeyError.new "Key not bound: #{c.inspect}"
end
end

Expand Down

0 comments on commit f0bd6b6

Please sign in to comment.