mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
* tool/redmine-backporter.rb: added history feature for platforms which
lack readline. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fd8cf62f37
commit
8516d7433f
2 changed files with 72 additions and 28 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Jan 27 15:58:23 2015 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* tool/redmine-backporter.rb: added history feature for platforms which
|
||||||
|
lack readline.
|
||||||
|
|
||||||
Mon Jan 26 22:09:35 2015 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
Mon Jan 26 22:09:35 2015 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||||
|
|
||||||
* .gitignore: ignored temporary file with git.
|
* .gitignore: ignored temporary file with git.
|
||||||
|
|
|
@ -200,7 +200,8 @@ def more(sio)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def Readline.readline(prompt = '')
|
class << Readline
|
||||||
|
def readline(prompt = '')
|
||||||
console = IO.console
|
console = IO.console
|
||||||
console.binmode
|
console.binmode
|
||||||
ly, lx = console.winsize
|
ly, lx = console.winsize
|
||||||
|
@ -217,6 +218,7 @@ def Readline.readline(prompt = '')
|
||||||
case c = console.getch
|
case c = console.getch
|
||||||
when "\r", "\n"
|
when "\r", "\n"
|
||||||
puts
|
puts
|
||||||
|
HISTORY << line
|
||||||
return line
|
return line
|
||||||
when "\C-?", "\b" # DEL/BS
|
when "\C-?", "\b" # DEL/BS
|
||||||
print "\b \b" if line.chop!
|
print "\b \b" if line.chop!
|
||||||
|
@ -226,11 +228,48 @@ def Readline.readline(prompt = '')
|
||||||
when "\C-d"
|
when "\C-d"
|
||||||
return nil if line.empty?
|
return nil if line.empty?
|
||||||
line << c
|
line << c
|
||||||
|
when "\C-p"
|
||||||
|
HISTORY.pos -= 1
|
||||||
|
line = HISTORY.current
|
||||||
|
print cls
|
||||||
|
print line
|
||||||
|
when "\C-n"
|
||||||
|
HISTORY.pos += 1
|
||||||
|
line = HISTORY.current
|
||||||
|
print cls
|
||||||
|
print line
|
||||||
else
|
else
|
||||||
print c
|
print c
|
||||||
line << c
|
line << c
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
HISTORY = []
|
||||||
|
def HISTORY.<<(val)
|
||||||
|
HISTORY.push(val)
|
||||||
|
@pos = self.size
|
||||||
|
self
|
||||||
|
end
|
||||||
|
def HISTORY.pos
|
||||||
|
@pos ||= 0
|
||||||
|
end
|
||||||
|
def HISTORY.pos=(val)
|
||||||
|
@pos = val
|
||||||
|
if @pos < 0
|
||||||
|
@pos = -1
|
||||||
|
elsif @pos >= self.size
|
||||||
|
@pos = self.size
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def HISTORY.current
|
||||||
|
@pos ||= 0
|
||||||
|
if @pos < 0 || @pos >= self.size
|
||||||
|
''
|
||||||
|
else
|
||||||
|
self[@pos]
|
||||||
|
end
|
||||||
|
end
|
||||||
end unless defined?(Readline.readline)
|
end unless defined?(Readline.readline)
|
||||||
|
|
||||||
def mergeinfo
|
def mergeinfo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue