Class: Tuile::StyledString::Style
- Inherits:
-
Object
- Object
- Tuile::StyledString::Style
- Defined in:
- lib/tuile/styled_string.rb
Overview
A frozen value type describing the visual style of a Span. Colors are stored as Color instances (or ‘nil` for the terminal default); inputs to Style.new and #merge are coerced via Color.coerce, so the four accepted color forms — `nil`, Symbol, Integer 0..255, RGB Array — work transparently.
Constant Summary collapse
- DEFAULT =
The style with no color and no attributes — what the terminal shows without any SGR applied.
new
Instance Attribute Summary collapse
- #bg ⇒ Color? readonly
- #bold ⇒ Boolean readonly
- #fg ⇒ Color? readonly
- #italic ⇒ Boolean readonly
- #underline ⇒ Boolean readonly
Class Method Summary collapse
Instance Method Summary collapse
- #default? ⇒ Boolean
-
#merge(**overrides) ⇒ Style
Returns a new Style with the given attributes overridden.
Instance Attribute Details
#bg ⇒ Color? (readonly)
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 |
# File 'lib/tuile/styled_string.rb', line 72 class Style < Data.define(:fg, :bg, :bold, :italic, :underline) # @param fg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bold [Boolean] # @param italic [Boolean] # @param underline [Boolean] # @return [Style] # @raise [ArgumentError] when a color is not one of the accepted forms. def self.new(fg: nil, bg: nil, bold: false, italic: false, underline: false) super(fg: Color.coerce(fg), bg: Color.coerce(bg), bold:, italic:, underline:) end # The style with no color and no attributes — what the terminal shows # without any SGR applied. # @return [Style] DEFAULT = new # @return [Boolean] def default? = self == DEFAULT # Returns a new {Style} with the given attributes overridden. # @param overrides [Hash{Symbol => Object}] # @return [Style] def merge(**overrides) = self.class.new(**to_h.merge(overrides)) end |
#bold ⇒ Boolean (readonly)
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 |
# File 'lib/tuile/styled_string.rb', line 72 class Style < Data.define(:fg, :bg, :bold, :italic, :underline) # @param fg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bold [Boolean] # @param italic [Boolean] # @param underline [Boolean] # @return [Style] # @raise [ArgumentError] when a color is not one of the accepted forms. def self.new(fg: nil, bg: nil, bold: false, italic: false, underline: false) super(fg: Color.coerce(fg), bg: Color.coerce(bg), bold:, italic:, underline:) end # The style with no color and no attributes — what the terminal shows # without any SGR applied. # @return [Style] DEFAULT = new # @return [Boolean] def default? = self == DEFAULT # Returns a new {Style} with the given attributes overridden. # @param overrides [Hash{Symbol => Object}] # @return [Style] def merge(**overrides) = self.class.new(**to_h.merge(overrides)) end |
#fg ⇒ Color? (readonly)
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 |
# File 'lib/tuile/styled_string.rb', line 72 class Style < Data.define(:fg, :bg, :bold, :italic, :underline) # @param fg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bold [Boolean] # @param italic [Boolean] # @param underline [Boolean] # @return [Style] # @raise [ArgumentError] when a color is not one of the accepted forms. def self.new(fg: nil, bg: nil, bold: false, italic: false, underline: false) super(fg: Color.coerce(fg), bg: Color.coerce(bg), bold:, italic:, underline:) end # The style with no color and no attributes — what the terminal shows # without any SGR applied. # @return [Style] DEFAULT = new # @return [Boolean] def default? = self == DEFAULT # Returns a new {Style} with the given attributes overridden. # @param overrides [Hash{Symbol => Object}] # @return [Style] def merge(**overrides) = self.class.new(**to_h.merge(overrides)) end |
#italic ⇒ Boolean (readonly)
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 |
# File 'lib/tuile/styled_string.rb', line 72 class Style < Data.define(:fg, :bg, :bold, :italic, :underline) # @param fg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bold [Boolean] # @param italic [Boolean] # @param underline [Boolean] # @return [Style] # @raise [ArgumentError] when a color is not one of the accepted forms. def self.new(fg: nil, bg: nil, bold: false, italic: false, underline: false) super(fg: Color.coerce(fg), bg: Color.coerce(bg), bold:, italic:, underline:) end # The style with no color and no attributes — what the terminal shows # without any SGR applied. # @return [Style] DEFAULT = new # @return [Boolean] def default? = self == DEFAULT # Returns a new {Style} with the given attributes overridden. # @param overrides [Hash{Symbol => Object}] # @return [Style] def merge(**overrides) = self.class.new(**to_h.merge(overrides)) end |
#underline ⇒ Boolean (readonly)
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 |
# File 'lib/tuile/styled_string.rb', line 72 class Style < Data.define(:fg, :bg, :bold, :italic, :underline) # @param fg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bg [Color, Symbol, Integer, Array<Integer>, nil] coerced via {Color.coerce}. # @param bold [Boolean] # @param italic [Boolean] # @param underline [Boolean] # @return [Style] # @raise [ArgumentError] when a color is not one of the accepted forms. def self.new(fg: nil, bg: nil, bold: false, italic: false, underline: false) super(fg: Color.coerce(fg), bg: Color.coerce(bg), bold:, italic:, underline:) end # The style with no color and no attributes — what the terminal shows # without any SGR applied. # @return [Style] DEFAULT = new # @return [Boolean] def default? = self == DEFAULT # Returns a new {Style} with the given attributes overridden. # @param overrides [Hash{Symbol => Object}] # @return [Style] def merge(**overrides) = self.class.new(**to_h.merge(overrides)) end |
Class Method Details
Instance Method Details
#merge(**overrides) ⇒ Style
Returns a new Tuile::StyledString::Style with the given attributes overridden.
95 |
# File 'lib/tuile/styled_string.rb', line 95 def merge(**overrides) = self.class.new(**to_h.merge(overrides)) |