Style class Style
Fluent, chainable style builder for terminal output.
All setter methods return this for chaining. Use render to apply
the style to text and produce ANSI-escaped output.
Basic Usage
final style = Style()
.bold()
.foreground(Colors.green)
.render('Success!');
Style Composition
Styles can be composed using inherit, which copies only the explicitly-set properties from another style:
final base = Style().foreground(Colors.white).padding(1);
final accent = Style().bold().foreground(Colors.cyan);
// Inherits bold and foreground from accent, keeps padding from base
final combined = base.copy()..inherit(accent);
Fluent, chainable style builder for CLI output.
Inspired by Go's lipgloss library, this provides a composable way
to build text styles for terminal output.
Artisanal Style uses a fluent, immutable API inspired by Lip Gloss. Each
method call returns a new [Style] instance with the property applied,
allowing for easy composition and reuse.
Styles can include:
- Text effects (bold, italic, underline, strikethrough)
- Colors (foreground, background, underline color)
- Spacing (padding, margin)
- Borders (rounded, thick, double, etc.)
- Alignment (horizontal and vertical)
```dart
final style = Style()
.bold()
.foreground(Colors.green)
.padding(1, 2)
.border(Border.rounded)
.width(40);
print(style.render('Hello World'));
- Available extensions
Constructors
- Style()
- Creates a new empty style.
Properties
- boxMetrics → BoxMetrics
-
Measures the current box model as immutable metrics.
no setter
- colorProfile ↔ ColorProfile
-
getter/setter pair
- data → StyleData
-
Returns an immutable snapshot of the current style state.
no setter
- foregroundColor → Color?
-
Returns the currently configured foreground color, if set.
no setter
- getAlign → HorizontalAlign
-
Gets the horizontal alignment.
no setter
- getAlignHorizontal → HorizontalAlign
-
Gets the horizontal alignment (alias).
no setter
- getAlignVertical → VerticalAlign
-
Gets the vertical alignment.
no setter
- getBackground → Color?
-
Gets the background color if set.
no setter
- getBorder → Border?
-
Gets the border if set.
no setter
- getBorderBackground → Color?
-
Gets the border background color if set.
no setter
- getBorderBottom → bool
-
Gets whether bottom border is visible.
no setter
- getBorderBottomBackground → Color?
-
Gets the bottom border background color if set.
no setter
- getBorderBottomForeground → Color?
-
Gets the bottom border foreground color if set.
no setter
- getBorderForeground → Color?
-
Gets the border foreground color if set.
no setter
-
getBorderForegroundBlend
→ List<
Color> -
Gets the border foreground blend stops, if set.
no setter
- getBorderForegroundBlendOffset → int
-
Gets the border foreground blend offset, if set.
no setter
- getBorderLeft → bool
-
Gets whether left border is visible.
no setter
- getBorderLeftBackground → Color?
-
Gets the left border background color if set.
no setter
- getBorderLeftForeground → Color?
-
Gets the left border foreground color if set.
no setter
- getBorderRight → bool
-
Gets whether right border is visible.
no setter
- getBorderRightBackground → Color?
-
Gets the right border background color if set.
no setter
- getBorderRightForeground → Color?
-
Gets the right border foreground color if set.
no setter
- getBorderSides → BorderSides
-
Gets the border sides.
no setter
- getBorderStyle → Border?
-
Gets the border style (alias for getBorder).
no setter
- getBorderTop → bool
-
Gets whether top border is visible.
no setter
- getBorderTopBackground → Color?
-
Gets the top border background color if set.
no setter
- getBorderTopForeground → Color?
-
Gets the top border foreground color if set.
no setter
- getForeground → Color?
-
Gets the foreground color if set.
no setter
- getFrameSize → ({int height, int width})
-
Gets the frame size (border + padding) as (width, height).
no setter
- getHeight → int
-
Gets the height if set.
no setter
- getHorizontalFrameSize → int
-
Gets the horizontal frame size (border + padding).
no setter
- getHorizontalMargins → int
-
Gets the horizontal margin (left + right).
no setter
- getHorizontalPadding → int
-
Gets the horizontal padding (left + right).
no setter
- getHyperlinkParams → String
-
Gets the hyperlink params if set.
no setter
- getHyperlinkUrl → String?
-
Gets the hyperlink URL if set.
no setter
- getMargin → Margin
-
Gets the margin.
no setter
- getMarginBackground → Color?
-
Gets the margin background color if set.
no setter
- getMarginBottom → int
-
Gets the bottom margin.
no setter
- getMarginChar → String
-
Gets the character used for margins.
no setter
- getMarginLeft → int
-
Gets the left margin.
no setter
- getMarginRight → int
-
Gets the right margin.
no setter
- getMarginTop → int
-
Gets the top margin.
no setter
- getMaxHeight → int
-
Gets the max height if set.
no setter
- getMaxWidth → int
-
Gets the max width if set.
no setter
- getPadding → Padding
-
Gets the padding.
no setter
- getPaddingBottom → int
-
Gets the bottom padding.
no setter
- getPaddingChar → String
-
Gets the character used for padding.
no setter
- getPaddingLeft → int
-
Gets the left padding.
no setter
- getPaddingRight → int
-
Gets the right padding.
no setter
- getPaddingTop → int
-
Gets the top padding.
no setter
- getStrikethroughSpaces → bool
-
Gets whether spaces have strikethrough.
no setter
- getTabWidth → int
-
Gets the tab width.
no setter
- getTransform → String Function(String)?
-
Gets the transform function if set.
no setter
- getUnderlineColor → Color?
-
Gets the underline color if set.
no setter
- getUnderlineSpaces → bool
-
Gets whether spaces are underlined.
no setter
- getUnderlineStyle → UnderlineStyle
-
Gets the underline style variant.
no setter
- getValue → String?
-
Gets the pre-set string value if set.
no setter
- getVerticalFrameSize → int
-
Gets the vertical frame size (border + padding).
no setter
- getVerticalMargins → int
-
Gets the vertical margin (top + bottom).
no setter
- getVerticalPadding → int
-
Gets the vertical padding (top + bottom).
no setter
- getWidth → int
-
Gets the width if set.
no setter
- hasColors → bool
-
Whether any color is set.
no setter
- hasDarkBackground ↔ bool
-
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasHyperlink → bool
-
Whether a hyperlink is explicitly set.
no setter
- hasSpacing → bool
-
Whether any spacing (padding or margin) is set.
no setter
- hasTextAttributes → bool
-
Whether any text attribute is set.
no setter
- isBlink → bool
-
Whether blink is explicitly set.
no setter
- isBold → bool
-
Whether bold is explicitly set.
no setter
- isDim → bool
-
Whether dim is explicitly set.
no setter
- isEmpty → bool
-
Whether this style has no active properties.
no setter
- isInline → bool
-
Whether inline mode is set.
no setter
- isInverse → bool
-
Whether inverse is explicitly set.
no setter
- isItalic → bool
-
Whether italic is explicitly set.
no setter
- isStrikethrough → bool
-
Whether strikethrough is explicitly set.
no setter
- isStrikethroughSpaces → bool
-
Whether strikethrough spaces is set.
no setter
- isUnderline → bool
-
Whether underline is explicitly set.
no setter
- isUnderlineSpaces → bool
-
Whether underline spaces is set.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → String?
-
Gets the pre-set string value.
no setter
Methods
-
align(
HorizontalAlign horizontal, [VerticalAlign? vertical]) → Style - Sets horizontal text alignment, optionally with vertical alignment.
-
alignBottom(
) → Style - Aligns text to the bottom.
-
alignCenter(
) → Style - Aligns text to the center horizontally.
-
alignHorizontal(
HorizontalAlign value) → Style - Sets horizontal text alignment (alias for align).
-
alignLeft(
) → Style - Aligns text to the left.
-
alignMiddle(
) → Style - Aligns text to the center vertically.
-
alignRight(
) → Style - Aligns text to the right.
-
alignTop(
) → Style - Aligns text to the top.
-
alignVertical(
VerticalAlign value) → Style - Sets vertical text alignment within the height.
-
background(
Color color) → Style - Sets the background color.
-
blink(
[bool value = true]) → Style - Sets blinking text (limited terminal support).
-
bold(
[bool value = true]) → Style - Sets bold text.
-
border(
Border value, {bool? top, bool? right, bool? bottom, bool? left}) → Style - Sets the border style, optionally specifying which sides are visible.
-
borderBackground(
Color color) → Style - Sets the border background color.
-
borderBottom(
bool visible) → Style - Shows or hides the bottom border.
-
borderBottomBackground(
Color color) → Style - Sets the bottom border background color.
-
borderBottomForeground(
Color color) → Style - Sets the bottom border foreground color.
-
borderForeground(
Color color) → Style - Sets the border foreground color.
-
borderForegroundBlend(
List< Color> colors) → Style - Sets a foreground color gradient for the border.
-
borderForegroundBlendOffset(
int value) → Style - Sets the border blend offset (in cells along the perimeter).
-
borderLeft(
bool visible) → Style - Shows or hides the left border.
-
borderLeftBackground(
Color color) → Style - Sets the left border background color.
-
borderLeftForeground(
Color color) → Style - Sets the left border foreground color.
-
borderRight(
bool visible) → Style - Shows or hides the right border.
-
borderRightBackground(
Color color) → Style - Sets the right border background color.
-
borderRightForeground(
Color color) → Style - Sets the right border foreground color.
-
borderSides(
BorderSides value) → Style - Sets which border sides are visible.
-
borderStyle(
Border value) → Style - Alias for setting border style only (without changing sides).
-
borderTop(
bool visible) → Style - Shows or hides the top border.
-
borderTopBackground(
Color color) → Style - Sets the top border background color.
-
borderTopForeground(
Color color) → Style - Sets the top border foreground color.
-
colorWhitespace(
[bool value = true]) → Style - Sets whether to color whitespace outside the core text (padding/alignment).
-
copy(
) → Style - Creates a copy of this style.
-
dim(
[bool value = true]) → Style - Sets dimmed/faint text.
-
emphasize(
Object? text) → String -
Available on Style, provided by the StyleConvenienceExtensions extension
Renders text with bold formatting. -
error(
Object? text) → String -
Available on Style, provided by the StyleConvenienceExtensions extension
Renders text with the error color. -
faint(
[bool value = true]) → Style - Alias for dim.
-
foreground(
Color color) → Style - Sets the foreground (text) color.
-
hasProperty(
int flag) → bool - Whether a specific property flag is set.
-
height(
int value) → Style - Sets the fixed height of the styled content.
-
hyperlink(
String url, {String params = ''}) → Style - Adds an OSC 8 hyperlink around rendered output.
-
info(
Object? text) → String -
Available on Style, provided by the StyleConvenienceExtensions extension
Renders text with the info color. -
inherit(
Style other) → Style - Inherits explicitly-set properties from another style.
-
inline(
[bool value = true]) → Style - Sets inline mode (ignores padding, margin, border).
-
inverse(
[bool value = true]) → Style - Sets inverse/reverse video.
-
italic(
[bool value = true]) → Style - Sets italic text.
-
margin(
int topOrAll, [int? right, int? bottom, int? left]) → Style - Sets margin on all sides or vertical/horizontal.
-
marginBackground(
Color color) → Style - Sets the background color for margin areas.
-
marginBottom(
int value) → Style - Sets bottom margin.
-
marginChar(
String char) → Style - Sets the character used for margins.
-
marginLeft(
int value) → Style - Sets left margin.
-
marginRight(
int value) → Style - Sets right margin.
-
marginTop(
int value) → Style - Sets top margin.
-
maxHeight(
int value) → Style - Sets the maximum height of the styled content.
-
maxWidth(
int value) → Style - Sets the maximum width of the styled content.
-
muted(
Object? text) → String -
Available on Style, provided by the StyleConvenienceExtensions extension
Renders text with the muted color. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
padding(
int topOrAll, [int? right, int? bottom, int? left]) → Style - Sets padding on all sides or vertical/horizontal.
-
paddingBottom(
int value) → Style - Sets bottom padding.
-
paddingChar(
String char) → Style - Sets the character used for padding.
-
paddingLeft(
int value) → Style - Sets left padding.
-
paddingRight(
int value) → Style - Sets right padding.
-
paddingTop(
int value) → Style - Sets top padding.
-
render(
[Object? text]) → String - Renders the given text with this style applied.
-
renderTo(
Renderer renderer, [Object? text]) → String -
Renders the given text using the settings from the provided
renderer. -
renderWithContext(
Object? text, RenderContext context) → String - Renders the given text with an explicit render context.
-
reverse(
[bool value = true]) → Style - Alias for inverse.
-
setString(
Object? value) → Style - Sets a pre-defined string content for this style.
-
strikethrough(
[bool value = true]) → Style - Sets strikethrough text.
-
strikethroughSpaces(
[bool value = true]) → Style - Sets whether spaces should have strikethrough.
-
success(
Object? text) → String -
Available on Style, provided by the StyleConvenienceExtensions extension
Renders text with the success color. -
tabWidth(
int width) → Style - Sets the tab width for tab character handling.
-
toString(
) → String -
A string representation of this object.
override
-
transform(
String fn(String)) → Style - Sets a text transformation function.
-
underline(
[bool value = true]) → Style - Sets underlined text.
-
underlineColor(
Color color) → Style - Sets the underline color.
-
underlineSpaces(
[bool value = true]) → Style - Sets whether spaces should be underlined.
-
underlineStyle(
UnderlineStyle style) → Style - Sets the underline style variant.
-
unsetAlign(
) → Style - Removes alignment.
-
unsetAlignHorizontal(
) → Style - Unsets horizontal alignment.
-
unsetAlignVertical(
) → Style - Unsets vertical alignment.
-
unsetBackground(
) → Style - Removes background color.
-
unsetBlink(
) → Style - Removes blink styling.
-
unsetBold(
) → Style - Removes bold styling.
-
unsetBorder(
) → Style - Unsets border.
-
unsetBorderBackground(
) → Style - Unsets border background color.
-
unsetBorderBottom(
) → Style - Unsets bottom border visibility.
-
unsetBorderForeground(
) → Style - Unsets border foreground color.
-
unsetBorderLeft(
) → Style - Unsets left border visibility.
-
unsetBorderRight(
) → Style - Unsets right border visibility.
-
unsetBorderTop(
) → Style - Unsets top border visibility.
-
unsetDim(
) → Style - Removes dimmed styling.
-
unsetFaint(
) → Style - Alias for unsetDim.
-
unsetForeground(
) → Style - Removes foreground color.
-
unsetHeight(
) → Style - Removes height constraint.
-
unsetHyperlink(
) → Style - Removes hyperlink styling.
-
unsetInline(
) → Style - Unsets inline mode.
-
unsetInverse(
) → Style - Removes inverse styling.
-
unsetItalic(
) → Style - Removes italic styling.
-
unsetMargin(
) → Style - Unsets margin.
-
unsetMarginBackground(
) → Style - Unsets margin background color.
-
unsetMarginBottom(
) → Style - Unsets margin bottom.
-
unsetMarginChar(
) → Style - Removes margin character.
-
unsetMarginLeft(
) → Style - Unsets margin left.
-
unsetMarginRight(
) → Style - Unsets margin right.
-
unsetMarginTop(
) → Style - Unsets margin top.
-
unsetMaxHeight(
) → Style - Unsets max height.
-
unsetMaxWidth(
) → Style - Unsets max width.
-
unsetPadding(
) → Style - Removes padding.
-
unsetPaddingBottom(
) → Style - Unsets padding bottom.
-
unsetPaddingChar(
) → Style - Removes padding character.
-
unsetPaddingLeft(
) → Style - Unsets padding left.
-
unsetPaddingRight(
) → Style - Unsets padding right.
-
unsetPaddingTop(
) → Style - Unsets padding top.
-
unsetReverse(
) → Style - Alias for unsetInverse.
-
unsetStrikethrough(
) → Style - Removes strikethrough styling.
-
unsetStrikethroughSpaces(
) → Style - Unsets strikethrough spaces.
-
unsetString(
) → Style - Unsets the pre-set string value.
-
unsetTabWidth(
) → Style - Unsets tab width.
-
unsetTransform(
) → Style - Unsets transform.
-
unsetUnderline(
) → Style - Removes underline styling.
-
unsetUnderlineColor(
) → Style - Removes underline color.
-
unsetUnderlineSpaces(
) → Style - Unsets underline spaces.
-
unsetWhitespaceChars(
) → Style - Removes custom whitespace characters.
-
unsetWhitespaceForeground(
) → Style - Removes whitespace foreground styling.
-
unsetWidth(
) → Style - Removes width constraint.
-
warning(
Object? text) → String -
Available on Style, provided by the StyleConvenienceExtensions extension
Renders text with the warning color. -
whitespaceChars(
String chars) → Style - Sets custom character(s) for whitespace fill.
-
whitespaceForeground(
Color color) → Style - Sets the foreground color for whitespace fill.
-
width(
int value) → Style - Sets the fixed width of the styled content.
-
wrapAnsi(
[bool value = true]) → Style - Sets whether to use ANSI-preserving wrapping.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
stack(
List< String> blocks) → String - Stacks multiple blocks of text on top of each other.
-
stripAnsi(
String text) → String - Strips ANSI escape sequences from a string.
-
styleRunes(
String str, Iterable< int> indices, Style matched, Style unmatched) → String - Applies one of two styles to runes at specific rune indices.
-
visibleLength(
String text) → int - Gets the visible length of a string (ignoring ANSI codes).