Class: ConsoleSplash
- Inherits:
-
Object
- Object
- ConsoleSplash
- Defined in:
- lib/console_splash.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#screen ⇒ Object
Returns the value of attribute screen.
Instance Method Summary collapse
-
#initialize(lines = nil, columns = nil) ⇒ ConsoleSplash
constructor
Create a new screen Array with a given console size (will be auto-generated otherwise using ‘stty size`).
-
#splash ⇒ Object
Print the screen onto the display (developers are in charge of holding the prompt in focus (i.e. gets)).
-
#write_bottom_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the bottom of the screen.
-
#write_center(line, text, opt = {}) ⇒ Object
Write to the center of the line.
-
#write_header(name, author, version, opt = {}) ⇒ Object
Write the name of the application, the author and the version in a vim-esq manner.
-
#write_horizontal_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the top and bottom of the screen.
-
#write_left(line, text, opt = {}) ⇒ Object
Write to the left of the line.
-
#write_left_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the left side of the screen.
-
#write_line(line, text, opt = {}) ⇒ Object
Writes on the lines of the screen.
-
#write_pixel(line, column, newChar, opt = {}) ⇒ Object
Writes a single pixel on the screen.
-
#write_right(line, text, opt = {}) ⇒ Object
Write to the right of the line.
-
#write_right_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the right side of the screen.
-
#write_top_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the top of the screen.
-
#write_vertical_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the sides of the screen.
Constructor Details
#initialize(lines = nil, columns = nil) ⇒ ConsoleSplash
Create a new screen Array with a given console size
(will be auto-generated otherwise using `stty size`)
13 14 15 16 17 18 19 20 |
# File 'lib/console_splash.rb', line 13 def initialize(lines=nil, columns=nil) @lines = lines ? lines : `stty size`.chomp.split()[0].to_i @columns = columns ? columns : `stty size`.chomp.split()[1].to_i @screen = Array.new(@lines) do Array.new(@columns) {Pixel.new(' ', nil, nil)} + [Pixel.new("\n",nil,nil)] end @screen[-1][-1] = Pixel.new("",nil,nil) end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
9 10 11 |
# File 'lib/console_splash.rb', line 9 def columns @columns end |
#lines ⇒ Object
Returns the value of attribute lines.
9 10 11 |
# File 'lib/console_splash.rb', line 9 def lines @lines end |
#screen ⇒ Object
Returns the value of attribute screen.
9 10 11 |
# File 'lib/console_splash.rb', line 9 def screen @screen end |
Instance Method Details
#splash ⇒ Object
Print the screen onto the display
(developers are in charge of holding the
prompt in focus (i.e. gets))
98 99 100 |
# File 'lib/console_splash.rb', line 98 def splash @screen.each { |line| line.each { |column| column.print_pixel } } end |
#write_bottom_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the bottom of the screen
40 41 42 |
# File 'lib/console_splash.rb', line 40 def write_bottom_pattern(pattern, opt={}) write_line(-1, pattern*(@columns/pattern.size), opt) end |
#write_center(line, text, opt = {}) ⇒ Object
Write to the center of the line
78 79 80 81 |
# File 'lib/console_splash.rb', line 78 def write_center(line, text, opt={}) buffer = (@columns-text.size)/2 write_line(line, text, opt.merge({:start=>buffer})) end |
#write_header(name, author, version, opt = {}) ⇒ Object
Write the name of the application, the author
and the version in a vim-esq manner
56 57 58 59 60 61 62 63 64 |
# File 'lib/console_splash.rb', line 56 def write_header(name, , version, opt={}) nameFg = opt[:nameFg]; = opt[:authorFg]; versionFg = opt[:versionFg]; nameBg = opt[:nameBg]; = opt[:authorBg]; versionBg = opt[:versionBg]; headLine = @lines/3 write_center(headLine, name, {:fg=>nameFg, :bg=>nameBg}) write_center(headLine+2, "version #{version}", {:fg=>versionFg, :bg=>versionBg}) write_center(headLine+3, "created by #{}", {:fg=>, :bg=>}) end |
#write_horizontal_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the top and bottom of the screen
23 24 25 26 |
# File 'lib/console_splash.rb', line 23 def write_horizontal_pattern(pattern, opt={}) write_top_pattern(pattern, opt) write_bottom_pattern(pattern, opt) end |
#write_left(line, text, opt = {}) ⇒ Object
Write to the left of the line
67 68 69 |
# File 'lib/console_splash.rb', line 67 def write_left(line, text, opt={}) write_line(line, text, opt.merge({:start=>0})) end |
#write_left_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the left side of the screen
50 51 52 |
# File 'lib/console_splash.rb', line 50 def write_left_pattern(pattern, opt={}) @screen.each { |line| write_left(@screen.index(line), pattern, opt) } end |
#write_line(line, text, opt = {}) ⇒ Object
Writes on the lines of the screen
84 85 86 87 |
# File 'lib/console_splash.rb', line 84 def write_line(line, text, opt={}) fg = opt[:fg]; bg = opt[:bg]; start = (opt[:start] or 0) @screen[line][(start..(start+text.size-1))] = text.split('').map { |c| Pixel.new(c, fg, bg) } end |
#write_pixel(line, column, newChar, opt = {}) ⇒ Object
Writes a single pixel on the screen
90 91 92 93 |
# File 'lib/console_splash.rb', line 90 def write_pixel( line, column, newChar, opt={} ) fg = opt[:fg]; bg = opt[:bg] @screen[line][column] = Pixel.new(newChar, fg, bg) end |
#write_right(line, text, opt = {}) ⇒ Object
Write to the right of the line
72 73 74 75 |
# File 'lib/console_splash.rb', line 72 def write_right(line, text, opt={}) buffer = (@columns-text.size) write_line(line, text, opt.merge({:start=>buffer})) end |
#write_right_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the right side of the screen
45 46 47 |
# File 'lib/console_splash.rb', line 45 def write_right_pattern(pattern, opt={}) @screen.each { |line| write_right(@screen.index(line), pattern, opt) } end |
#write_top_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the top of the screen
35 36 37 |
# File 'lib/console_splash.rb', line 35 def write_top_pattern(pattern, opt={}) write_line(0, pattern*(@columns/pattern.size), opt) end |
#write_vertical_pattern(pattern, opt = {}) ⇒ Object
Draw a continuous pattern on the sides of the screen
29 30 31 32 |
# File 'lib/console_splash.rb', line 29 def write_vertical_pattern(pattern, opt={}) write_left_pattern(pattern, opt) write_right_pattern(pattern, opt) end |