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
-
#initialize(win = STDSCR, str = "", i = 0) ⇒ GetString
constructor
A new instance of GetString.
- #left_arrow ⇒ Object
- #right_arrow ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(win = STDSCR, str = "", i = 0) ⇒ GetString
Returns a new instance of GetString.
142 143 144 145 146 147 148 |
# File 'lib/output.rb', line 142 def initialize(win = STDSCR, str = "", i = 0) @win = win @r0, @c0 = @win.rc @str, @i = str, i @len = @str.length @max = @len - 1 end |
Instance Method Details
#add(ch) ⇒ Object
181 182 183 184 185 186 |
# File 'lib/output.rb', line 181 def add(ch) @str.insert(@i, ch) @win.right @win.go(@r0, @c0) { @win.print @str } @i += 1 end |
#backspace ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/output.rb', line 168 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
150 151 152 |
# File 'lib/output.rb', line 150 def enter @win.crlf end |
#left_arrow ⇒ Object
154 155 156 157 158 159 |
# File 'lib/output.rb', line 154 def left_arrow if @i > 0 @i -= 1 @win.left end end |
#right_arrow ⇒ Object
161 162 163 164 165 166 |
# File 'lib/output.rb', line 161 def right_arrow if @i < @str.length @i += 1 @win.right end end |
#value ⇒ Object
188 189 190 |
# File 'lib/output.rb', line 188 def value @str end |