jbe-goethe 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.textile +70 -0
  2. data/lib/goethe.rb +57 -0
  3. data/test/test_goethe.rb +25 -0
  4. metadata +55 -0
data/README.textile ADDED
@@ -0,0 +1,70 @@
1
+ h1. Goethe
2
+
3
+ h2. ANSI terminal coloring in Ruby.
4
+
5
+ h3. Installation
6
+
7
+ @gem sources -a http://gems.github.com@
8
+
9
+ @sudo gem install jbe-goethe@
10
+
11
+ h3. Features
12
+
13
+ * Sensible syntax
14
+ * Less than 60 lines of code
15
+
16
+ h3. Requires
17
+
18
+ * A terminal with 16 colors afaik
19
+ * @gem install win32console@ in case of Windows (untested)
20
+
21
+ h2. Synopsis
22
+
23
+ <pre>
24
+ <code>
25
+ require 'rubygems'
26
+ require 'goethe'
27
+
28
+ class Poet
29
+
30
+ include Goethe::Palette
31
+
32
+ def proclaim
33
+ puts red( 'Oh!' )
34
+ puts 'How ' + black('twisted', :yellow) + ' is not fate?'
35
+ puts blue('But, alas, how wonderful!',
36
+ :underline, cyan, :blink, :bold)
37
+ end
38
+ end
39
+ </code>
40
+ </pre>
41
+
42
+ Method names denote foreground colors. Parameters, in the form of symbols, denote background color or modifiers.
43
+
44
+ |Colors|black, red, green, yellow, blue, purple, cyan, white|
45
+ |Modifiers|bold, underline, blink|
46
+
47
+ h3. License
48
+
49
+ (MIT License)
50
+
51
+ Copyright (c) 2009 Jostein Berre Eliassen
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ 'Software'), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/goethe.rb ADDED
@@ -0,0 +1,57 @@
1
+
2
+ # Goethe -- easy ansi coloring
3
+ # svusj.com
4
+
5
+ module Goethe
6
+
7
+ begin
8
+ require 'Win32/Console/ANSI' if PLATFORM =~ /win32/
9
+ rescue LoadError
10
+ raise 'You must gem install win32console to use color on Windows'
11
+ end
12
+ end
13
+
14
+ module Goethe::Tech
15
+
16
+ Colors = [:black, :red, :green, :yellow, :blue, :purple, :cyan, :white]
17
+
18
+ # ANSI codes
19
+ BG = Hash[Colors.zip((40..47).map(&:to_s).to_a)]
20
+ FG = Hash[Colors.zip((30..37).map(&:to_s).to_a)]
21
+ Mod = {
22
+ :bold => '1',
23
+ :bright => '1',
24
+ :underline => '4',
25
+ :blink => '5'}
26
+ ESC = "\033["
27
+ UNESC = 'm'
28
+ RESET = ESC + '0' + UNESC
29
+
30
+ def self.colorize( fg, args )
31
+
32
+ text = args.select {|arg| arg.is_a? String }.join
33
+
34
+ deco = (args & Mod.keys)
35
+
36
+ pre = deco.empty? ? nil :
37
+ deco.map {|k| Mod[k] }.join(';')
38
+
39
+ match = (args & Colors).first
40
+ bg = match ? BG[match] : nil
41
+
42
+ code = [ pre, FG[fg], bg ].compact.join( ';' )
43
+
44
+ ESC + code + UNESC + text + RESET
45
+ end
46
+ end
47
+
48
+ module Goethe::Palette
49
+ Goethe::Tech::Colors.each do |color|
50
+
51
+ define_method color do |*args|
52
+ Goethe::Tech.colorize( color, args )
53
+ end
54
+ end
55
+ end
56
+
57
+
@@ -0,0 +1,25 @@
1
+ require "test/unit"
2
+ require "goethe"
3
+
4
+ class TestGoethe < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "write tests or I will kneecap you"
7
+
8
+
9
+
10
+
11
+
12
+
13
+ end
14
+ end
15
+
16
+
17
+
18
+ module TestPalette
19
+ extend Goethe::Palette
20
+ end
21
+
22
+ puts TestPalette.red('red bold blink underline blue', :bold, :blink, :underline, :blue)
23
+ puts TestPalette.green('green bold blue', :bold, :blue)
24
+ puts TestPalette.white('white')
25
+ puts TestPalette.white('white underline', :underline)
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jbe-goethe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Jostein Berre Eliassen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-28 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Goethe is a Ruby library for writing ANSI colored text to the terminal.
17
+ email: jbe@svusj.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.textile
26
+ - lib/goethe.rb
27
+ - test/test_goethe.rb
28
+ has_rdoc: false
29
+ homepage: http://github.com/jbe/goethe
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.2.0
51
+ signing_key:
52
+ specification_version: 2
53
+ summary: Goethe is a Ruby library for writing ANSI colored text to the terminal.
54
+ test_files: []
55
+