diff options
author | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-12-14 07:45:20 -0300 |
---|---|---|
committer | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-12-14 07:45:20 -0300 |
commit | 9edb18767c8bbf397e6ed9723d72bbc624e91980 (patch) | |
tree | 0bd2a443c3e8a648b781b03c522658edba9aac3f /lib/highline/builtin_styles.rb | |
parent | 2de591ce37b54ca7efe9e5564145d80ae02b515d (diff) | |
download | highline-9edb18767c8bbf397e6ed9723d72bbc624e91980.tar.gz |
Improve HighLine::BuiltinStyles documentation
Diffstat (limited to 'lib/highline/builtin_styles.rb')
-rw-r--r-- | lib/highline/builtin_styles.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/highline/builtin_styles.rb b/lib/highline/builtin_styles.rb index 6321d1d..c829f60 100644 --- a/lib/highline/builtin_styles.rb +++ b/lib/highline/builtin_styles.rb @@ -1,11 +1,16 @@ #coding: utf-8 class HighLine + # Builtin Styles that are included at HighLine initialization. + # It has the basic styles like :bold and :underline. module BuiltinStyles + # Included callback + # @param base [Class, Module] base class def self.included(base) base.extend ClassMethods end + # Basic styles' ANSI escape codes like :bold => "\e[1m" STYLE_LIST = { erase_line: "\e[K", erase_char: "\e[P", @@ -27,8 +32,10 @@ class HighLine const_set style + "_STYLE", Style.new(name: style_name, code: code, builtin: true) end + # Basic Style names like CLEAR, BOLD, UNDERLINE STYLES = %w{CLEAR RESET BOLD DARK UNDERLINE UNDERSCORE BLINK REVERSE CONCEALED} + # A Hash with the basic colors an their ANSI escape codes. COLOR_LIST = { black: { code: "\e[30m", rgb: [0, 0, 0] }, red: { code: "\e[31m", rgb: [128, 0, 0] }, @@ -56,6 +63,7 @@ class HighLine const_set color + "_STYLE", style end + # The builtin styles basic colors like black, red, green. BASIC_COLORS = %w{BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GRAY GREY NONE} colors = BASIC_COLORS.dup @@ -68,6 +76,8 @@ class HighLine colors << light_color const_set light_color + '_STYLE', const_get(color + '_STYLE').light end + + # The builtin styles' colors like LIGHT_RED and BRIGHT_BLUE. COLORS = colors colors.each do |color| @@ -78,11 +88,17 @@ class HighLine ON_NONE_STYLE.rgb = [255,255,255] # Override; white background + # BuiltinStyles class methods to be extended. module ClassMethods - RGB_COLOR = /^(ON_)?(RGB_)([A-F0-9]{6})(_STYLE)?$/ + # Regexp to match against RGB style constant names. + RGB_COLOR_PATTERN = /^(ON_)?(RGB_)([A-F0-9]{6})(_STYLE)?$/ + + # const_missing callback for automatically respond to + # builtin constants (without explicitly defining them) + # @param name [Symbol] missing constant name def const_missing(name) - if name.to_s =~ RGB_COLOR + if name.to_s =~ RGB_COLOR_PATTERN on = $1 suffix = $4 |