module Sheen

Defined in:

sheen.cr
sheen/background.cr
sheen/border.cr
sheen/border_painter.cr
sheen/color.cr
sheen/composition.cr
sheen/list.cr
sheen/position.cr
sheen/ranges.cr
sheen/renderer.cr
sheen/style.cr
sheen/style_painter.cr
sheen/table.cr
sheen/table_painter.cr
sheen/table_resizer.cr
sheen/tree.cr
sheen/tree_painter.cr

Constant Summary

BLACK = ANSIColor.new(0)
BLUE = ANSIColor.new(4)
BRIGHT_BLACK = ANSIColor.new(8)
BRIGHT_BLUE = ANSIColor.new(12)
BRIGHT_CYAN = ANSIColor.new(14)
BRIGHT_GREEN = ANSIColor.new(10)
BRIGHT_MAGENTA = ANSIColor.new(13)
BRIGHT_RED = ANSIColor.new(9)
BRIGHT_WHITE = ANSIColor.new(15)
BRIGHT_YELLOW = ANSIColor.new(11)
BUILD_DATE = {{ (`date +%F`).stringify.chomp }}
BUILD_HASH = {{ (`git rev-parse HEAD`).stringify[0...8] }}
CYAN = ANSIColor.new(6)
GREEN = ANSIColor.new(2)
MAGENTA = ANSIColor.new(5)
RED = ANSIColor.new(1)
VERSION = {{ (`shards version /srv/crystaldoc.info/github-lowkeyliesmyth-sheen-v0.1.2/src/..`).stringify.chomp }}
WHITE = ANSIColor.new(7)
YELLOW = ANSIColor.new(3)

Class Method Summary

Class Method Detail

def self.color(value : TerminalColor) : TerminalColor #

Builds a TerminalColor from a hex string, an index string, an integer index, or an existing color returned as-is.


[View source]
def self.color(value : String) : TerminalColor #

Builds a TerminalColor from a hex string, an index string, an integer index, or an existing color returned as-is.


[View source]
def self.color(value : Int) : TerminalColor #

Builds a TerminalColor from a hex string, an index string, an integer index, or an existing color returned as-is.


[View source]
def self.has_dark_background?(input : IO = STDIN, output : IO = STDOUT, env : Foundation::Env = Foundation::LiveEnv.new) : Bool #

Reports whether the terminal renders on a dark background, so that AdaptiveColor and CompleteAdaptiveColor can pick the correct light or dark variant.

Detection is env-first and TTY-safe:

  1. COLORFGBG(a fg;bg pair of ANSI indices)
  2. An OSC11 background query written to output and read from input only when both are real TTYs
  3. Fallback to Dark (default black background) when nothing else answers

[View source]
def self.height(string : String) : Int32 #

Height of string in lines: one more than its newline count.


[View source]
def self.join_horizontal(pos : Position, strings : Enumerable(String)) : String #

Joins the strings collection (eg table row cells) left to right, aligning blocks of differing height along the vertical axis at pos (0.0=top, 0.5=center, 1.0=bottom, or any float in between). Each block's lines are padded to its own widest line so columns stay aligned.


[View source]
def self.join_horizontal(pos : Position, *strings : String) : String #

Joins strings left to right. Variadic form that delegates to the collection form.


[View source]
def self.join_vertical(pos : Position, strings : Enumerable(String)) : String #

Joins strings collection top to bottom, aligning lines of differing width along the horizontal axis at pos (0.0=left, 0.5=center, 1.0=right, or any float in between). All lines are padded to the widest line across every block.


[View source]
def self.join_vertical(pos : Position, *strings : String) : String #

Joins strings top to bottom. Variadic form that delegates to the collection form.


[View source]
def self.place(width : Int32, height : Int32, h_pos : Position, v_pos : Position, string : String, *, ws_chars : String = " ", ws_foreground : TerminalColor | Nil = nil, ws_background : TerminalColor | Nil = nil, renderer : Renderer = Sheen.renderer) : String #

Places string inside a box of width x height, aligning it at h_pos horizontally and v_pos vertically. Extra space is filled with whitespace which can be styled via the ws_* keyword options.

If width or height is not larger than string's own width or height, that axis is left unchanged.


[View source]
def self.place_horizontal(width : Int32, pos : Position, string : String, *, ws_chars : String = " ", ws_foreground : TerminalColor | Nil = nil, ws_background : TerminalColor | Nil = nil, renderer : Renderer = Sheen.renderer) : String #

Places string horizontally in a box of width at pos (0.0=left ... 1.0=right). Each line pads to fill up the full width, but if width <= the widest line then no change is applied.


[View source]
def self.place_vertical(height : Int32, pos : Position, string : String, *, ws_chars : String = " ", ws_foreground : TerminalColor | Nil = nil, ws_background : TerminalColor | Nil = nil, renderer : Renderer = Sheen.renderer) : String #

Places string vertically in a box of height at pos (0.0=top ... 1.0=bottom). Blank lines fill up the the full block width. If height <= the string's line count then no change is applied.


[View source]
def self.renderer : Renderer #

Process-global default renderer. Configure it directly, eg Sheen.renderer.color_profile = Foundation::Profile::TrueColor.

Or replace it wholesale: Sheen.renderer = Sheen::Renderer.new(io)


[View source]
def self.renderer=(renderer : Renderer) #

Process-global default renderer. Configure it directly, eg Sheen.renderer.color_profile = Foundation::Profile::TrueColor.

Or replace it wholesale: Sheen.renderer = Sheen::Renderer.new(io)


[View source]
def self.resolve_value(value : String, profile : Foundation::Profile) : Foundation::SGRColor | Nil #

Helper shared by color types. Resolves a color value hex or index string against profile.

Returns nil for empty/invalid value or a colorless profile.


[View source]
def self.size(string : String) : Tuple(Int32, Int32) #

The {width, height} of string in cells


[View source]
def self.style(renderer : Renderer = Sheen.renderer, & : Style::Builder -> ) : Style #

Builds a Style imperatively. Yields a mutable builder and returns the resulting immutable Style.

Sheen.style { |s| s.bold; s.foreground("#FF0000") }.


[View source]
def self.style_ranges(str : String, ranges : Array(StyleRange)) : String #

Styles visible-cell ranges of str, preserving any existing styling as-is in the gaps between ranges. Ranges must be ordered and not overlap.

Each range has its text stripped of ANSI sequences, leaving only a printable content string.


[View source]
def self.style_ranges(str : String, *ranges : StyleRange) : String #

Styles visible-cell ranges of str, preserving any existing styling as-is in the gaps between ranges. Ranges must be ordered and not overlap.

Each range has its text stripped of ANSI sequences, leaving only a printable content string.

Splat convenience version: Sheen.style.ranges(str, r1, r2). Requires at least one range. Use the array overload version for any possible empty case.


[View source]
def self.style_runes(str : String, indices : Enumerable(Int32), matched : Style, unmatched : Style) : String #

Applies matched Style to the runes of str at the given indices. The rest of the runes get the unmatched Style applied. Each run of same-status runes are rendered as one styled group.

Note that runes are Unicode codepoints and not grapheme clusters. Indices out of bounds are ignored. Returns the reassembled and fully styled string.


[View source]
def self.width(string : String) : Int32 #

Visible cell width of the widest line in string (ANSI-aware, grapheme based).


[View source]