Class: NattyUI::Theme
- Inherits:
-
Object
- Object
- NattyUI::Theme
- Defined in:
- lib/natty-ui/theme.rb
Overview
This chapter needs more documentation.
A theme defines the style of elements.
Defined Under Namespace
Classes: Compiled
Class Attribute Summary collapse
-
.current ⇒ Compiled
Currently used theme.
-
.default ⇒ Theme
readonly
Default theme.
Instance Attribute Summary collapse
-
#border ⇒ Object
readonly
Returns the value of attribute border.
-
#choice_current_style ⇒ Object
Returns the value of attribute choice_current_style.
-
#choice_style ⇒ Object
Returns the value of attribute choice_style.
-
#heading ⇒ Object
readonly
Returns the value of attribute heading.
-
#heading_sytle ⇒ Object
Returns the value of attribute heading_sytle.
-
#mark ⇒ Object
readonly
Returns the value of attribute mark.
-
#section_border ⇒ Object
Returns the value of attribute section_border.
-
#section_styles ⇒ Object
readonly
Returns the value of attribute section_styles.
-
#task_style ⇒ Object
Returns the value of attribute task_style.
Class Method Summary collapse
-
.create {|theme| ... } ⇒ Theme
Create a theme.
Instance Method Summary collapse
- #compiled ⇒ Object
- #define_border(**defs) ⇒ Object
- #define_heading(*defs) ⇒ Object
- #define_marker(**defs) ⇒ Object
- #define_section(**defs) ⇒ Object
Class Attribute Details
.current ⇒ Compiled
Currently used theme
15 16 17 |
# File 'lib/natty-ui/theme.rb', line 15 def current @current end |
.default ⇒ Theme (readonly)
Default theme.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/natty-ui/theme.rb', line 42 def default create do |theme| theme.heading_sytle = :bright_blue theme.task_style = i[bright_green b] # theme.choice_style = theme.choice_current_style = i[bright_white on_blue b] theme.define_marker( bullet: '[bright_white]•[/fg]', checkmark: '[bright_green]✓[/fg]', quote: '[bright_blue]▍[/fg]', information: '[bright_yellow]𝒊[/fg]', warning: '[bright_yellow]![/fg]', error: '[red]𝙓[/fg]', failed: '[bright_red]𝑭[/fg]', choice: '[bright_white]◦[/fg]', current_choice: '[bright_green]◉[/fg]' ) theme.define_section( default: :bright_blue, message: :bright_blue, information: :bright_blue, warning: :bright_yellow, error: :red, failed: :bright_red ) end end |
Instance Attribute Details
#border ⇒ Object (readonly)
Returns the value of attribute border.
72 73 74 |
# File 'lib/natty-ui/theme.rb', line 72 def border @border end |
#choice_current_style ⇒ Object
Returns the value of attribute choice_current_style.
72 73 74 |
# File 'lib/natty-ui/theme.rb', line 72 def choice_current_style @choice_current_style end |
#choice_style ⇒ Object
Returns the value of attribute choice_style.
72 73 74 |
# File 'lib/natty-ui/theme.rb', line 72 def choice_style @choice_style end |
#heading ⇒ Object (readonly)
Returns the value of attribute heading.
72 73 74 |
# File 'lib/natty-ui/theme.rb', line 72 def heading @heading end |
#heading_sytle ⇒ Object
Returns the value of attribute heading_sytle.
72 73 74 |
# File 'lib/natty-ui/theme.rb', line 72 def heading_sytle @heading_sytle end |
#mark ⇒ Object (readonly)
Returns the value of attribute mark.
72 73 74 |
# File 'lib/natty-ui/theme.rb', line 72 def mark @mark end |
#section_border ⇒ Object
Returns the value of attribute section_border.
71 72 73 |
# File 'lib/natty-ui/theme.rb', line 71 def section_border @section_border end |
#section_styles ⇒ Object (readonly)
Returns the value of attribute section_styles.
72 73 74 |
# File 'lib/natty-ui/theme.rb', line 72 def section_styles @section_styles end |
#task_style ⇒ Object
Returns the value of attribute task_style.
72 73 74 |
# File 'lib/natty-ui/theme.rb', line 72 def task_style @task_style end |
Class Method Details
.create {|theme| ... } ⇒ Theme
Create a theme.
32 33 34 35 36 |
# File 'lib/natty-ui/theme.rb', line 32 def create theme = new yield(theme) if block_given? theme end |
Instance Method Details
#compiled ⇒ Object
97 |
# File 'lib/natty-ui/theme.rb', line 97 def compiled = Compiled.new(self).freeze |
#define_border(**defs) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/natty-ui/theme.rb', line 104 def define_border(**defs) defs.each_pair do |name, str| s = str.to_s case Text.width(s, bbcode: false) when 1 @border[name.to_sym] = "#{s * 11} " when 11 @border[name.to_sym] = "#{s} " when 13 @border[name.to_sym] = s else raise( TypeError, "invalid boder definition for #{name} - #{str.inspect}" ) end end self end |
#define_heading(*defs) ⇒ Object
124 125 126 127 128 |
# File 'lib/natty-ui/theme.rb', line 124 def define_heading(*defs) @heading = defs.flatten.take(6) @heading += Array.new(6 - @heading.size, @heading[-1]) self end |
#define_marker(**defs) ⇒ Object
99 100 101 102 |
# File 'lib/natty-ui/theme.rb', line 99 def define_marker(**defs) @mark.merge!(defs) self end |
#define_section(**defs) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/natty-ui/theme.rb', line 130 def define_section(**defs) defs.each_pair do |name, style| style = Utils.style(style) @section_styles[name.to_sym] = style if style end self end |