fhlow 1.91.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.
- data/bin/fhlow +186 -0
- data/lib/module_cmdparse/cmdparse.rb +480 -0
- data/lib/module_cmdparse/cmdparse/wrappers/optparse.rb +65 -0
- data/lib/module_config/config.rb +67 -0
- data/lib/module_config/configexception.rb +18 -0
- data/lib/module_config/configitems/complex.rb +71 -0
- data/lib/module_config/configitems/complexpackage.rb +67 -0
- data/lib/module_config/configitems/complexunit.rb +76 -0
- data/lib/module_config/configitems/simple.rb +56 -0
- data/lib/module_config/configitems/simplearchitecture.rb +52 -0
- data/lib/module_config/configitems/simplepackage.rb +47 -0
- data/lib/module_config/configitems/simpleunit.rb +53 -0
- data/lib/module_config/configs.test +24 -0
- data/lib/module_config/item.rb +34 -0
- data/lib/module_config/itemfactory.rb +55 -0
- data/lib/module_config/section.rb +69 -0
- data/lib/module_config/test.flw +20 -0
- data/lib/module_config/test.rb +85 -0
- data/lib/module_config/tmp +3 -0
- data/lib/module_config/unittests/config_1.flw +14 -0
- data/lib/module_config/unittests/config_1_fixed.flw +14 -0
- data/lib/module_config/unittests/config_2.flw +15 -0
- data/lib/module_config/unittests/config_3a.flw +16 -0
- data/lib/module_config/unittests/config_3b.flw +15 -0
- data/lib/module_config/unittests/config_test.rb +579 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-configexception_rb.html +647 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-configitems-complex_rb.html +700 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-configitems-complexpackage_rb.html +694 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-configitems-complexunit_rb.html +704 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-configitems-simple_rb.html +685 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-configitems-simplepackage_rb.html +676 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-configitems-simpleunit_rb.html +682 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-item_rb.html +663 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-itemfactory_rb.html +687 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-myconfig_rb.html +687 -0
- data/lib/module_config/unittests/coverage/-home-simon-tmp-fhlow_v2-flw-core-lib-module_config-section_rb.html +692 -0
- data/lib/module_config/unittests/coverage/index.html +689 -0
- data/lib/module_fhlow/fhlowexception.rb +55 -0
- data/lib/module_fhlow/leaf.rb +197 -0
- data/lib/module_fhlow/leaf.rb~ +202 -0
- data/lib/module_fhlow/leaffactory.rb +97 -0
- data/lib/module_fhlow/leafs/Package.rb +55 -0
- data/lib/module_fhlow/leafs/Unit.rb +152 -0
- data/lib/module_fhlow/log.rb +100 -0
- data/lib/module_fhlow/node.rb +206 -0
- data/lib/module_fhlow/pen.rb +101 -0
- data/lib/module_fhlow/plugin.rb +54 -0
- data/lib/module_fhlow/pluginpool.rb +81 -0
- data/lib/module_fhlow/rootnode.rb +98 -0
- data/lib/module_fhlow/test.rb +15 -0
- data/lib/module_term/ansicolor.rb +102 -0
- data/tests/testsuite.rb +20 -0
- metadata +106 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
#----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007 Simon Lasselsberger
|
4
|
+
# simon.lasselsberger@fh-hagenberg.at
|
5
|
+
#
|
6
|
+
# This file is part of the _fhlow_ scripting environment.
|
7
|
+
#
|
8
|
+
# The _fhlow_ scripting environment is free software; you can redistribute
|
9
|
+
# it and/or modify it under the terms of the GNU General Public License
|
10
|
+
# as published by the Free Software Foundation; either version 2 of the
|
11
|
+
# License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# _fhlow_ is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with _fhlow_; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
#
|
22
|
+
#----------------------------------------------------------------------------
|
23
|
+
|
24
|
+
|
25
|
+
require 'ansicolor'
|
26
|
+
|
27
|
+
module Fhlow
|
28
|
+
|
29
|
+
|
30
|
+
# The class Pen is a wrapper to the standard output function from IO. It is able
|
31
|
+
# to add colors to the output by mixing in the module Term::ANSIColor from rubyforge.
|
32
|
+
# It also adds a border to the output with a header (Pen.welcome) and a footer (Pen.bye).
|
33
|
+
class Pen
|
34
|
+
include Term::ANSIColor
|
35
|
+
|
36
|
+
# Initializes the members.
|
37
|
+
# +_outstream+:: The IO obejct to be used for output.
|
38
|
+
# +_coloring+:: Set to +true+ for colorful output or +false+ for no colors.
|
39
|
+
# +_prefix+:: This is the prefix that will be added in front of every line.
|
40
|
+
# +_width+:: The width of the border in amount of characters.
|
41
|
+
def initialize(_outstream, _coloring, _prefix=lightblue+"| "+clear, _width=80)
|
42
|
+
@@coloring = _coloring
|
43
|
+
@outstream = _outstream
|
44
|
+
@prefix = Hash.new
|
45
|
+
@prefix[true] = _prefix
|
46
|
+
@prefix[false] = uncolored(_prefix)
|
47
|
+
@width = _width
|
48
|
+
end
|
49
|
+
|
50
|
+
# Turns colors off.
|
51
|
+
def noColor
|
52
|
+
@@coloring = false
|
53
|
+
end
|
54
|
+
|
55
|
+
# Prints the header.
|
56
|
+
# +_msg+:: The message inside the header.
|
57
|
+
def header(_msg="fhlow - fast handling of a lot of work")
|
58
|
+
@width = _msg.length+2 if _msg.length > @width
|
59
|
+
@outstream.print lightblue, ",", "-"*@width, "+\n", clear
|
60
|
+
@outstream.print lightblue, "| ", clear, _msg.center(@width-2), lightblue, " |\n", clear
|
61
|
+
@outstream.print lightblue, "+", "-"*@width, "+\n", clear
|
62
|
+
end
|
63
|
+
|
64
|
+
# Prints a seperator line.
|
65
|
+
# +_color+:: The color of the line.
|
66
|
+
def seperator(_color=lightblue)
|
67
|
+
@outstream.print _color, "+", "-"*@width, "+\n", clear
|
68
|
+
end
|
69
|
+
|
70
|
+
# Prints the footer.
|
71
|
+
# +_msg+:: The message inside the footer.
|
72
|
+
def footer(_msg="work done!")
|
73
|
+
@width = _msg.length+2 if _msg.length > @width
|
74
|
+
@outstream.print lightblue, "+", "-"*@width, "+\n", clear
|
75
|
+
@outstream.print lightblue, "| ", clear, _msg.center(@width-2), lightblue, " |\n", clear
|
76
|
+
@outstream.print lightblue, "`", "-"*@width, "+\n", clear
|
77
|
+
end
|
78
|
+
|
79
|
+
# Prints a newline without adding the prefix.
|
80
|
+
def nl
|
81
|
+
@outstream.print "\n"
|
82
|
+
end
|
83
|
+
|
84
|
+
# Behaves like IO.print but adds the prefix to each line.
|
85
|
+
# <tt>*_strings</tt>:: An Array of objects that will be passed to IO.print.
|
86
|
+
def print(*_strings)
|
87
|
+
_strings.each { |s| s.gsub!(/\n(?!\z)/, "\n"+lightblue+"| "+clear) }
|
88
|
+
@outstream.print @prefix[@@coloring], _strings
|
89
|
+
end
|
90
|
+
|
91
|
+
# Behaves like IO.puts but adds the prefix to each line.
|
92
|
+
# <tt>*_strings</tt>:: An Array of objects that will be passed to IO.puts.
|
93
|
+
def puts(*_strings)
|
94
|
+
_strings.each { |s| s.gsub!(/\n(?!\z)/, "\n"+lightblue+"| "+clear) }
|
95
|
+
@outstream.puts @prefix[@@coloring]+_strings.join
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'cmdparse'
|
2
|
+
|
3
|
+
module Fhlow
|
4
|
+
|
5
|
+
# This _abstract_ class Plugin acts a super class for concrete Plugins
|
6
|
+
class Plugin
|
7
|
+
# The Object that contains the command and the subcommand of a Plugin.
|
8
|
+
attr_reader :cmd
|
9
|
+
|
10
|
+
private
|
11
|
+
# Initializes the Plugin.
|
12
|
+
# +_actualLeaf+:: Reference to the Leaf you are working on.
|
13
|
+
# +_pen+:: Reference to a Pen output object.
|
14
|
+
# +_log+:: Reference to a Log object.
|
15
|
+
def initialize(_actualLeaf, _pen, _log)
|
16
|
+
@pen = _pen
|
17
|
+
@log = _log
|
18
|
+
@actualLeaf = _actualLeaf
|
19
|
+
@cmd = CmdParse::Command.new(self.class.to_s, true, true)
|
20
|
+
@cmd.pen = @pen
|
21
|
+
end
|
22
|
+
|
23
|
+
# Describes the Plugins main command. The name of the main command
|
24
|
+
# is the name of the Plugin subclass.
|
25
|
+
# +_shortdesc+:: A short description of the command.
|
26
|
+
# +_desc+:: A longer description of the command.
|
27
|
+
# +_options+:: An initialized object from CmdParse::OptionParserWrapper.
|
28
|
+
def describeCmd(_shortdesc, _desc="", _options=nil)
|
29
|
+
@cmd.short_desc = _shortdesc
|
30
|
+
@cmd.description = _desc
|
31
|
+
@cmd.options = _options if _options
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# Descibes a subcommand of the plugin.
|
36
|
+
# +_name+:: The name of the subcommand.
|
37
|
+
# +_shortdesc+:: A short description of the command.
|
38
|
+
# +_desc+:: A longer description of the command.
|
39
|
+
# +_options+:: An initialized object from CmdParse::OptionParserWrapper.
|
40
|
+
# +_&action:: A Block that will be executed when the command is used.
|
41
|
+
def registerSubCmd(_name, _shortdesc="", _desc="", _options=nil, &_action)
|
42
|
+
subcmd = CmdParse::Command.new(_name, false)
|
43
|
+
subcmd.pen = @pen
|
44
|
+
subcmd.short_desc = _shortdesc
|
45
|
+
subcmd.description = _desc
|
46
|
+
subcmd.set_execution_block(&_action)
|
47
|
+
subcmd.options = _options if _options
|
48
|
+
@cmd.add_command(subcmd)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007 Simon Lasselsberger
|
4
|
+
# simon.lasselsberger@fh-hagenberg.at
|
5
|
+
#
|
6
|
+
# This file is part of the _fhlow_ scripting environment.
|
7
|
+
#
|
8
|
+
# The _fhlow_ scripting environment is free software; you can redistribute
|
9
|
+
# it and/or modify it under the terms of the GNU General Public License
|
10
|
+
# as published by the Free Software Foundation; either version 2 of the
|
11
|
+
# License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# _fhlow_ is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with _fhlow_; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
#
|
22
|
+
#----------------------------------------------------------------------------
|
23
|
+
|
24
|
+
require 'log'
|
25
|
+
|
26
|
+
module Fhlow
|
27
|
+
|
28
|
+
# A Pluginpool is a container that loads, initializes and stores references to
|
29
|
+
# the loaded plugins.
|
30
|
+
class Pluginpool
|
31
|
+
|
32
|
+
# Loads and initializes the loaded plugins.
|
33
|
+
# +_plugindir+:: The direcotry where the plugins can be found.
|
34
|
+
# +_actualLeaf+:: Reference to the Leaf you are working on.
|
35
|
+
# +_pen+:: Reference to a Pen output object.
|
36
|
+
# +_log+:: Reference to a Log object.
|
37
|
+
def initialize(_plugindir, _actualLeaf, _pen, _log)
|
38
|
+
@pool = Array.new
|
39
|
+
@log = _log
|
40
|
+
@pen = _pen
|
41
|
+
@plugindir = _plugindir
|
42
|
+
@actualLeaf = _actualLeaf
|
43
|
+
|
44
|
+
|
45
|
+
Dir.glob(@plugindir+"*.rb").each do |plugin|
|
46
|
+
|
47
|
+
pluginname = File.basename(plugin, ".rb").capitalize
|
48
|
+
|
49
|
+
require plugin
|
50
|
+
|
51
|
+
@pool.push(Kernel.const_get(pluginname).new(@actualLeaf, @pen, @log))
|
52
|
+
@log.info(self, "loaded plugin "+plugin)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
# Prints all loaded plugins.
|
58
|
+
def printMe
|
59
|
+
width = 50
|
60
|
+
@pen.print ",", "-"*width, "+\n"
|
61
|
+
@pen.print "|", " Pluginpool:".ljust(width),"|\n"
|
62
|
+
@pen.print "+", "-"*width, "+\n"
|
63
|
+
|
64
|
+
@pool.each do |plugin|
|
65
|
+
str = " ["+@pen.lightgreen+plugin.to_s+@pen.clear+"]"+@pen.clear
|
66
|
+
@pen.print "|", str.ljust(width+(str.length-@pen.uncolored(str).length)), "|\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
@pen.print "`", "-"*width, "+\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Calls +&block+ for each Plugin. This is a Wraper to Array.each.
|
73
|
+
# +&_block+:: The Block that will be invoked for each Plugin.
|
74
|
+
def each(&_block)
|
75
|
+
@pool.each(&_block)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Copyright (C) 2006 Simon Lasselsberger
|
4
|
+
# simon.lasselsberger@fh-hagenberg.at
|
5
|
+
#
|
6
|
+
# This file is part of the _fhlow_ scripting environment.
|
7
|
+
#
|
8
|
+
# The _fhlow_ scripting environment is free software; you can redistribute
|
9
|
+
# it and/or modify it under the terms of the GNU General Public License
|
10
|
+
# as published by the Free Software Foundation; either version 2 of the
|
11
|
+
# License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# _fhlow_ is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with _fhlow_; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
#
|
22
|
+
#----------------------------------------------------------------------------
|
23
|
+
require 'node'
|
24
|
+
require 'config'
|
25
|
+
require 'leaffactory'
|
26
|
+
|
27
|
+
module Fhlow
|
28
|
+
|
29
|
+
# This class represents the root directory of one fhlow environment and is therefore
|
30
|
+
# the main Node with +@nodelevel+ = 0.
|
31
|
+
class RootNode < Node
|
32
|
+
|
33
|
+
public
|
34
|
+
# Initializes the memebers and the LeafFactory.
|
35
|
+
# +_log+:: A reference to a Log object.
|
36
|
+
# +_pen+:: A reference to a Pen output object.
|
37
|
+
#
|
38
|
+
def initialize(_defaultconf, _log, _pen, _path=RootNode.detectFhlowRootDir)
|
39
|
+
|
40
|
+
# don't do anything if _path is nil
|
41
|
+
raise FhlowException.new(self.class), "Couldn't detect the fhlow root directory!" if _path.nil?
|
42
|
+
raise FhlowException.new(self.class), "You have to provide a default configuration object!" if !_defaultconf.instance_of?(Config::Config)
|
43
|
+
|
44
|
+
@path = _path
|
45
|
+
@conf = _defaultconf
|
46
|
+
|
47
|
+
# load all the leaf classes
|
48
|
+
LeafFactory.load(@path+"/flw/core/lib/module_fhlow/leafs/")
|
49
|
+
|
50
|
+
super("", "RootNode", self, 0, _log, _pen)
|
51
|
+
|
52
|
+
@nodes.each_value { |node| node.fetchDependencies() }
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def getActualLeaf(_dir=Dir.pwd)
|
57
|
+
raise FhlowException.new(self.class), "couldn't detect the actual child!" if _dir =~ /.*\/flw\/.*/
|
58
|
+
|
59
|
+
ofp = _dir.gsub(@path,"").split("/")
|
60
|
+
|
61
|
+
prefixfound = false
|
62
|
+
|
63
|
+
begin
|
64
|
+
|
65
|
+
@conf["fhlow"]["LeafPrefixes"].reverse.each do |prefixlevel|
|
66
|
+
prefixlevel.split(",").each do |prefix|
|
67
|
+
prefixfound = true if ofp[-1] =~ /#{prefix}.*/
|
68
|
+
return getLeaf(ofp) if prefixfound && ofp.length > 1
|
69
|
+
raise FhlowException.new(self.class), "couldn't detect the actual child!" if ofp.length < 2
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
ofp.delete_at(-1) if !prefixfound
|
74
|
+
|
75
|
+
end until prefixfound == true
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# Returns the path to the fhlow root directory.
|
81
|
+
def getPath
|
82
|
+
@path
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
# Tries to detect the root directory of the actual fhlow root directory by parsing
|
87
|
+
# the string provided by 'Dir.pwd'.
|
88
|
+
# +_dir+:: The directory that will be used to find the fhlow root directory.
|
89
|
+
def RootNode.detectFhlowRootDir(_dir=Dir.pwd)
|
90
|
+
if Dir.entries(_dir).include?("flw")
|
91
|
+
return _dir+"/"
|
92
|
+
else
|
93
|
+
return detectFhlowRootDir(_dir.gsub(/(.*)\/\w*[\/]*/,'\1'))
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Term
|
2
|
+
module ANSIColor
|
3
|
+
@@attributes = [
|
4
|
+
[ :clear , 0 ],
|
5
|
+
[ :reset , 0 ], # synonym for :clear
|
6
|
+
[ :bold , 1 ],
|
7
|
+
[ :dark , 2 ],
|
8
|
+
[ :italic , 3 ], # not widely implemented
|
9
|
+
[ :underline , 4 ],
|
10
|
+
[ :underscore , 4 ], # synonym for :underline
|
11
|
+
[ :blink , 5 ],
|
12
|
+
[ :rapid_blink , 6 ], # not widely implemented
|
13
|
+
[ :negative , 7 ], # no reverse because of String#reverse
|
14
|
+
[ :concealed , 8 ],
|
15
|
+
[ :strikethrough, 9 ], # not widely implemented
|
16
|
+
[ :black , 30 ],
|
17
|
+
[ :red , 31 ],
|
18
|
+
[ :green , 32 ],
|
19
|
+
[ :yellow , 33 ],
|
20
|
+
[ :blue , 34 ],
|
21
|
+
[ :magenta , 35 ],
|
22
|
+
[ :cyan , 36 ],
|
23
|
+
[ :white , 37 ],
|
24
|
+
[ :on_black , 40 ],
|
25
|
+
[ :on_red , 41 ],
|
26
|
+
[ :on_green , 42 ],
|
27
|
+
[ :on_yellow , 43 ],
|
28
|
+
[ :on_blue , 44 ],
|
29
|
+
[ :on_magenta , 45 ],
|
30
|
+
[ :on_cyan , 46 ],
|
31
|
+
[ :on_white , 47 ],
|
32
|
+
[ :lightred , "01;31"],
|
33
|
+
[ :lightgreen , "01;32"],
|
34
|
+
[ :lightyellow , "01;33"],
|
35
|
+
[ :lightblue , "01;34"],
|
36
|
+
[ :lightmagenta , "01;35"],
|
37
|
+
[ :lightcyan , "01;36"],
|
38
|
+
]
|
39
|
+
|
40
|
+
|
41
|
+
# Returns true, if the coloring function of this module
|
42
|
+
# is switched on, false otherwise.
|
43
|
+
def self.coloring?
|
44
|
+
@@coloring
|
45
|
+
end
|
46
|
+
|
47
|
+
# Turns the coloring on or off globally, so you can easily do
|
48
|
+
# this for example:
|
49
|
+
# Term::ANSIColor::coloring = STDOUT.isatty
|
50
|
+
def self.coloring=(val)
|
51
|
+
@@coloring = val
|
52
|
+
end
|
53
|
+
self.coloring = true
|
54
|
+
|
55
|
+
@@attributes.each do |c, v|
|
56
|
+
eval %Q{
|
57
|
+
def #{c}(string = nil)
|
58
|
+
result = ''
|
59
|
+
result << "\e[#{v}m" if @@coloring
|
60
|
+
if block_given?
|
61
|
+
result << yield
|
62
|
+
elsif string
|
63
|
+
result << string
|
64
|
+
elsif respond_to?(:to_str)
|
65
|
+
result << self
|
66
|
+
else
|
67
|
+
return result #only switch on
|
68
|
+
end
|
69
|
+
result << "\e[0m" if @@coloring
|
70
|
+
result
|
71
|
+
end
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
# Regular expression that is used to scan for ANSI-sequences. It is used to
|
76
|
+
# uncolor strins.
|
77
|
+
COLORED_REGEXP = /\e\[([34][0-7]|[0-9]|01;3[1-6])m/
|
78
|
+
|
79
|
+
# Returns an uncolored version of the string, that is all
|
80
|
+
# ANSI-sequences are stripped from the string.
|
81
|
+
def uncolored(string = nil) # :yields:
|
82
|
+
if block_given?
|
83
|
+
yield.gsub(COLORED_REGEXP, '')
|
84
|
+
elsif string
|
85
|
+
string.gsub(COLORED_REGEXP, '')
|
86
|
+
elsif respond_to?(:to_str)
|
87
|
+
gsub(COLORED_REGEXP, '')
|
88
|
+
else
|
89
|
+
''
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
module_function
|
94
|
+
|
95
|
+
# Returns an array of all Term::ANSIColor attributes as symbols.
|
96
|
+
def attributes
|
97
|
+
@@attributes.map { |c| c.first }
|
98
|
+
end
|
99
|
+
extend self
|
100
|
+
end
|
101
|
+
end
|
102
|
+
# vim: set et sw=2 ts=2:
|