Module: Term

Extended by:
Term
Included in:
Term
Defined in:
lib/epitools/term.rb

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

Classes: Table, Window

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#wrapObject

Returns the value of attribute wrap


26
27
28
# File 'lib/epitools/term.rb', line 26

def wrap
  @wrap
end

#xObject

Returns the value of attribute x


26
27
28
# File 'lib/epitools/term.rb', line 26

def x
  @x
end

#yObject

Returns the value of attribute y


26
27
28
# File 'lib/epitools/term.rb', line 26

def y
  @y
end

Instance Method Details

#clearObject


40
41
42
# File 'lib/epitools/term.rb', line 40

def clear
  print "\e[H\e[J"
end

#clear_eolObject


48
49
50
# File 'lib/epitools/term.rb', line 48

def clear_eol
  print "\e[0K"
end

#clear_lineObject


44
45
46
# File 'lib/epitools/term.rb', line 44

def clear_line
  print "\e[2K"
end

#color(fore, back = nil) ⇒ Object


80
81
82
83
# File 'lib/epitools/term.rb', line 80

def color(fore, back=nil)
  @fore = fore
  @back = back if back
end

#goto(x, y) ⇒ Object


37
# File 'lib/epitools/term.rb', line 37

def goto(x,y); @x, @y = x, y; end

#heightObject


36
# File 'lib/epitools/term.rb', line 36

def height; size[1]; end

#hide_cursorObject


72
73
74
# File 'lib/epitools/term.rb', line 72

def hide_cursor
  print "\e[?25l"
end

#homeObject


56
57
58
# File 'lib/epitools/term.rb', line 56

def home
  move_to
end

#move_to(row: 1, col: 1) ⇒ Object


52
53
54
# File 'lib/epitools/term.rb', line 52

def move_to(row: 1, col: 1)
  print "\e[#{row};#{col}H"
end

#move_to_bottomObject


64
65
66
# File 'lib/epitools/term.rb', line 64

def move_to_bottom
  move_to_row(height-1)
end

#move_to_row(n) ⇒ Object


60
61
62
# File 'lib/epitools/term.rb', line 60

def move_to_row(n)
  move_to(row: n)
end

#move_to_topObject


68
69
70
# File 'lib/epitools/term.rb', line 68

def move_to_top
  move_to_row(1)
end

#posObject


38
# File 'lib/epitools/term.rb', line 38

def pos; [@x, @y]; end

#puts(s) ⇒ Object


85
86
87
# File 'lib/epitools/term.rb', line 85

def puts(s)
  # some curses shit
end

#show_cursorObject


76
77
78
# File 'lib/epitools/term.rb', line 76

def show_cursor
  print "\e[?25h"
end

#sizeObject

Return the [width,height] of the terminal.


31
32
33
# File 'lib/epitools/term.rb', line 31

def size
  $stdout.winsize.reverse
end

#widthObject


35
# File 'lib/epitools/term.rb', line 35

def width;  size[0]; end