Class: RubyText::Window::GetString
- Inherits:
-
Object
- Object
- RubyText::Window::GetString
- Defined in:
- output.rb
Instance Method Summary collapse
- #add(ch) ⇒ Object
- #backspace ⇒ Object
- #complete ⇒ Object
- #enter ⇒ Object
- #history_next ⇒ Object
- #history_prev ⇒ Object
-
#initialize(win = STDSCR, str = "", i = 0, history: [], limit: nil, tab: [], capture: []) ⇒ GetString
constructor
A new instance of GetString.
- #left_arrow ⇒ Object
- #right_arrow ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(win = STDSCR, str = "", i = 0, history: [], limit: nil, tab: [], capture: []) ⇒ GetString
Returns a new instance of GetString.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'output.rb', line 150 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 |
Instance Method Details
#add(ch) ⇒ Object
236 237 238 239 240 241 242 243 244 245 |
# File 'output.rb', line 236 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 ⇒ Object
185 186 187 188 189 190 191 192 |
# File 'output.rb', line 185 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 ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'output.rb', line 218 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.(items: targets) else target = targets.first end @str = target.nil? ? "" : target.dup @i = @str.length @win.go @r0, @c0 @win.print @str end |
#enter ⇒ Object
165 166 167 168 169 |
# File 'output.rb', line 165 def enter @win.crlf @history << @str @h = @history.length - 1 end |
#history_next ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 |
# File 'output.rb', line 206 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 ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 |
# File 'output.rb', line 194 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 ⇒ Object
171 172 173 174 175 176 |
# File 'output.rb', line 171 def left_arrow if @i > 0 @i -= 1 @win.left end end |
#right_arrow ⇒ Object
178 179 180 181 182 183 |
# File 'output.rb', line 178 def right_arrow if @i < @str.length @i += 1 @win.right end end |
#value ⇒ Object
247 248 249 |
# File 'output.rb', line 247 def value @str end |