console_splash 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/console_splash.rb +89 -0
  2. metadata +46 -0
@@ -0,0 +1,89 @@
1
+ # console_splash.rb
2
+ # created by Jesse Jurman
3
+
4
+ class Console_Splash
5
+
6
+ attr_accessor :screen, :lines, :columns
7
+
8
+ # Create a new screen Array with a given console size
9
+ # (will be auto-generated otherwise using `stty size`)
10
+ def initialize(lines=nil, columns=nil)
11
+ @lines = lines ? lines : (`stty size`.chomp.split()[0].to_i - 1)
12
+ @columns = columns ? columns : `stty size`.chomp.split()[1].to_i
13
+ @screen = Array.new(@lines, "#{' '*(@columns)}\n")
14
+ @screen[-1] = "#{' '*(@columns)}"
15
+ end
16
+
17
+ # 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)
21
+ end
22
+
23
+ # Draw a continuous pattern on the sides of the screen
24
+ def write_vertical_pattern(pattern="=")
25
+ write_right_pattern(pattern)
26
+ write_left_pattern(pattern)
27
+ end
28
+
29
+ # Draw a continuous pattern on the top of the screen
30
+ def write_top_pattern(pattern="=")
31
+ strSize = pattern.size
32
+ line_write(0, "#{pattern*((@columns-1)/strSize)}")
33
+ end
34
+
35
+ # Draw a continuous pattern on the bottom of the screen
36
+ def write_bottom_pattern(pattern="=")
37
+ strSize = pattern.size
38
+ line_write(-1, "#{pattern*((@columns-1)/strSize)}")
39
+ end
40
+
41
+ # Draw a continuous pattern on the right side of the screen
42
+ def write_right_pattern(pattern="=")
43
+ count = 1
44
+ @screen[(1..-2)].each do |line|
45
+ line_write(count, pattern, (@columns-(pattern.size+1)))
46
+ count += 1
47
+ end
48
+ end
49
+
50
+ # Draw a continuous pattern on the left side of the screen
51
+ def write_left_pattern(pattern="=")
52
+ count = 1
53
+ @screen[(1..-2)].each do |line|
54
+ line_write(count, pattern)
55
+ count += 1
56
+ end
57
+ end
58
+
59
+ # Write the name of the application, the author
60
+ # and the version in a vim-esq manner
61
+ def write_header(name, author, version)
62
+ header = (@screen.size*(1.0/3.0)).to_i
63
+ center_write(header, name)
64
+ center_write(header+2, "version #{version}")
65
+ center_write(header+3, "by #{author}")
66
+ end
67
+
68
+ # Write to the center of the line
69
+ def center_write(line, text)
70
+ strSize = text.size
71
+ buffer = (@columns - strSize)/2.0
72
+ line_write(line, text, buffer)
73
+ end
74
+
75
+ # Writes on the lines of the screen
76
+ def line_write(line, text, start=0)
77
+ buffer = @screen[line].split('')
78
+ buffer[start..(start+text.size()-1)] = text.split('')
79
+ @screen[line] = buffer.join('')
80
+ end
81
+
82
+ # Print the screen onto the display
83
+ # (developers are in charge of holding the
84
+ # prompt in focus (i.e. gets))
85
+ def splash
86
+ @screen.each { |line| print line }
87
+ end
88
+
89
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: console_splash
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jesse Jurman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Allows developers to give programs a vim-esq splash screen
15
+ email: j.r.jurman@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/console_splash.rb
21
+ homepage: https://github.com/JRJurman/console_splash
22
+ licenses:
23
+ - MIT
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.23
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Splash screen gem for command line ruby programs
46
+ test_files: []