summaryrefslogtreecommitdiff
path: root/lib/highline/style.rb
diff options
context:
space:
mode:
authorAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-11-17 11:33:05 -0300
committerAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-11-17 11:33:05 -0300
commit6bfb69667323df4052b13785c4ac15405798973b (patch)
tree7df58ce902a18e9821bad22c8240487989f40870 /lib/highline/style.rb
parent98f763313adf495625a214fda1b484d8789e2de5 (diff)
downloadhighline-6bfb69667323df4052b13785c4ac15405798973b.tar.gz
Extract Style.find_or_create_style and .find_or_create_style_list
Diffstat (limited to 'lib/highline/style.rb')
-rwxr-xr-xlib/highline/style.rb52
1 files changed, 30 insertions, 22 deletions
diff --git a/lib/highline/style.rb b/lib/highline/style.rb
index 1acac0b..63085f0 100755
--- a/lib/highline/style.rb
+++ b/lib/highline/style.rb
@@ -14,34 +14,42 @@ class HighLine
def self.Style(*args)
args = args.compact.flatten
if args.size==1
- arg = args.first
- if arg.is_a?(Style)
- Style.list[arg.name] || Style.index(arg)
- elsif arg.is_a?(::String) && arg =~ /^\e\[/ # arg is a code
- if styles = Style.code_index[arg]
- styles.first
- else
- Style.new(:code=>arg)
- end
- elsif style = Style.list[arg]
- style
- elsif HighLine.color_scheme && HighLine.color_scheme[arg]
- HighLine.color_scheme[arg]
- elsif arg.is_a?(Hash)
- Style.new(arg)
- elsif arg.to_s.downcase =~ /^rgb_([a-f0-9]{6})$/
- Style.rgb($1)
- elsif arg.to_s.downcase =~ /^on_rgb_([a-f0-9]{6})$/
- Style.rgb($1).on
+ find_or_create_style(*args)
+ else
+ find_or_create_style_list(*args)
+ end
+ end
+
+ def self.find_or_create_style(*args)
+ arg = args.first
+ if arg.is_a?(Style)
+ Style.list[arg.name] || Style.index(arg)
+ elsif arg.is_a?(::String) && arg =~ /^\e\[/ # arg is a code
+ if styles = Style.code_index[arg]
+ styles.first
else
- raise NameError, "#{arg.inspect} is not a defined Style"
+ Style.new(:code=>arg)
end
+ elsif style = Style.list[arg]
+ style
+ elsif HighLine.color_scheme && HighLine.color_scheme[arg]
+ HighLine.color_scheme[arg]
+ elsif arg.is_a?(Hash)
+ Style.new(arg)
+ elsif arg.to_s.downcase =~ /^rgb_([a-f0-9]{6})$/
+ Style.rgb($1)
+ elsif arg.to_s.downcase =~ /^on_rgb_([a-f0-9]{6})$/
+ Style.rgb($1).on
else
- name = args
- Style.list[name] || Style.new(:list=>args)
+ raise NameError, "#{arg.inspect} is not a defined Style"
end
end
+ def self.find_or_create_style_list(*args)
+ name = args
+ Style.list[name] || Style.new(:list=>args)
+ end
+
# ANSI styles to be used by HighLine.
class Style