1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

redmine-backporter.rb: like Readline.readline

* tool/redmine-backporter.rb (readline): rename and add optional
  argument prompt, like Readline.readline.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-01-20 03:14:21 +00:00
parent 6cb0b95fe3
commit 506cb40667

View file

@ -195,16 +195,17 @@ def more(sio)
end end
end end
def mygets def readline(prompt = '')
console = IO.console console = IO.console
ly, lx = console.winsize ly, lx = console.winsize
cls = "\r" + (" " * lx) + "\r> " cls = "\r" + (" " * lx) + "\r" + prompt
console.print prompt
console.flush
line = '' line = ''
while 1 while 1
case c = console.getch case c = console.getch
when "\r", "\n" when "\r", "\n"
puts puts
line << c
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!
@ -258,13 +259,11 @@ puts "Backporter #{VERSION}".color(bold: true) + " for #{TARGET_VERSION}"
@issue = nil @issue = nil
@changesets = nil @changesets = nil
while true while true
print '> '
begin begin
l = mygets l = readline '> '
rescue Interrupt rescue Interrupt
break break
end end
l.strip! if l
case l case l
when 'ls' when 'ls'
uri = URI(REDMINE_BASE+'/projects/ruby-trunk/issues.json?'+URI.encode_www_form(@query)) uri = URI(REDMINE_BASE+'/projects/ruby-trunk/issues.json?'+URI.encode_www_form(@query))