console_splash 1.2.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/console_splash.rb +53 -40
- data/lib/console_splash/pixel.rb +20 -0
- metadata +21 -5
data/lib/console_splash.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# console_splash.rb
|
2
2
|
# created by Jesse Jurman
|
3
3
|
|
4
|
+
require 'colorize'
|
5
|
+
require 'console_splash/pixel'
|
6
|
+
|
4
7
|
class ConsoleSplash
|
5
8
|
|
6
9
|
attr_accessor :screen, :lines, :columns
|
@@ -10,80 +13,90 @@ class ConsoleSplash
|
|
10
13
|
def initialize(lines=nil, columns=nil)
|
11
14
|
@lines = lines ? lines : `stty size`.chomp.split()[0].to_i
|
12
15
|
@columns = columns ? columns : `stty size`.chomp.split()[1].to_i
|
13
|
-
@screen = Array.new(@lines
|
14
|
-
|
16
|
+
@screen = Array.new(@lines) do
|
17
|
+
Array.new(@columns) {Pixel.new(' ', nil, nil)} + [Pixel.new("\n",nil,nil)]
|
18
|
+
end
|
19
|
+
@screen[-1][-1] = Pixel.new("",nil,nil)
|
15
20
|
end
|
16
21
|
|
17
22
|
# Draw a continuous pattern on the top and bottom of the screen
|
18
|
-
def write_horizontal_pattern(pattern=
|
19
|
-
write_top_pattern(pattern)
|
20
|
-
write_bottom_pattern(pattern)
|
23
|
+
def write_horizontal_pattern(pattern, opt={})
|
24
|
+
write_top_pattern(pattern, opt)
|
25
|
+
write_bottom_pattern(pattern, opt)
|
21
26
|
end
|
22
27
|
|
23
28
|
# Draw a continuous pattern on the sides of the screen
|
24
|
-
def write_vertical_pattern(pattern=
|
25
|
-
|
26
|
-
|
29
|
+
def write_vertical_pattern(pattern, opt={})
|
30
|
+
write_left_pattern(pattern, opt)
|
31
|
+
write_right_pattern(pattern, opt)
|
27
32
|
end
|
28
33
|
|
29
34
|
# Draw a continuous pattern on the top of the screen
|
30
|
-
def write_top_pattern(pattern=
|
31
|
-
|
32
|
-
write_line(0, "#{pattern*((@columns-1)/strSize)}")
|
35
|
+
def write_top_pattern(pattern, opt={})
|
36
|
+
write_line(0, pattern*(@columns/pattern.size), opt)
|
33
37
|
end
|
34
38
|
|
35
39
|
# Draw a continuous pattern on the bottom of the screen
|
36
|
-
def write_bottom_pattern(pattern=
|
37
|
-
|
38
|
-
write_line(-1, "#{pattern*((@columns-1)/strSize)}")
|
40
|
+
def write_bottom_pattern(pattern, opt={})
|
41
|
+
write_line(-1, pattern*(@columns/pattern.size), opt)
|
39
42
|
end
|
40
43
|
|
41
44
|
# Draw a continuous pattern on the right side of the screen
|
42
|
-
def write_right_pattern(pattern=
|
43
|
-
|
44
|
-
@screen[(1..-2)].each do |line|
|
45
|
-
write_line(count, pattern, (@columns-(pattern.size+1)))
|
46
|
-
count += 1
|
47
|
-
end
|
45
|
+
def write_right_pattern(pattern, opt={})
|
46
|
+
@screen.each { |line| write_right(@screen.index(line), pattern, opt) }
|
48
47
|
end
|
49
48
|
|
50
49
|
# Draw a continuous pattern on the left side of the screen
|
51
|
-
def write_left_pattern(pattern=
|
52
|
-
|
53
|
-
@screen[(1..-2)].each do |line|
|
54
|
-
write_line(count, pattern)
|
55
|
-
count += 1
|
56
|
-
end
|
50
|
+
def write_left_pattern(pattern, opt={})
|
51
|
+
@screen.each { |line| write_left(@screen.index(line), pattern, opt) }
|
57
52
|
end
|
58
53
|
|
59
54
|
# Write the name of the application, the author
|
60
55
|
# and the version in a vim-esq manner
|
61
|
-
def write_header(name, author, version)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
def write_header(name, author, version, opt={})
|
57
|
+
nameFg = opt[:nameFg]; authorFg = opt[:authorFg]; versionFg = opt[:versionFg];
|
58
|
+
nameBg = opt[:nameBg]; authorBg = opt[:authorBg]; versionBg = opt[:versionBg];
|
59
|
+
|
60
|
+
headLine = @lines/3
|
61
|
+
write_center(headLine, name, {:fg=>nameFg, :bg=>nameBg})
|
62
|
+
write_center(headLine+2, "version #{version}", {:fg=>versionFg, :bg=>versionBg})
|
63
|
+
write_center(headLine+3, "created by #{author}", {:fg=>authorFg, :bg=>authorBg})
|
64
|
+
end
|
65
|
+
|
66
|
+
# Write to the left of the line
|
67
|
+
def write_left(line, text, opt={})
|
68
|
+
write_line(line, text, opt.merge({:start=>0}))
|
69
|
+
end
|
70
|
+
|
71
|
+
# Write to the right of the line
|
72
|
+
def write_right(line, text, opt={})
|
73
|
+
buffer = (@columns-text.size)
|
74
|
+
write_line(line, text, opt.merge({:start=>buffer}))
|
66
75
|
end
|
67
76
|
|
68
77
|
# Write to the center of the line
|
69
|
-
def write_center(line, text)
|
70
|
-
|
71
|
-
|
72
|
-
write_line(line, text, buffer)
|
78
|
+
def write_center(line, text, opt={})
|
79
|
+
buffer = (@columns-text.size)/2
|
80
|
+
write_line(line, text, opt.merge({:start=>buffer}))
|
73
81
|
end
|
74
82
|
|
75
83
|
# Writes on the lines of the screen
|
76
|
-
def write_line(line, text,
|
77
|
-
|
78
|
-
|
79
|
-
|
84
|
+
def write_line(line, text, opt={})
|
85
|
+
fg = opt[:fg]; bg = opt[:bg]; start = (opt[:start] or 0)
|
86
|
+
@screen[line][(start..(start+text.size-1))] = text.split('').map { |c| Pixel.new(c, fg, bg) }
|
87
|
+
end
|
88
|
+
|
89
|
+
# Writes a single pixel on the screen
|
90
|
+
def write_pixel( line, column, newChar, opt={} )
|
91
|
+
fg = opt[:fg]; bg = opt[:bg]
|
92
|
+
@screen[line][column] = Pixel.new(newChar, fg, bg)
|
80
93
|
end
|
81
94
|
|
82
95
|
# Print the screen onto the display
|
83
96
|
# (developers are in charge of holding the
|
84
97
|
# prompt in focus (i.e. gets))
|
85
98
|
def splash
|
86
|
-
@screen.each { |line|
|
99
|
+
@screen.each { |line| line.each { |column| column.print_pixel } }
|
87
100
|
end
|
88
101
|
|
89
102
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# pixel.rb
|
2
|
+
# Created by Jesse Jurman
|
3
|
+
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
class Pixel
|
7
|
+
|
8
|
+
attr_accessor :char, :fcolor, :bcolor
|
9
|
+
|
10
|
+
def initialize( char=' ', fcolor=:white, bcolor=nil )
|
11
|
+
@char = char
|
12
|
+
@fcolor = fcolor
|
13
|
+
@bcolor = bcolor
|
14
|
+
end
|
15
|
+
|
16
|
+
def print_pixel
|
17
|
+
print char.colorize( :color => fcolor, :background => bcolor )
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console_splash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colorize
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: Allows developers to give programs a vim-esq splash screen
|
15
31
|
email: j.r.jurman@gmail.com
|
16
32
|
executables: []
|
@@ -18,9 +34,9 @@ extensions: []
|
|
18
34
|
extra_rdoc_files: []
|
19
35
|
files:
|
20
36
|
- lib/console_splash.rb
|
37
|
+
- lib/console_splash/pixel.rb
|
21
38
|
homepage: https://github.com/JRJurman/console_splash
|
22
|
-
licenses:
|
23
|
-
- MIT
|
39
|
+
licenses: []
|
24
40
|
post_install_message:
|
25
41
|
rdoc_options: []
|
26
42
|
require_paths:
|