class RubyText::Window::GetString
Public Class Methods
new(win = STDSCR, str = "", i = 0, history: [], limit: nil, tab: [], capture: [])
click to toggle source
# File lib/output.rb, line 164 def initialize(win = STDSCR, str = "", i = 0, history: [], limit: nil, tab: [], capture: []) @win = win @r0, @c0 = @win.rc @limit = limit || (@win.cols - @r0 - 1) raise ArgumentError unless @limit.is_a?(Numeric) @str, @i = str[0..(@limit-1)], i @str ||= "" @win.print @str @win.left @str.length @history = history @h = @history.length - 1 @maxlen = 0 # longest string in history list @tabcom = tab end
Public Instance Methods
add(ch)
click to toggle source
# File lib/output.rb, line 250 def add(ch) if @str.length >= @limit Curses.beep return end @str.insert(@i, ch) @win.right @win.go(@r0, @c0) { @win.print @str } @i += 1 end
backspace()
click to toggle source
# File lib/output.rb, line 199 def backspace # remember: may be in middle of string return if @i == 0 @i -= 1 @str[@i] = "" @win.left @win.rcprint @r0, @c0, @str + " " end
complete()
click to toggle source
# File lib/output.rb, line 232 def complete targets = @tabcom.find_all {|x| x.start_with?(@str) } if targets.nil? # Curses.beep @win.print "???" return end if targets.size > 1 num, target = @win.menu(items: targets) else target = targets.first end @str = target.nil? ? "" : target.dup @i = @str.length @win.go @r0, @c0 @win.print @str end
enter()
click to toggle source
# File lib/output.rb, line 179 def enter @win.crlf @history << @str @h = @history.length - 1 end
history_next()
click to toggle source
# File lib/output.rb, line 220 def history_next return if @history.empty? @h = (@h + 1) % @history.length @win.go @r0, @c0 @maxlen = @history.map(&:length).max @win.print(" "*@maxlen) @str = @history[@h] @i = @str.length @win.go @r0, @c0 @win.print @str end
history_prev()
click to toggle source
# File lib/output.rb, line 208 def history_prev return if @history.empty? @win.go @r0, @c0 @maxlen = @history.map(&:length).max @win.print(" "*@maxlen) @h = (@h - 1) % @history.length @str = @history[@h] @i = @str.length @win.go @r0, @c0 @win.print @str end
left_arrow()
click to toggle source
# File lib/output.rb, line 185 def left_arrow if @i > 0 @i -= 1 @win.left end end
right_arrow()
click to toggle source
# File lib/output.rb, line 192 def right_arrow if @i < @str.length @i += 1 @win.right end end
value()
click to toggle source
# File lib/output.rb, line 261 def value @str end