Class: Aniview::Util::Term
- Inherits:
-
Object
- Object
- Aniview::Util::Term
- Defined in:
- lib/aniview/util/term.rb
Class Method Summary collapse
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.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/aniview/util/term.rb', line 5 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 |
Class Method Details
.cols ⇒ Object
31 |
# File 'lib/aniview/util/term.rb', line 31 def self.cols; return HighLine::SystemExtensions.terminal_size[0]; end |
.rows ⇒ Object
32 |
# File 'lib/aniview/util/term.rb', line 32 def self.rows; return HighLine::SystemExtensions.terminal_size[1]; end |
Instance Method Details
#bold ⇒ Object
25 |
# File 'lib/aniview/util/term.rb', line 25 def bold; print @tput["bold"]; return self; end |
#clear ⇒ Object
24 |
# File 'lib/aniview/util/term.rb', line 24 def clear; print "\033[2J"; return self; end |
#clear_line ⇒ Object
21 |
# File 'lib/aniview/util/term.rb', line 21 def clear_line; print @tput["el1"]; return self; end |
#cols ⇒ Object
28 |
# File 'lib/aniview/util/term.rb', line 28 def cols; return HighLine::SystemExtensions.terminal_size[0]; end |
#echo_off ⇒ Object
22 |
# File 'lib/aniview/util/term.rb', line 22 def echo_off; %x(stty -echo); return self; end |
#echo_on ⇒ Object
23 |
# File 'lib/aniview/util/term.rb', line 23 def echo_on; %x(stty echo); return self; end |
#getKey ⇒ Object
34 35 36 |
# File 'lib/aniview/util/term.rb', line 34 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
19 |
# File 'lib/aniview/util/term.rb', line 19 def hide_cursor; print @tput["civis"]; return self; end |
#nobold ⇒ Object
26 |
# File 'lib/aniview/util/term.rb', line 26 def nobold; print @tput["nobold"]; return self; end |
#reset ⇒ Object
38 39 40 |
# File 'lib/aniview/util/term.rb', line 38 def reset self.restore.show_cursor.echo_on end |
#restore ⇒ Object
18 |
# File 'lib/aniview/util/term.rb', line 18 def restore; print @tput["rmcup"]; return self; end |
#rows ⇒ Object
29 |
# File 'lib/aniview/util/term.rb', line 29 def rows; return HighLine::SystemExtensions.terminal_size[1]; end |
#save ⇒ Object
17 |
# File 'lib/aniview/util/term.rb', line 17 def save; print @tput["smcup"]; return self; end |
#show_cursor ⇒ Object
20 |
# File 'lib/aniview/util/term.rb', line 20 def show_cursor; print @tput["cnorm"]; return self; end |