Class: RubyRich::Theme
- Inherits:
-
Object
- Object
- RubyRich::Theme
- Defined in:
- lib/ruby_rich/theme.rb
Constant Summary collapse
- DEFAULT_ROLES =
{ accent: { color: :blue, bright: true, bold: true }, body: { color: :white, bright: true }, muted: { color: :black, bright: true }, dim: { color: :black, bright: true }, thinking: { color: :white, bright: true, italic: true }, success: { color: :green, bright: true }, warning: { color: :yellow, bright: true }, error: { color: :red, bright: true }, status: { color: :cyan, bright: true } }.freeze
Instance Attribute Summary collapse
-
#border ⇒ Object
readonly
Returns the value of attribute border.
-
#focused_border ⇒ Object
readonly
Returns the value of attribute focused_border.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Class Method Summary collapse
Instance Method Summary collapse
- #color(name, bright: false) ⇒ Object
-
#initialize(roles: {}, border: :blue, focused_border: :cyan) ⇒ Theme
constructor
A new instance of Theme.
- #panel_border(focused: false) ⇒ Object
- #style(text, role = :body) ⇒ Object
Constructor Details
#initialize(roles: {}, border: :blue, focused_border: :cyan) ⇒ Theme
Returns a new instance of Theme.
64 65 66 67 68 |
# File 'lib/ruby_rich/theme.rb', line 64 def initialize(roles: {}, border: :blue, focused_border: :cyan) @roles = DEFAULT_ROLES.merge(roles) @border = border @focused_border = focused_border end |
Instance Attribute Details
#border ⇒ Object (readonly)
Returns the value of attribute border.
17 18 19 |
# File 'lib/ruby_rich/theme.rb', line 17 def border @border end |
#focused_border ⇒ Object (readonly)
Returns the value of attribute focused_border.
17 18 19 |
# File 'lib/ruby_rich/theme.rb', line 17 def focused_border @focused_border end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
17 18 19 |
# File 'lib/ruby_rich/theme.rb', line 17 def roles @roles end |
Class Method Details
.agent_dark ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby_rich/theme.rb', line 25 def self.agent_dark new( border: :blue, focused_border: :cyan, roles: { accent: { color: :blue, bright: true, bold: true }, body: { color: :white, bright: true }, muted: { color: :black, bright: true }, dim: { color: :black, bright: true }, thinking: { color: :white, bright: true, italic: true }, success: { color: :green, bright: true }, warning: { color: :yellow, bright: true }, error: { color: :red, bright: true }, status: { color: :cyan, bright: true } } ) end |
.auto ⇒ Object
19 20 21 22 23 |
# File 'lib/ruby_rich/theme.rb', line 19 def self.auto ENV["COLORFGBG"].to_s.split(";").last.to_i >= 8 ? light : agent_dark rescue agent_dark end |
.light ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby_rich/theme.rb', line 43 def self.light new( border: :blue, focused_border: :cyan, roles: { accent: { color: :blue, bright: false, bold: true }, body: { color: :black, bright: false }, muted: { color: :black, bright: true }, dim: { color: :black, bright: true }, success: { color: :green, bright: false }, warning: { color: :yellow, bright: false }, error: { color: :red, bright: false }, status: { color: :cyan, bright: false } } ) end |
.no_color ⇒ Object
60 61 62 |
# File 'lib/ruby_rich/theme.rb', line 60 def self.no_color new(roles: DEFAULT_ROLES.transform_values { { color: :white } }, border: :white, focused_border: :white) end |
Instance Method Details
#color(name, bright: false) ⇒ Object
75 76 77 |
# File 'lib/ruby_rich/theme.rb', line 75 def color(name, bright: false) AnsiCode.color(name, bright) end |
#panel_border(focused: false) ⇒ Object
79 80 81 |
# File 'lib/ruby_rich/theme.rb', line 79 def panel_border(focused: false) focused ? @focused_border : @border end |