summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-27 07:00:50 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-27 07:00:50 +0000
commit8516d7433f7e1966f39cea5c86ec758e046d43c5 (patch)
tree9f7cf2d350913435c58a851934aefd5a0269fcce /tool
parentfd8cf62f37cd3530e5311ed681359241072a3f76 (diff)
* 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
Diffstat (limited to 'tool')
-rwxr-xr-xtool/redmine-backporter.rb93
1 files changed, 66 insertions, 27 deletions
diff --git a/tool/redmine-backporter.rb b/tool/redmine-backporter.rb
index 64078c0..13a9ec8 100755
--- a/tool/redmine-backporter.rb
+++ b/tool/redmine-backporter.rb
@@ -200,35 +200,74 @@ def more(sio)
end
end
-def Readline.readline(prompt = '')
- console = IO.console
- console.binmode
- ly, lx = console.winsize
- if /mswin|mingw/ =~ RUBY_PLATFORM or /^(?:vt\d\d\d|xterm)/i =~ ENV["TERM"]
- cls = "\r\e[2K"
- else
- cls = "\r" << (" " * lx)
+class << Readline
+ def readline(prompt = '')
+ console = IO.console
+ console.binmode
+ ly, lx = console.winsize
+ if /mswin|mingw/ =~ RUBY_PLATFORM or /^(?:vt\d\d\d|xterm)/i =~ ENV["TERM"]
+ cls = "\r\e[2K"
+ else
+ cls = "\r" << (" " * lx)
+ end
+ cls << "\r" << prompt
+ console.print prompt
+ console.flush
+ line = ''
+ while 1
+ case c = console.getch
+ when "\r", "\n"
+ puts
+ HISTORY << line
+ return line
+ when "\C-?", "\b" # DEL/BS
+ print "\b \b" if line.chop!
+ when "\C-u"
+ print cls
+ line.clear
+ when "\C-d"
+ return nil if line.empty?
+ 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
+ print c
+ line << c
+ end
+ end
end
- cls << "\r" << prompt
- console.print prompt
- console.flush
- line = ''
- while 1
- case c = console.getch
- when "\r", "\n"
- puts
- return line
- when "\C-?", "\b" # DEL/BS
- print "\b \b" if line.chop!
- when "\C-u"
- print cls
- line.clear
- when "\C-d"
- return nil if line.empty?
- line << c
+
+ 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
- print c
- line << c
+ self[@pos]
end
end
end unless defined?(Readline.readline)