Class: Term
- Inherits:
-
Object
- Object
- Term
- Defined in:
- lib/aniview/util/term.rb
Instance Method Summary collapse
- #bold ⇒ Object
- #clear ⇒ Object
- #clear_line ⇒ Object
- #cols ⇒ Object
- #echo_off ⇒ Object
- #echo_on ⇒ Object
- #getKey ⇒ Object
- #hide_cursor ⇒ Object
-
#initialize ⇒ Term
constructor
A new instance of Term.
- #nobold ⇒ Object
- #reset ⇒ Object
- #restore ⇒ Object
- #rows ⇒ Object
- #save ⇒ Object
- #show_cursor ⇒ Object
Constructor Details
#initialize ⇒ Term
Returns a new instance of Term.
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/aniview/util/term.rb', line 3 def initialize @tput=Hash[ "smcup" => %x(tput smcup), "rmcup" => %x(tput rmcup), "civis" => %x(tput civis), "cnorm" => %x(tput cnorm), "el1" => "\e[2K", "bold" => %x(tput bold), "nobold" => %x(tput sgr0), ] end |
Instance Method Details
#bold ⇒ Object
23 |
# File 'lib/aniview/util/term.rb', line 23 def bold; print @tput["bold"]; return self; end |
#clear ⇒ Object
22 |
# File 'lib/aniview/util/term.rb', line 22 def clear; print "\033[2J"; return self; end |
#clear_line ⇒ Object
19 |
# File 'lib/aniview/util/term.rb', line 19 def clear_line; print @tput["el1"]; return self; end |
#cols ⇒ Object
26 |
# File 'lib/aniview/util/term.rb', line 26 def cols; return HighLine::SystemExtensions.terminal_size[0]; end |
#echo_off ⇒ Object
20 |
# File 'lib/aniview/util/term.rb', line 20 def echo_off; %x(stty -echo); return self; end |
#echo_on ⇒ Object
21 |
# File 'lib/aniview/util/term.rb', line 21 def echo_on; %x(stty echo); return self; end |
#getKey ⇒ Object
29 30 31 |
# File 'lib/aniview/util/term.rb', line 29 def getKey return STDIN.getch.gsub("\r", "enter").gsub(" ", "space").gsub("A", "up").gsub("B", "down").gsub("C", "right").gsub("D", "left").gsub("\e", "skip").gsub("[", "skip") end |
#hide_cursor ⇒ Object
17 |
# File 'lib/aniview/util/term.rb', line 17 def hide_cursor; print @tput["civis"]; return self; end |
#nobold ⇒ Object
24 |
# File 'lib/aniview/util/term.rb', line 24 def nobold; print @tput["nobold"]; return self; end |
#reset ⇒ Object
33 34 35 |
# File 'lib/aniview/util/term.rb', line 33 def reset self.restore.show_cursor.echo_on end |
#restore ⇒ Object
16 |
# File 'lib/aniview/util/term.rb', line 16 def restore; print @tput["rmcup"]; return self; end |
#rows ⇒ Object
27 |
# File 'lib/aniview/util/term.rb', line 27 def rows; return HighLine::SystemExtensions.terminal_size[1]; end |
#save ⇒ Object
15 |
# File 'lib/aniview/util/term.rb', line 15 def save; print @tput["smcup"]; return self; end |
#show_cursor ⇒ Object
18 |
# File 'lib/aniview/util/term.rb', line 18 def show_cursor; print @tput["cnorm"]; return self; end |