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.
- .emoji ⇒ Object
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 69 |
# 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]', current: '[bright_green]➔[/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.
102 103 104 |
# File 'lib/natty-ui/theme.rb', line 102 def border @border end |
#choice_current_style ⇒ Object
Returns the value of attribute choice_current_style.
102 103 104 |
# File 'lib/natty-ui/theme.rb', line 102 def choice_current_style @choice_current_style end |
#choice_style ⇒ Object
Returns the value of attribute choice_style.
102 103 104 |
# File 'lib/natty-ui/theme.rb', line 102 def choice_style @choice_style end |
#heading ⇒ Object (readonly)
Returns the value of attribute heading.
102 103 104 |
# File 'lib/natty-ui/theme.rb', line 102 def heading @heading end |
#heading_sytle ⇒ Object
Returns the value of attribute heading_sytle.
102 103 104 |
# File 'lib/natty-ui/theme.rb', line 102 def heading_sytle @heading_sytle end |
#mark ⇒ Object (readonly)
Returns the value of attribute mark.
102 103 104 |
# File 'lib/natty-ui/theme.rb', line 102 def mark @mark end |
#section_border ⇒ Object
Returns the value of attribute section_border.
101 102 103 |
# File 'lib/natty-ui/theme.rb', line 101 def section_border @section_border end |
#section_styles ⇒ Object (readonly)
Returns the value of attribute section_styles.
102 103 104 |
# File 'lib/natty-ui/theme.rb', line 102 def section_styles @section_styles end |
#task_style ⇒ Object
Returns the value of attribute task_style.
102 103 104 |
# File 'lib/natty-ui/theme.rb', line 102 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 |
.emoji ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/natty-ui/theme.rb', line 71 def emoji 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: '▫️', checkmark: '✅', quote: '[bright_blue]▍[/fg]', information: '📌', warning: '⚠️', error: '❗️', failed: '‼️', current: '➡️', 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 Method Details
#compiled ⇒ Object
127 |
# File 'lib/natty-ui/theme.rb', line 127 def compiled = Compiled.new(self).freeze |
#define_border(**defs) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/natty-ui/theme.rb', line 134 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
154 155 156 157 158 |
# File 'lib/natty-ui/theme.rb', line 154 def define_heading(*defs) @heading = defs.flatten.take(6) @heading += Array.new(6 - @heading.size, @heading[-1]) self end |
#define_marker(**defs) ⇒ Object
129 130 131 132 |
# File 'lib/natty-ui/theme.rb', line 129 def define_marker(**defs) @mark.merge!(defs) self end |
#define_section(**defs) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/natty-ui/theme.rb', line 160 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 |