Module: FPrinter
- Defined in:
- lib/fprinter/screen.rb,
lib/fprinter/display_change.rb,
lib/fprinter/printer_change.rb
Constant Summary collapse
- CONSOLE_MATCHES =
{ bold: "\e[1m", blink: "\e[5m", underline: "\e[4m" , highlight: "\e[7m" , black: "\e[30m", red: "\e[31m", green: "\e[32m", yellow: "\e[33m", blue: "\e[34m", magenta: "\e[35m", cyan: "\e[36m", white: "\e[37m", highlighted_black: "\e[40m", highlighted_red: "\e[41m", highlighted_green: "\e[42m", highlighted_yellow: "\e[43m", highlighted_blue: "\e[44m", highlighted_magenta: "\e[45m", highlighted_cyan: "\e[46m", highlighted_white: "\e[47m" }
Class Method Summary collapse
- .appear_from_left(str, sec = 0.05) ⇒ Object
- .appear_from_right(str, sec = 0.05) ⇒ Object
- .big(str) ⇒ Object
- .clean! ⇒ Object
- .flush! ⇒ Object
- .move_to_home! ⇒ Object
- .reset! ⇒ Object
- .reverse(str, sec = 0.05) ⇒ Object
- .slow(str, sec = 0.05) ⇒ Object
- .slow_unprint(str, sec = 0.05) ⇒ Object
Class Method Details
.appear_from_left(str, sec = 0.05) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/fprinter/printer_change.rb', line 22 def self.appear_from_left(str, sec = 0.05) s = str.length str.split("").each_with_index do |l, i| print "\e[K", str[(s-1-i)..(s-1)], "\e[D" * (i + 1) sleep(sec) print "\e[D" * (s - i) end print "\e[D" * 2, "\n" end |
.appear_from_right(str, sec = 0.05) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/fprinter/printer_change.rb', line 32 def self.appear_from_right(str, sec = 0.05) s = str.length str.split("").each_with_index do |l, i| print "\e[K", " " * (s - i - 1), str[0..(i)] sleep(sec) print "\e[D" * (s + i) end print "\e[D" * 2, "\n" end |
.big(str) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fprinter/display_change.rb', line 39 def self.big(str) transform = str.split("") line0, line1, line2, line3, line4, line5 = [], [], [], [], [], [] transform.each do |letter| letter.downcase! raise "Unknown character #{letter}" if !BIG_LETTERS.has_key?(letter) line0 << LINE0[BIG_LETTERS[letter]..(BIG_LETTERS[letter.next] - 1)] line1 << LINE1[BIG_LETTERS[letter]..(BIG_LETTERS[letter.next] - 1)] line2 << LINE2[BIG_LETTERS[letter]..(BIG_LETTERS[letter.next] - 1)] line3 << LINE3[BIG_LETTERS[letter]..(BIG_LETTERS[letter.next] - 1)] line4 << LINE4[BIG_LETTERS[letter]..(BIG_LETTERS[letter.next] - 1)] line5 << LINE5[BIG_LETTERS[letter]..(BIG_LETTERS[letter.next] - 1)] end puts line0.join("") puts line1.join("") puts line2.join("") puts line3.join("") puts line4.join("") puts line5.join("") end |
.clean! ⇒ Object
3 4 5 |
# File 'lib/fprinter/screen.rb', line 3 def self.clean! print "\e[2J" end |
.flush! ⇒ Object
15 16 17 |
# File 'lib/fprinter/screen.rb', line 15 def self.flush! $stdout.flush end |
.move_to_home! ⇒ Object
7 8 9 |
# File 'lib/fprinter/screen.rb', line 7 def self.move_to_home! print "\e[H" end |
.reset! ⇒ Object
11 12 13 |
# File 'lib/fprinter/screen.rb', line 11 def self.reset! print "\e[0m\n" end |
.reverse(str, sec = 0.05) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/fprinter/printer_change.rb', line 42 def self.reverse(str, sec = 0.05) s = str.length str.split("").each_with_index do |l, i| print "\e[K", " " * (s - i - 1), str[(s-1-i)..(s-1)], "\e[D" * (i + 1) sleep(sec) print "\e[D" * (s - i) end print "\e[D" * 2, "\n" end |
.slow(str, sec = 0.05) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/fprinter/printer_change.rb', line 4 def self.slow(str, sec = 0.05) str.split("").each do |l| print l sleep(sec) end puts "" end |
.slow_unprint(str, sec = 0.05) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/fprinter/printer_change.rb', line 12 def self.slow_unprint(str, sec = 0.05) s = str.length str.split("").each_with_index do |l, i| print "\e[K", str[0..(s-i)] sleep(sec) print "\e[D" * (s - i + 2) end print "\e[D" * 2, "\e[K", "\n" end |