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

[FIX] Ctrl+arrow keys navigation fixed #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
6 changes: 2 additions & 4 deletions coolline.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

$LOAD_PATH.unshift File.expand_path(File.join("lib", File.dirname(__FILE__)))

require 'coolline/version'
require File.expand_path('../lib/coolline/version', __FILE__)

Gem::Specification.new do |s|
s.name = "coolline"

s.version = Coolline::Version
s.version = Coolline::VERSION

s.summary = "Sounds like readline, smells like readline, but isn't readline"
s.description = <<-eof
Expand Down
29 changes: 26 additions & 3 deletions lib/coolline/coolline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,17 @@ class Coolline
Handler.new(?\C-a..?\C-z) {},

Handler.new(/\A\e(?:\C-h|\x7F)\z/, &:kill_backward_word),
Handler.new("\e[1;5D", &:backward_word),
Handler.new("\e[1;5C", &:forward_word),
Handler.new("\eb", &:backward_word),
Handler.new("\ef", &:forward_word),
Handler.new("\e[c", &:backward_word),
Handler.new("\e[5D", &:backward_word),
Handler.new("\eOD", &:backward_word),
Handler.new("\eOd", &:backward_word),
Handler.new("\e[d", &:forward_word),
Handler.new("\e[5C", &:forward_word),
Handler.new("\eOC", &:forward_word),
Handler.new("\eOc", &:forward_word),
Handler.new("\e[A", &:previous_history_line),
Handler.new("\e[B", &:next_history_line),
Handler.new("\e[3~", &:kill_current_char),
Expand Down Expand Up @@ -235,9 +244,8 @@ def readline_full(prompt = ">> ", default_line = "")
@history << @line

@input.raw do |raw_stdin|
until (char = raw_stdin.getc) == "\r"
until (char = read_char) == "\r"
@menu.erase

handle(char)
return if @should_exit

Expand Down Expand Up @@ -493,4 +501,19 @@ def handle_escape(char)
str
end
end

def read_char
c = STDIN.getch
if(c=="\e")
extra_thread = Thread.new{
7.times{c+= STDIN.getc.chr}
}
# wait just long enough for special keys to get swallowed
extra_thread.join(0.0001)
# kill thread so not-so-long special keys don't wait on getc
extra_thread.kill
end
c
end

end
2 changes: 1 addition & 1 deletion lib/coolline/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Coolline
Version = "0.5.0"
VERSION = "0.5.2"
end