Module: Term
Overview
Example usage:
puts Term::Table[ (1..100).to_a ].horizontally #=> prints all the numbers, ordered across rows
puts Term::Table[ (1..100).to_a ].vertically #=> prints all the numbers, ordered across columns
puts Term::Table[ [[1,2], [3,4]] ] #=> prints the table that was supplied
Term::Table.new do |t|
t.row [...]
t.rows[5] = [...]
t.rows << [...]
t.col []
end.to_s
table.compact.to_s #=> minimize the table's columns
Defined Under Namespace
Instance Attribute Summary collapse
-
#wrap ⇒ Object
Returns the value of attribute wrap.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#clear ⇒ Object
<n>J = Clear (part of) the screen.
- #clear_all_above ⇒ Object
- #clear_all_below ⇒ Object
-
#clear_eol ⇒ Object
0 = clear to end of line.
-
#clear_line ⇒ Object
2 = clear entire line.
- #clear_scrollback_buffer! ⇒ Object
- #color(fore, back = nil) ⇒ Object
- #height ⇒ Object
- #hide_cursor ⇒ Object
- #home ⇒ Object
-
#move_to(row: 1, col: 1) ⇒ Object
<n>;<m>H = Move!.
- #move_to_bottom ⇒ Object
- #move_to_row(n) ⇒ Object
- #move_to_top ⇒ Object
- #show_cursor ⇒ Object
-
#size ⇒ Object
Return the [width,height] of the terminal.
- #width ⇒ Object
Instance Attribute Details
#wrap ⇒ Object
Returns the value of attribute wrap.
26 27 28 |
# File 'lib/epitools/term.rb', line 26 def wrap @wrap end |
#x ⇒ Object
Returns the value of attribute x.
26 27 28 |
# File 'lib/epitools/term.rb', line 26 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
26 27 28 |
# File 'lib/epitools/term.rb', line 26 def y @y end |
Instance Method Details
#clear ⇒ Object
<n>J = Clear (part of) the screen.
63 64 65 66 |
# File 'lib/epitools/term.rb', line 63 def clear # If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). print "\e[2J\e[H" end |
#clear_all_above ⇒ Object
68 69 70 71 |
# File 'lib/epitools/term.rb', line 68 def clear_all_above # If n is 1, clear from cursor to beginning of the screen. print "\e[1J" end |
#clear_all_below ⇒ Object
73 74 75 76 |
# File 'lib/epitools/term.rb', line 73 def clear_all_below # If n is 0 (or missing), clear from cursor to end of screen. print "\e[0J" end |
#clear_eol ⇒ Object
0 = clear to end of line
55 56 57 |
# File 'lib/epitools/term.rb', line 55 def clear_eol print "\e[0K" end |
#clear_line ⇒ Object
2 = clear entire line
50 51 52 |
# File 'lib/epitools/term.rb', line 50 def clear_line print "\e[2K" end |
#clear_scrollback_buffer! ⇒ Object
78 79 80 81 |
# File 'lib/epitools/term.rb', line 78 def clear_scrollback_buffer! # If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications). print "\e[3J" end |
#color(fore, back = nil) ⇒ Object
116 117 118 119 |
# File 'lib/epitools/term.rb', line 116 def color(fore, back=nil) @fore = fore @back = back if back end |
#height ⇒ Object
36 |
# File 'lib/epitools/term.rb', line 36 def height; size[1]; end |
#hide_cursor ⇒ Object
108 109 110 |
# File 'lib/epitools/term.rb', line 108 def hide_cursor print "\e[?25l" end |
#home ⇒ Object
92 93 94 |
# File 'lib/epitools/term.rb', line 92 def home move_to end |
#move_to(row: 1, col: 1) ⇒ Object
<n>;<m>H = Move!
88 89 90 |
# File 'lib/epitools/term.rb', line 88 def move_to(row: 1, col: 1) print "\e[#{row};#{col}H" end |
#move_to_bottom ⇒ Object
100 101 102 |
# File 'lib/epitools/term.rb', line 100 def move_to_bottom move_to_row(height-1) end |
#move_to_row(n) ⇒ Object
96 97 98 |
# File 'lib/epitools/term.rb', line 96 def move_to_row(n) move_to(row: n) end |
#move_to_top ⇒ Object
104 105 106 |
# File 'lib/epitools/term.rb', line 104 def move_to_top move_to_row(1) end |
#show_cursor ⇒ Object
112 113 114 |
# File 'lib/epitools/term.rb', line 112 def show_cursor print "\e[?25h" end |
#size ⇒ Object
Return the [width,height] of the terminal.
31 32 33 |
# File 'lib/epitools/term.rb', line 31 def size $stdout.winsize.reverse rescue [80,25] end |
#width ⇒ Object
35 |
# File 'lib/epitools/term.rb', line 35 def width; size[0]; end |