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

Improve readline.cr #5791

Merged
merged 1 commit into from
Mar 8, 2018
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
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