struct Sheen::Style

Overview

An immutable set of styling rules bound to a renderer. Every setter returns a new style, and the original is never mutated.

Build one fluently like Style.new.bold.foreground("#7D56F4) or via the Sheen.style block.

Defined in:

sheen/style.cr

Constant Summary

NO_TAB_CONVERSION = -1

Sentinel for #tab_width that disables tab conversion wholesale.

TAB_WIDTH_DEFAULT = 4

Default tab expansion width when #tab_width is unset.

Constructors

Macro Summary

Instance Method Summary

Constructor Detail

def self.new(renderer : Renderer = Sheen.renderer, value : String = "", bold : Union(Bool, Nil) = nil, italic : Union(Bool, Nil) = nil, underline : Union(Bool, Nil) = nil, strikethrough : Union(Bool, Nil) = nil, reverse : Union(Bool, Nil) = nil, blink : Union(Bool, Nil) = nil, faint : Union(Bool, Nil) = nil, underline_spaces : Union(Bool, Nil) = nil, strikethrough_spaces : Union(Bool, Nil) = nil, color_whitespace : Union(Bool, Nil) = nil, foreground : Union(TerminalColor, Nil) = nil, background : Union(TerminalColor, Nil) = nil, max_width : Union(Int32, Nil) = nil, max_height : Union(Int32, Nil) = nil, width : Union(Int32, Nil) = nil, height : Union(Int32, Nil) = nil, align_horizontal : Union(Position, Nil) = nil, align_vertical : Union(Position, Nil) = nil, padding_top : Union(Int32, Nil) = nil, padding_right : Union(Int32, Nil) = nil, padding_bottom : Union(Int32, Nil) = nil, padding_left : Union(Int32, Nil) = nil, margin_top : Union(Int32, Nil) = nil, margin_right : Union(Int32, Nil) = nil, margin_bottom : Union(Int32, Nil) = nil, margin_left : Union(Int32, Nil) = nil, margin_background : Union(TerminalColor, Nil) = nil, inline : Union(Bool, Nil) = nil, tab_width : Union(Int32, Nil) = nil, border_style : Union(Border, Nil) = nil, border_top : Union(Bool, Nil) = nil, border_right : Union(Bool, Nil) = nil, border_bottom : Union(Bool, Nil) = nil, border_left : Union(Bool, Nil) = nil, border_top_foreground : Union(TerminalColor, Nil) = nil, border_right_foreground : Union(TerminalColor, Nil) = nil, border_bottom_foreground : Union(TerminalColor, Nil) = nil, border_left_foreground : Union(TerminalColor, Nil) = nil, border_top_background : Union(TerminalColor, Nil) = nil, border_right_background : Union(TerminalColor, Nil) = nil, border_bottom_background : Union(TerminalColor, Nil) = nil, border_left_background : Union(TerminalColor, Nil) = nil, transform : Union(Transform, Nil) = nil) #

The single source of truth for the property fields. nil means unset.

Follows the form {name, Type, default}


[View source]

Macro Detail

macro bool_prop(name) #

Emits the setters and ? getter for a boolean property.


[View source]
macro color_prop(name) #

Emits the setter and getter for a color property.

Defaults to NoColor when unset.


[View source]
macro int_prop(name) #

Emits the setter and getter for an Int32 property.

Defaults to 0 when unset


[View source]
macro position_prop(name, default) #

Emits the setter and getter for a Position property.

default when unset.


[View source]
macro storage(*decls) #

Generates initialize and copy_with from a single field list so the two can never drift. Each decl is the form {name, Type, default}.

nil means unset


[View source]
macro unset_prop(name) #

[View source]

Instance Method Detail

def align(horizontal : Position, vertical : Position | Nil = nil) : Style #

Sets horizontal alignment, with optional vertical alignment.


[View source]
def align_horizontal(pos : Position) : Style #

Sets align_horizontal to pos. Returns a new Style.


[View source]
def align_horizontal : Position #

The align_horizontal position, or Position::LEFT when unset.


[View source]
def align_horizontal_set? : Bool #

True when align_horizontal has been explicitly set


def align_vertical(pos : Position) : Style #

Sets align_vertical to pos. Returns a new Style.


[View source]
def align_vertical : Position #

The align_vertical position, or Position::TOP when unset.


[View source]
def align_vertical_set? : Bool #

True when align_vertical has been explicitly set


def background(color : TerminalColor | String | Int) : Style #

Sets background from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def background : TerminalColor #

The background color, or NoColor when unset.


[View source]
def background_set? : Bool #

True when background has been explicitly set


def blink(value : Bool = true) : Style #

Enables or disables blink. Returns a new Style


[View source]
def blink? : Bool #

True when blink is enabled.


[View source]
def blink_set? : Bool #

True when blink has been explicitly set


def bold(value : Bool = true) : Style #

Enables or disables bold. Returns a new Style


[View source]
def bold? : Bool #

True when bold is enabled.


[View source]
def bold_set? : Bool #

True when bold has been explicitly set


def border(b : Border) : Style #

Sets the border b and which sides show, via CSS-style shorthand.

  • no side values: shows all four
  • 1 side value: all sides
  • 2 side values: vert, horiz
  • 3 side values: top, horiz, bottom
  • 4 side values: top, right, bottom, left

[View source]
def border(b : Border, *sides : Bool) : Style #

Sets the border b and which sides show, via CSS-style shorthand.

  • no side values: shows all four
  • 1 side value: all sides
  • 2 side values: vert, horiz
  • 3 side values: top, horiz, bottom
  • 4 side values: top, right, bottom, left

[View source]
def border_background(*colors : TerminalColor | String | Int) : Style #

Sets all four border background colors via CSS 1-4 shorthand values. Raises on a value count outside 1-4.


[View source]
def border_bottom(value : Bool = true) : Style #

Enables or disables border_bottom. Returns a new Style


[View source]
def border_bottom? : Bool #

True when border_bottom is enabled.


[View source]
def border_bottom_background(color : TerminalColor | String | Int) : Style #

Sets border_bottom_background from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def border_bottom_background : TerminalColor #

The border_bottom_background color, or NoColor when unset.


[View source]
def border_bottom_background_set? : Bool #

True when border_bottom_background has been explicitly set


def border_bottom_foreground(color : TerminalColor | String | Int) : Style #

Sets border_bottom_foreground from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def border_bottom_foreground : TerminalColor #

The border_bottom_foreground color, or NoColor when unset.


[View source]
def border_bottom_foreground_set? : Bool #

True when border_bottom_foreground has been explicitly set


def border_bottom_set? : Bool #

True when border_bottom has been explicitly set


def border_bottom_size : Int32 #

Cell-width of the bottom border edge. Defaults to 0 when the bottom side is off.


[View source]
def border_foreground(*colors : TerminalColor | String | Int) : Style #

Sets all four border foreground colors via CSS 1-4 shorthand values. Raises on a value count outside 1-4.


[View source]
def border_left(value : Bool = true) : Style #

Enables or disables border_left. Returns a new Style


[View source]
def border_left? : Bool #

True when border_left is enabled.


[View source]
def border_left_background(color : TerminalColor | String | Int) : Style #

Sets border_left_background from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def border_left_background : TerminalColor #

The border_left_background color, or NoColor when unset.


[View source]
def border_left_background_set? : Bool #

True when border_left_background has been explicitly set


def border_left_foreground(color : TerminalColor | String | Int) : Style #

Sets border_left_foreground from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def border_left_foreground : TerminalColor #

The border_left_foreground color, or NoColor when unset.


[View source]
def border_left_foreground_set? : Bool #

True when border_left_foreground has been explicitly set


def border_left_set? : Bool #

True when border_left has been explicitly set


def border_left_size : Int32 #

Cell-width of the left border edge. Defaults to 0 when the left side is off.


[View source]
def border_right(value : Bool = true) : Style #

Enables or disables border_right. Returns a new Style


[View source]
def border_right? : Bool #

True when border_right is enabled.


[View source]
def border_right_background(color : TerminalColor | String | Int) : Style #

Sets border_right_background from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def border_right_background : TerminalColor #

The border_right_background color, or NoColor when unset.


[View source]
def border_right_background_set? : Bool #

True when border_right_background has been explicitly set


def border_right_foreground(color : TerminalColor | String | Int) : Style #

Sets border_right_foreground from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def border_right_foreground : TerminalColor #

The border_right_foreground color, or NoColor when unset.


[View source]
def border_right_foreground_set? : Bool #

True when border_right_foreground has been explicitly set


def border_right_set? : Bool #

True when border_right has been explicitly set


def border_right_size : Int32 #

Cell-width of the right border edge. Defaults to 0 when the right side is off.


[View source]
def border_style(b : Border) : Style #

Sets the border b character styleset without touching side visibility. If no side is later toggled, all four are rendered. (see #implicit_borders?)


[View source]
def border_style : Border #

The border character set, or a none border when unset.


[View source]
def border_style_set? : Bool #

True when border_style has been explicitly set


[View source]
def border_top(value : Bool = true) : Style #

Enables or disables border_top. Returns a new Style


[View source]
def border_top? : Bool #

True when border_top is enabled.


[View source]
def border_top_background(color : TerminalColor | String | Int) : Style #

Sets border_top_background from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def border_top_background : TerminalColor #

The border_top_background color, or NoColor when unset.


[View source]
def border_top_background_set? : Bool #

True when border_top_background has been explicitly set


def border_top_foreground(color : TerminalColor | String | Int) : Style #

Sets border_top_foreground from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def border_top_foreground : TerminalColor #

The border_top_foreground color, or NoColor when unset.


[View source]
def border_top_foreground_set? : Bool #

True when border_top_foreground has been explicitly set


def border_top_set? : Bool #

True when border_top has been explicitly set


def border_top_size : Int32 #

Cell-width of the top border edge. Defaults to 0 when the top side is off.


[View source]
def color_whitespace(value : Bool = true) : Style #

Enables or disables color_whitespace. Returns a new Style


[View source]
def color_whitespace? : Bool #

True when color_whitespace is enabled.


[View source]
def color_whitespace_set? : Bool #

True when color_whitespace has been explicitly set


def faint(value : Bool = true) : Style #

Enables or disables faint. Returns a new Style


[View source]
def faint? : Bool #

True when faint is enabled.


[View source]
def faint_set? : Bool #

True when faint has been explicitly set


def foreground(color : TerminalColor | String | Int) : Style #

Sets foreground from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def foreground : TerminalColor #

The foreground color, or NoColor when unset.


[View source]
def foreground_set? : Bool #

True when foreground has been explicitly set


def frame_size : Tuple(Int32, Int32) #

Getter for the {horizontal, vertical} frame size


[View source]
def height(n : Int32) : Style #

Sets height to n. Returns a new Style


[View source]
def height : Int32 #

The height value, or 0 when unset.


[View source]
def height_set? : Bool #

True when height has been explicitly set


def horizontal_border_size : Int32 #

Total horizontal border width, left + right.


[View source]
def horizontal_frame_size : Int32 #

Getter sum of horizontal margins, padding, and border.


[View source]
def horizontal_margins : Int32 #

Total horizontal margins, left + right


[View source]
def horizontal_padding : Int32 #

Total horizontal padding, left + right


[View source]
def implicit_borders? : Bool #

True when a border style is set but no side has been explicitly toggled, which triggers all four sides to render


[View source]
def inherit(other : Style) : Style #

Overlays other onto this style. For every property other has explicitly set that this style has not, this style adopts the value of other and returns a new Style.

Note:

  • Inheriting a background also seeds the margin background when neither style has one set.
  • Padding, margins, and the bound string value are the exceptions and are never inherited, so those properties are intentionally excluded.

[View source]
def inline(value : Bool = true) : Style #

Enables or disables inline. Returns a new Style


[View source]
def inline? : Bool #

True when inline is enabled.


[View source]
def inline_set? : Bool #

True when inline has been explicitly set


def italic(value : Bool = true) : Style #

Enables or disables italic. Returns a new Style


[View source]
def italic? : Bool #

True when italic is enabled.


[View source]
def italic_set? : Bool #

True when italic has been explicitly set


def margin(*values : Int32) : Style #

Sets margins via same CSS shorthand as #padding.

Raises on any value count other than 1-4.


[View source]
def margin_background(color : TerminalColor | String | Int) : Style #

Sets margin_background from a TerminalColor, hex string, or ANSI index. Returns a new Style


[View source]
def margin_background : TerminalColor #

The margin_background color, or NoColor when unset.


[View source]
def margin_background_set? : Bool #

True when margin_background has been explicitly set


def margin_bottom(n : Int32) : Style #

Sets margin_bottom to n. Returns a new Style


[View source]
def margin_bottom : Int32 #

The margin_bottom value, or 0 when unset.


[View source]
def margin_bottom_set? : Bool #

True when margin_bottom has been explicitly set


def margin_left(n : Int32) : Style #

Sets margin_left to n. Returns a new Style


[View source]
def margin_left : Int32 #

The margin_left value, or 0 when unset.


[View source]
def margin_left_set? : Bool #

True when margin_left has been explicitly set


def margin_right(n : Int32) : Style #

Sets margin_right to n. Returns a new Style


[View source]
def margin_right : Int32 #

The margin_right value, or 0 when unset.


[View source]
def margin_right_set? : Bool #

True when margin_right has been explicitly set


def margin_top(n : Int32) : Style #

Sets margin_top to n. Returns a new Style


[View source]
def margin_top : Int32 #

The margin_top value, or 0 when unset.


[View source]
def margin_top_set? : Bool #

True when margin_top has been explicitly set


def max_height(n : Int32) : Style #

Sets max_height to n. Returns a new Style


[View source]
def max_height : Int32 #

The max_height value, or 0 when unset.


[View source]
def max_height_set? : Bool #

True when max_height has been explicitly set


def max_width(n : Int32) : Style #

Sets max_width to n. Returns a new Style


[View source]
def max_width : Int32 #

The max_width value, or 0 when unset.


[View source]
def max_width_set? : Bool #

True when max_width has been explicitly set


def padding(*values : Int32) : Style #

Sets padding via CSS shorthand:

  • 1 value: all sides
  • 2 values: vert, horiz
  • 3 values: top, horiz, bottom
  • 4 values: top, right, bottom, left

Raises on any other value count.


[View source]
def padding_bottom(n : Int32) : Style #

Sets padding_bottom to n. Returns a new Style


[View source]
def padding_bottom : Int32 #

The padding_bottom value, or 0 when unset.


[View source]
def padding_bottom_set? : Bool #

True when padding_bottom has been explicitly set


def padding_left(n : Int32) : Style #

Sets padding_left to n. Returns a new Style


[View source]
def padding_left : Int32 #

The padding_left value, or 0 when unset.


[View source]
def padding_left_set? : Bool #

True when padding_left has been explicitly set


def padding_right(n : Int32) : Style #

Sets padding_right to n. Returns a new Style


[View source]
def padding_right : Int32 #

The padding_right value, or 0 when unset.


[View source]
def padding_right_set? : Bool #

True when padding_right has been explicitly set


def padding_top(n : Int32) : Style #

Sets padding_top to n. Returns a new Style


[View source]
def padding_top : Int32 #

The padding_top value, or 0 when unset.


[View source]
def padding_top_set? : Bool #

True when padding_top has been explicitly set


def render : String #

Renders strings through this style's rules, each line is styled independently:

  • joined by a space
  • prefixed with any bound #string content
  • wrapped in SGR sequences assembled from current properties
  • with colors resolved and downsampled through the attached renderer's profile
  • width and height truncation is applied last

Zero-arg convenience version that renders this style's bound #string content with no additional arguments.


[View source]
def render(*strings : String) : String #

Renders strings through this style's rules, each line is styled independently:

  • joined by a space
  • prefixed with any bound #string content
  • wrapped in SGR sequences assembled from current properties
  • with colors resolved and downsampled through the attached renderer's profile
  • width and height truncation is applied last

[View source]
def renderer(r : Renderer) : Style #

Rebinds this style to r, is chainable.


[View source]
def renderer : Renderer #

[View source]
def reverse(value : Bool = true) : Style #

Enables or disables reverse. Returns a new Style


[View source]
def reverse? : Bool #

True when reverse is enabled.


[View source]
def reverse_set? : Bool #

True when reverse has been explicitly set


def strikethrough(value : Bool = true) : Style #

Enables or disables strikethrough. Returns a new Style


[View source]
def strikethrough? : Bool #

True when strikethrough is enabled.


[View source]
def strikethrough_set? : Bool #

True when strikethrough has been explicitly set


def strikethrough_spaces(value : Bool = true) : Style #

Enables or disables strikethrough_spaces. Returns a new Style


[View source]
def strikethrough_spaces? : Bool #

True when strikethrough_spaces is enabled.


[View source]
def strikethrough_spaces_set? : Bool #

True when strikethrough_spaces has been explicitly set


def string(*values : String) : Style #

Binds values joined by a space, as this style's underlying content.


[View source]
def tab_width(n : Int32) : Style #

Tab expansion width setter. Use NO_TAB_CONVERSION to leave tabs intact.


[View source]
def tab_width : Int32 #

Tab expansion width getter. Uses TAB_WIDTH_DEFAULT if not otherwise set.


[View source]
def to_s(io : IO) : Nil #

Renders the bound #string content. Writes the result of #render (this style's bound #string content) to io.


[View source]
def transform : Transform | Nil #

[View source]
def transform(&block : String -> String) : Style #

Sets a block applied to the assembled content at render time, before tab expansion or any styling. Returns a new Style.


[View source]
def transform_set? : Bool #

True when transform has been explicitly set


[View source]
def underline(value : Bool = true) : Style #

Enables or disables underline. Returns a new Style


[View source]
def underline? : Bool #

True when underline is enabled.


[View source]
def underline_set? : Bool #

True when underline has been explicitly set


def underline_spaces(value : Bool = true) : Style #

Enables or disables underline_spaces. Returns a new Style


[View source]
def underline_spaces? : Bool #

True when underline_spaces is enabled.


[View source]
def underline_spaces_set? : Bool #

True when underline_spaces has been explicitly set


def unset_align : Style #

Returns a new Style with both alignment axes unset


[View source]
def unset_align_horizontal : Style #

Returns a new Style with align_horizontal returned to the unset (inheritable) state.


def unset_align_vertical : Style #

Returns a new Style with align_vertical returned to the unset (inheritable) state.


def unset_background : Style #

Returns a new Style with background returned to the unset (inheritable) state.


def unset_blink : Style #

Returns a new Style with blink returned to the unset (inheritable) state.


def unset_bold : Style #

Returns a new Style with bold returned to the unset (inheritable) state.


def unset_border_background : Style #

Returns a new Style with all four border background colors unset.


[View source]
def unset_border_bottom : Style #

Returns a new Style with border_bottom returned to the unset (inheritable) state.


def unset_border_bottom_background : Style #

Returns a new Style with border_bottom_background returned to the unset (inheritable) state.


def unset_border_bottom_foreground : Style #

Returns a new Style with border_bottom_foreground returned to the unset (inheritable) state.


def unset_border_foreground : Style #

Returns a new Style with all four border foreground colors unset.


[View source]
def unset_border_left : Style #

Returns a new Style with border_left returned to the unset (inheritable) state.


def unset_border_left_background : Style #

Returns a new Style with border_left_background returned to the unset (inheritable) state.


def unset_border_left_foreground : Style #

Returns a new Style with border_left_foreground returned to the unset (inheritable) state.


def unset_border_right : Style #

Returns a new Style with border_right returned to the unset (inheritable) state.


def unset_border_right_background : Style #

Returns a new Style with border_right_background returned to the unset (inheritable) state.


def unset_border_right_foreground : Style #

Returns a new Style with border_right_foreground returned to the unset (inheritable) state.


def unset_border_style : Style #

Returns a new Style with border_style returned to the unset (inheritable) state.


[View source]
def unset_border_top : Style #

Returns a new Style with border_top returned to the unset (inheritable) state.


def unset_border_top_background : Style #

Returns a new Style with border_top_background returned to the unset (inheritable) state.


def unset_border_top_foreground : Style #

Returns a new Style with border_top_foreground returned to the unset (inheritable) state.


def unset_color_whitespace : Style #

Returns a new Style with color_whitespace returned to the unset (inheritable) state.


def unset_faint : Style #

Returns a new Style with faint returned to the unset (inheritable) state.


def unset_foreground : Style #

Returns a new Style with foreground returned to the unset (inheritable) state.


def unset_height : Style #

Returns a new Style with height returned to the unset (inheritable) state.


def unset_inline : Style #

Returns a new Style with inline returned to the unset (inheritable) state.


def unset_italic : Style #

Returns a new Style with italic returned to the unset (inheritable) state.


def unset_margin_background : Style #

Returns a new Style with margin_background returned to the unset (inheritable) state.


def unset_margin_bottom : Style #

Returns a new Style with margin_bottom returned to the unset (inheritable) state.


def unset_margin_left : Style #

Returns a new Style with margin_left returned to the unset (inheritable) state.


def unset_margin_right : Style #

Returns a new Style with margin_right returned to the unset (inheritable) state.


def unset_margin_top : Style #

Returns a new Style with margin_top returned to the unset (inheritable) state.


def unset_margins : Style #

Returns a new Style with all four margin sides unset


[View source]
def unset_max_height : Style #

Returns a new Style with max_height returned to the unset (inheritable) state.


def unset_max_width : Style #

Returns a new Style with max_width returned to the unset (inheritable) state.


def unset_padding : Style #

Returns a new Style with all four padding sides unset.


[View source]
def unset_padding_bottom : Style #

Returns a new Style with padding_bottom returned to the unset (inheritable) state.


def unset_padding_left : Style #

Returns a new Style with padding_left returned to the unset (inheritable) state.


def unset_padding_right : Style #

Returns a new Style with padding_right returned to the unset (inheritable) state.


def unset_padding_top : Style #

Returns a new Style with padding_top returned to the unset (inheritable) state.


def unset_reverse : Style #

Returns a new Style with reverse returned to the unset (inheritable) state.


def unset_strikethrough : Style #

Returns a new Style with strikethrough returned to the unset (inheritable) state.


def unset_strikethrough_spaces : Style #

Returns a new Style with strikethrough_spaces returned to the unset (inheritable) state.


def unset_string : Style #

Returns a new Style with the bound string value cleared


[View source]
def unset_tab_width : Style #

Returns a new STyle with the tab width returned to its default.


[View source]
def unset_transform : Style #

Returns a new Style with transform returned to the unset (inheritable) state.


[View source]
def unset_underline : Style #

Returns a new Style with underline returned to the unset (inheritable) state.


def unset_underline_spaces : Style #

Returns a new Style with underline_spaces returned to the unset (inheritable) state.


def unset_width : Style #

Returns a new Style with width returned to the unset (inheritable) state.


def value : String #

[View source]
def vertical_border_size : Int32 #

Total vertical border width, top + bottom.


[View source]
def vertical_frame_size : Int32 #

Getter sum of vertical margins, padding, and border.


[View source]
def vertical_margins : Int32 #

Total vertical margins, top + bottom


[View source]
def vertical_padding : Int32 #

Total vertical padding, top + bottom


[View source]
def width(n : Int32) : Style #

Sets width to n. Returns a new Style


[View source]
def width : Int32 #

The width value, or 0 when unset.


[View source]
def width_set? : Bool #

True when width has been explicitly set