Class: RubyText::Window::GetString
- Inherits:
-
Object
- Object
- RubyText::Window::GetString
- Defined in:
- lib/output.rb
Instance Method Summary collapse
- #add(ch) ⇒ Object
- #backspace ⇒ Object
- #enter ⇒ Object
- #history_next ⇒ Object
- #history_prev ⇒ Object
-
#initialize(win = STDSCR, str = "", i = 0, history: []) ⇒ GetString
constructor
A new instance of GetString.
- #left_arrow ⇒ Object
- #right_arrow ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(win = STDSCR, str = "", i = 0, history: []) ⇒ GetString
Returns a new instance of GetString.
142 143 144 145 146 147 148 149 |
# File 'lib/output.rb', line 142 def initialize(win = STDSCR, str = "", i = 0, history: []) @win = win @r0, @c0 = @win.rc @str, @i = str, i @history = history @h = @history.length - 1 @maxlen = 0 end |
Instance Method Details
#add(ch) ⇒ Object
207 208 209 210 211 212 |
# File 'lib/output.rb', line 207 def add(ch) @str.insert(@i, ch) @win.right @win.go(@r0, @c0) { @win.print @str } @i += 1 end |
#backspace ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/output.rb', line 171 def backspace # remember: may be in middle of string return if @i == 0 @i -= 1 @str[@i] = "" @win.left @win.rcprint @r0, @c0, @str + " " # @r, @c = @win.rc # @win[@r0, @[email protected]+1] = ' ' # @win.go @r, @c end |
#enter ⇒ Object
151 152 153 154 155 |
# File 'lib/output.rb', line 151 def enter @win.crlf @history << @str @h = @history.length - 1 end |
#history_next ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/output.rb', line 195 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
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/output.rb', line 183 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
157 158 159 160 161 162 |
# File 'lib/output.rb', line 157 def left_arrow if @i > 0 @i -= 1 @win.left end end |
#right_arrow ⇒ Object
164 165 166 167 168 169 |
# File 'lib/output.rb', line 164 def right_arrow if @i < @str.length @i += 1 @win.right end end |
#value ⇒ Object
214 215 216 |
# File 'lib/output.rb', line 214 def value @str end |