Module: Cursor
Overview
:nodoc:all
Instance Method Summary collapse
- #clear_line ⇒ Object
- #down(n = 1) ⇒ Object
- #left(x = 1) ⇒ Object
- #line(n = 1) ⇒ Object
- #move=(*args) ⇒ Object
-
#position ⇒ Object
Returns [x,y] for the current cursor position.
- #restore ⇒ Object
- #right(x = 1) ⇒ Object
- #save ⇒ Object
- #up(n = 1) ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
Instance Method Details
#clear_line ⇒ Object
193 194 195 |
# File 'lib/drydock/console.rb', line 193 def clear_line tput :el end |
#down(n = 1) ⇒ Object
169 170 171 |
# File 'lib/drydock/console.rb', line 169 def down(n=1) tput :cud, n end |
#left(x = 1) ⇒ Object
177 178 179 |
# File 'lib/drydock/console.rb', line 177 def left(x=1) tput :cub, x end |
#line(n = 1) ⇒ Object
181 182 183 |
# File 'lib/drydock/console.rb', line 181 def line(n=1) tput :il, n end |
#move=(*args) ⇒ Object
160 161 162 163 |
# File 'lib/drydock/console.rb', line 160 def move=(*args) x,y = *args.flatten tput(:cup, y, x) # "tput cup" takes y before x end |
#position ⇒ Object
Returns [x,y] for the current cursor position.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/drydock/console.rb', line 131 def position yx = [0,0] position_lamb = lambda { begin # NOTE: Can we get cursor position from tput? termsettings = `stty -g` # DEBUGGING: The following code works in Ruby 1.9 but not 1.8. system("stty raw -echo") print "\e[6n" # Forces output of: \e[49;1R (\e is not printable) c = '' (pos ||= '') << c while (c = STDIN.getc) != 'R'# NOTE: There must be a better way! yx = pos.scan(/(\d+);(\d+)/).flatten yx[0] = yx[0].to_i - 1 # It returns 1 for the first column, but we want 0 yx[1] = yx[1].to_i - 1 ensure system("stty #{termsettings}") # Get out of raw mode end } RUBY_VERSION =~ /1.9/ ? Thread.exclusive(&position_lamb) : position_lamb.call yx.reverse end |
#restore ⇒ Object
189 190 191 |
# File 'lib/drydock/console.rb', line 189 def restore tput :rc end |
#right(x = 1) ⇒ Object
173 174 175 |
# File 'lib/drydock/console.rb', line 173 def right(x=1) tput :cuf, x end |
#save ⇒ Object
185 186 187 |
# File 'lib/drydock/console.rb', line 185 def save tput :sc end |
#up(n = 1) ⇒ Object
165 166 167 |
# File 'lib/drydock/console.rb', line 165 def up(n=1) tput :cuu, n end |
#x ⇒ Object
157 |
# File 'lib/drydock/console.rb', line 157 def x; position[0]; end |
#y ⇒ Object
158 |
# File 'lib/drydock/console.rb', line 158 def y; position[1]; end |