package lipgloss

Import Path
	charm.land/lipgloss/v2 (on go.dev)

Dependency Relation
	imports 23 packages, and imported by 3 packages

Involved Source Files align.go ansi_unix.go blending.go borders.go canvas.go color.go get.go join.go layer.go Package lipgloss provides style definitions for nice terminal layouts. Built with TUIs in mind. position.go query.go ranges.go runes.go set.go size.go style.go terminal.go unset.go whitespace.go wrap.go writer.go
Package-Level Type Names (total 22, in which 16 are exported)
/* sort exporteds by: | */
ANSIColor is a color specified by an ANSI256 color value. Example usage: colorA := lipgloss.ANSIColor(8) colorB := lipgloss.ANSIColor(134)
Border contains a series of values which comprise the various parts of a border. Bottom string BottomLeft string BottomRight string Left string Middle string MiddleBottom string MiddleLeft string MiddleRight string MiddleTop string Right string Top string TopLeft string TopRight string GetBottomSize returns the width of the bottom border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the bottom edge, 0 is returned. GetLeftSize returns the width of the left border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the left edge, 0 is returned. GetRightSize returns the width of the right border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the right edge, 0 is returned. GetTopSize returns the width of the top border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the top edge, 0 is returned. func ASCIIBorder() Border func BlockBorder() Border func DoubleBorder() Border func HiddenBorder() Border func InnerHalfBlockBorder() Border func MarkdownBorder() Border func NormalBorder() Border func OuterHalfBlockBorder() Border func RoundedBorder() Border func ThickBorder() Border func Style.GetBorder() (b Border, top, right, bottom, left bool) func Style.GetBorderStyle() Border func Style.Border(b Border, sides ...bool) Style func Style.BorderStyle(b Border) Style func charm.land/lipgloss/v2/table.(*Table).Border(border Border) *table.Table
Canvas is a cell-buffer that can be used to compose and draw [uv.Drawable]s like [Layer]s. Composed drawables are drawn onto the canvas in the order they were composed, meaning later drawables will appear "on top" of earlier ones. A canvas can read, modify, and render its cell contents. It implements [uv.Screen] and [uv.Drawable]. Bounds implements [uv.Screen]. CellAt implements [uv.Screen]. Clear clears the canvas. Compose composes a [Layer] or any [uv.Drawable] onto the [Canvas]. Draw draws the [Canvas] onto the given [uv.Screen] within the specified area. It implements [uv.Drawable]. Height returns the height of the canvas. Render renders the canvas into a styled string. Any trailing spaces are trimmed. Resize resizes the canvas to the given width and height. SetCell implements [uv.Screen]. Width returns the width of the canvas. WidthMethod implements [uv.Screen]. *Canvas : github.com/charmbracelet/ultraviolet.Drawable *Canvas : github.com/charmbracelet/ultraviolet.Screen func NewCanvas(width, height int) *Canvas func (*Canvas).Compose(drawer uv.Drawable) *Canvas
CompleteFunc is a function that returns the appropriate color based on the given color profile. Example usage: p := colorprofile.Detect(os.Stderr, os.Environ()) complete := lipgloss.Complete(p) color := complete( lipgloss.Color(1), // ANSI lipgloss.Color(124), // ANSI256 lipgloss.Color("#ff34ac"), // TrueColor ) fmt.Println("Ooh, pretty color: ", color) For more info see [Complete]. func Complete(p colorprofile.Profile) CompleteFunc
Compositor manages the composition of layers. It flattens a layer hierarchy once and provides efficient drawing and hit testing operations. All computation related to layers happens in the Compositor. AddLayers adds layers to the compositor's root and refreshes the internal state. Bounds returns the overall bounds of all layers in the compositor. Draw draws all layers onto the given [uv.Screen] in z-index order. GetLayer returns a layer by its ID, or nil if not found. Layers with empty IDs are not indexed and cannot be retrieved. Hit performs a hit test at the given (x, y) coordinates. If a layer is hit, it returns the ID of the top-most layer at that point. Layers with empty IDs are ignored. If no layer is hit, it returns an empty [LayerHit]. Refresh re-flattens the layer hierarchy. Call this after modifying the layer tree structure or positions to update the compositor's internal state. Render renders the compositor into a styled string. This is a helper function that creates a temporary canvas, draws the compositor onto it, and returns the resulting string. *Compositor : github.com/charmbracelet/ultraviolet.Drawable func NewCompositor(layers ...*Layer) *Compositor func (*Compositor).AddLayers(layers ...*Layer) *Compositor
Layer represents a visual layer with content and positioning. It's a pure data structure that defines the layer hierarchy without any computation. AddLayers adds child layers to the Layer. Draw draws the content of the layer on the screen at the specified area. GetContent returns the content of the Layer. GetID returns the ID of the Layer. GetLayer returns a descendant layer by its ID, or nil if not found. Layers with empty IDs are skipped. GetX returns the x-coordinate of the Layer relative to its parent. GetY returns the y-coordinate of the Layer relative to its parent. GetZ returns the z-index of the Layer relative to its parent. Height returns the height of the Layer. ID sets the ID of the Layer. MaxZ returns the maximum z-index among this layer and all its descendants. Width returns the width of the Layer. X sets the x-coordinate of the Layer relative to its parent. Y sets the y-coordinate of the Layer relative to its parent. Z sets the z-index of the Layer relative to its parent. *Layer : github.com/charmbracelet/ultraviolet.Drawable func NewLayer(content string, layers ...*Layer) *Layer func (*Compositor).GetLayer(id string) *Layer func (*Layer).AddLayers(layers ...*Layer) *Layer func (*Layer).GetLayer(id string) *Layer func (*Layer).ID(id string) *Layer func (*Layer).X(x int) *Layer func (*Layer).Y(y int) *Layer func (*Layer).Z(z int) *Layer func LayerHit.Layer() *Layer func NewCompositor(layers ...*Layer) *Compositor func NewLayer(content string, layers ...*Layer) *Layer func (*Compositor).AddLayers(layers ...*Layer) *Compositor func (*Layer).AddLayers(layers ...*Layer) *Layer
LayerHit represents the result of a hit test on a [Layer]. Bounds returns the bounds of the LayerHit. Empty returns true if the LayerHit represents no hit. ID returns the ID of the hit Layer. Layer returns the layer that was hit. func (*Compositor).Hit(x, y int) LayerHit
LightDarkFunc is a function that returns a color based on whether the terminal has a light or dark background. You can create one of these with [LightDark]. Example: lightDark := lipgloss.LightDark(hasDarkBackground) red, blue := lipgloss.Color("#ff0000"), lipgloss.Color("#0000ff") myHotColor := lightDark(red, blue) For more info see [LightDark]. func LightDark(isDark bool) LightDarkFunc
NoColor is used to specify the absence of color styling. When this is active foreground colors will be rendered with the terminal's default text color, and background colors will not be drawn at all. Example usage: var style = someStyle.Background(lipgloss.NoColor{}) RGBA returns the RGBA value of this color. Because we have to return something, despite this color being the absence of color, we're returning black with 100% opacity. Red: 0x0, Green: 0x0, Blue: 0x0, Alpha: 0xFFFF. NoColor : github.com/charmbracelet/x/ansi.Color NoColor : image/color.Color
Position represents a position along a horizontal or vertical axis. It's in situations where an axis is involved, like alignment, joining, placement and so on. A value of 0 represents the start (the left or top) and 1 represents the end (the right or bottom). 0.5 represents the center. There are constants Top, Bottom, Center, Left and Right in this package that can be used to aid readability. func Style.GetAlign() Position func Style.GetAlignHorizontal() Position func Style.GetAlignVertical() Position func JoinHorizontal(pos Position, strs ...string) string func JoinVertical(pos Position, strs ...string) string func Place(width, height int, hPos, vPos Position, str string, opts ...WhitespaceOption) string func PlaceHorizontal(width int, pos Position, str string, opts ...WhitespaceOption) string func PlaceVertical(height int, pos Position, str string, opts ...WhitespaceOption) string func Style.Align(p ...Position) Style func Style.AlignHorizontal(p Position) Style func Style.AlignVertical(p Position) Style const Bottom const Center const Left const Right const Top
Range is a range of text and associated styling to be used with [StyleRanges]. End int Start int Style Style func NewRange(start, end int, style Style) Range func StyleRanges(s string, ranges ...Range) string
RGBColor is a color specified by red, green, and blue values. B uint8 G uint8 R uint8 RGBA returns the RGBA value of this color. This satisfies the Go Color interface. RGBColor : github.com/charmbracelet/x/ansi.Color RGBColor : image/color.Color
Style contains a set of rules that comprise a style as a whole. Align is a shorthand method for setting horizontal and vertical alignment. With one argument, the position value is applied to the horizontal alignment. With two arguments, the value is applied to the horizontal and vertical alignments, in that order. AlignHorizontal sets a horizontal text alignment rule. AlignVertical sets a vertical text alignment rule. Background sets a background color. Blink sets a rule for blinking foreground text. Bold sets a bold formatting rule. Border is shorthand for setting the border style and which sides should have a border at once. The variadic argument sides works as follows: With one value, the value is applied to all sides. With two values, the values are applied to the vertical and horizontal sides, in that order. With three values, the values are applied to the top side, the horizontal sides, and the bottom side, in that order. With four values, the values are applied clockwise starting from the top side, followed by the right side, then the bottom, and finally the left. With more than four arguments the border will be applied to all sides. Examples: // Applies borders to the top and bottom only lipgloss.NewStyle().Border(lipgloss.NormalBorder(), true, false) // Applies rounded borders to the right and bottom only lipgloss.NewStyle().Border(lipgloss.RoundedBorder(), false, true, true, false) BorderBackground is a shorthand function for setting all of the background colors of the borders at once. The arguments work as follows: With one argument, the argument is applied to all sides. With two arguments, the arguments are applied to the vertical and horizontal sides, in that order. With three arguments, the arguments are applied to the top side, the horizontal sides, and the bottom side, in that order. With four arguments, the arguments are applied clockwise starting from the top side, followed by the right side, then the bottom, and finally the left. With more than four arguments nothing will be set. BorderBottom determines whether or not to draw a bottom border. BorderBottomBackground sets the background color of the bottom of the border. BorderBottomForeground sets the foreground color for the bottom of the border. BorderForeground is a shorthand function for setting all of the foreground colors of the borders at once. The arguments work as follows: With one argument, the argument is applied to all sides. With two arguments, the arguments are applied to the vertical and horizontal sides, in that order. With three arguments, the arguments are applied to the top side, the horizontal sides, and the bottom side, in that order. With four arguments, the arguments are applied clockwise starting from the top side, followed by the right side, then the bottom, and finally the left. With more than four arguments nothing will be set. BorderForegroundBlend sets the foreground colors for the border blend. At least 2 colors are required to use blending, otherwise this will no-op with 0 colors, and pass to BorderForeground with 1 color. This will override all other border foreground colors when used. When providing colors, in most cases (e.g. when all border sides are enabled), you will want to provide a wrapping-set of colors, so the start and end color are either the same, or very similar. For example: lipgloss.NewStyle().BorderForegroundBlend( lipgloss.Color("#00FA68"), lipgloss.Color("#9900FF"), lipgloss.Color("#ED5353"), lipgloss.Color("#9900FF"), lipgloss.Color("#00FA68"), ) BorderForegroundBlendOffset sets the border blend offset cells, starting from the top left corner. Value can be positive or negative, and does not need to equal the dimensions of the border region. Direction (when positive) is as follows ("o" is starting point): o --------> ┌──────────┐ ^ │ │ | | │ │ | | │ │ | | │ │ v └──────────┘ <--------- BorderLeft determines whether or not to draw a left border. BorderLeftBackground set the background color of the left side of the border. BorderLeftForeground sets the foreground color for the left side of the border. BorderRight determines whether or not to draw a right border. BorderRightBackground sets the background color of right side the border. BorderRightForeground sets the foreground color for the right side of the border. BorderStyle defines the Border on a style. A Border contains a series of definitions for the sides and corners of a border. Note that if border visibility has not been set for any sides when setting the border style, the border will be enabled for all sides during rendering. You can define border characters as you'd like, though several default styles are included: NormalBorder(), RoundedBorder(), BlockBorder(), OuterHalfBlockBorder(), InnerHalfBlockBorder(), ThickBorder(), and DoubleBorder(). Example: lipgloss.NewStyle().BorderStyle(lipgloss.ThickBorder()) BorderTop determines whether or not to draw a top border. BorderTopBackground sets the background color of the top of the border. BorderTopForeground set the foreground color for the top of the border. ColorWhitespace determines whether or not the background color should be applied to the padding. This is true by default as it's more than likely the desired and expected behavior, but it can be disabled for certain graphic effects. Deprecated: Just use margins and padding. Copy returns a copy of this style, including any underlying string values. Deprecated: to copy just use assignment (i.e. a := b). All methods also return a new style. Faint sets a rule for rendering the foreground color in a dimmer shade. Foreground sets a foreground color. // Sets the foreground to blue s := lipgloss.NewStyle().Foreground(lipgloss.Color("#0000ff")) // Removes the foreground color s.Foreground(lipgloss.NoColor) GetAlign returns the style's implicit horizontal alignment setting. If no alignment is set Position.Left is returned. GetAlignHorizontal returns the style's implicit horizontal alignment setting. If no alignment is set Position.Left is returned. GetAlignVertical returns the style's implicit vertical alignment setting. If no alignment is set Position.Top is returned. GetBackground returns the style's background color. If no value is set NoColor{} is returned. GetBlink returns the style's blink value. If no value is set false is returned. GetBold returns the style's bold value. If no value is set false is returned. GetBorder returns the style's border style (type Border) and value for the top, right, bottom, and left in that order. If no value is set for the border style, Border{} is returned. For all other unset values false is returned. GetBorderBottom returns the style's bottom border setting. If no value is set false is returned. GetBorderBottomBackground returns the style's border bottom background color. If no value is set NoColor{} is returned. GetBorderBottomForeground returns the style's border bottom foreground color. If no value is set NoColor{} is returned. GetBorderBottomSize returns the width of the bottom border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the left edge, 0 is returned. GetBorderForegroundBlend returns the style's border blend foreground colors. If no value is set, nil is returned. GetBorderForegroundBlendOffset returns the style's border blend offset. If no value is set, 0 is returned. GetBorderLeft returns the style's left border setting. If no value is set false is returned. GetBorderLeftBackground returns the style's border left background color. If no value is set NoColor{} is returned. GetBorderLeftForeground returns the style's border left foreground color. If no value is set NoColor{} is returned. GetBorderLeftSize returns the width of the left border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the left edge, 0 is returned. GetBorderRight returns the style's right border setting. If no value is set false is returned. GetBorderRightBackground returns the style's border right background color. If no value is set NoColor{} is returned. GetBorderRightForeground returns the style's border right foreground color. If no value is set NoColor{} is returned. GetBorderRightSize returns the width of the right border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the right edge, 0 is returned. GetBorderStyle returns the style's border style (type Border). If no value is set Border{} is returned. GetBorderTop returns the style's top border setting. If no value is set false is returned. GetBorderTopBackground returns the style's border top background color. If no value is set NoColor{} is returned. GetBorderTopForeground returns the style's border top foreground color. If no value is set NoColor{} is returned. GetBorderTopSize returns the width of the top border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the top edge, 0 is returned. GetBorderTopWidth returns the width of the top border. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the top edge, 0 is returned. Deprecated: This function simply calls Style.GetBorderTopSize. GetColorWhitespace returns the style's whitespace coloring setting. If no value is set false is returned. GetFaint returns the style's faint value. If no value is set false is returned. GetForeground returns the style's foreground color. If no value is set NoColor{} is returned. GetFrameSize returns the sum of the margins, padding and border width for both the horizontal and vertical margins. GetHeight returns the style's height setting. If no height is set 0 is returned. GetHorizontalBorderSize returns the width of the horizontal borders. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the horizontal edges, 0 is returned. GetHorizontalFrameSize returns the sum of the style's horizontal margins, padding and border widths. Provisional: this method may be renamed. GetHorizontalMargins returns the style's left and right margins. Unset values are measured as 0. GetHorizontalPadding returns the style's left and right padding. Unset values are measured as 0. GetHyperlink returns the hyperlink along with its parameters. If no hyperlink is set, empty strings are returned. GetInline returns the style's inline setting. If no value is set false is returned. GetItalic returns the style's italic value. If no value is set false is returned. GetMargin returns the style's top, right, bottom, and left margins, in that order. 0 is returned for unset values. GetMarginBottom returns the style's bottom margin. If no value is set 0 is returned. GetMarginChar returns the style's padding character. If no value is set a space is returned. GetMarginLeft returns the style's left margin. If no value is set 0 is returned. GetMarginRight returns the style's right margin. If no value is set 0 is returned. GetMarginTop returns the style's top margin. If no value is set 0 is returned. GetMaxHeight returns the style's max height setting. If no value is set 0 is returned. GetMaxWidth returns the style's max width setting. If no value is set 0 is returned. GetPadding returns the style's top, right, bottom, and left padding values, in that order. 0 is returned for unset values. GetPaddingBottom returns the style's bottom padding. If no value is set 0 is returned. GetPaddingChar returns the style's padding character. If no value is set a space is returned. GetPaddingLeft returns the style's left padding. If no value is set 0 is returned. GetPaddingRight returns the style's right padding. If no value is set 0 is returned. GetPaddingTop returns the style's top padding. If no value is set 0 is returned. GetReverse returns the style's reverse value. If no value is set false is returned. GetStrikethrough returns the style's strikethrough value. If no value is set false is returned. GetStrikethroughSpaces returns whether or not the style is set to strikethrough spaces. If not value is set false is returned. GetTabWidth returns the style's tab width setting. If no value is set 4 is returned which is the implicit default. GetTransform returns the transform set on the style. If no transform is set nil is returned. GetUnderline returns the style's underline value. If no value is set false is returned. GetUnderlineColor returns the style's underline color. If no value is set NoColor{} is returned. GetUnderlineSpaces returns whether or not the style is set to underline spaces. If not value is set false is returned. GetUnderlineStyle returns the style's underline style. If no value is set UnderlineNone is returned. GetVerticalBorderSize returns the width of the vertical borders. If borders contain runes of varying widths, the widest rune is returned. If no border exists on the vertical edges, 0 is returned. GetVerticalFrameSize returns the sum of the style's vertical margins, padding and border widths. Provisional: this method may be renamed. GetVerticalMargins returns the style's top and bottom margins. Unset values are measured as 0. GetVerticalPadding returns the style's top and bottom padding. Unset values are measured as 0. GetWidth returns the style's width setting. If no width is set 0 is returned. Height sets the height of the block before applying margins. If the height of the text block is less than this value after applying padding (or not), the block will be set to this height. Hyperlink sets a hyperlink on a style. This is useful for rendering text that can be clicked on in a terminal emulator that supports hyperlinks. Example: s := lipgloss.NewStyle().Hyperlink("https://charm.sh") s := lipgloss.NewStyle().Hyperlink("https://charm.sh", "id=1") Inherit overlays the style in the argument onto this style by copying each explicitly set value from the argument style onto this style if it is not already explicitly set. Existing set values are kept intact and not overwritten. Margins, padding, and underlying string values are not inherited. Inline makes rendering output one line and disables the rendering of margins, padding and borders. This is useful when you need a style to apply only to font rendering and don't want it to change any physical dimensions. It works well with Style.MaxWidth. Because this in intended to be used at the time of render, this method will not mutate the style and instead return a copy. Example: var userInput string = "..." var userStyle = text.Style{ /* ... */ } fmt.Println(userStyle.Inline(true).Render(userInput)) Italic sets an italic formatting rule. In some terminal emulators this will render with "reverse" coloring if not italic font variant is available. Margin is a shorthand method for setting margins on all sides at once. With one argument, the value is applied to all sides. With two arguments, the value is applied to the vertical and horizontal sides, in that order. With three arguments, the value is applied to the top side, the horizontal sides, and the bottom side, in that order. With four arguments, the value is applied clockwise starting from the top side, followed by the right side, then the bottom, and finally the left. With more than four arguments no margin will be added. MarginBackground sets the background color of the margin. Note that this is also set when inheriting from a style with a background color. In that case the background color on that style will set the margin color on this style. MarginBottom sets the value of the bottom margin. MarginChar sets the character used for the margin. This is useful for rendering blocks with a specific character, such as a space or a dot. MarginLeft sets the value of the left margin. MarginRight sets the value of the right margin. MarginTop sets the value of the top margin. MaxHeight applies a max height to a given style. This is useful in enforcing a certain height at render time, particularly with arbitrary strings and styles. Because this in intended to be used at the time of render, this method will not mutate the style and instead returns a copy. MaxWidth applies a max width to a given style. This is useful in enforcing a certain width at render time, particularly with arbitrary strings and styles. Because this in intended to be used at the time of render, this method will not mutate the style and instead return a copy. Example: var userInput string = "..." var userStyle = text.Style{ /* ... */ } fmt.Println(userStyle.MaxWidth(16).Render(userInput)) Padding is a shorthand method for setting padding on all sides at once. With one argument, the value is applied to all sides. With two arguments, the value is applied to the vertical and horizontal sides, in that order. With three arguments, the value is applied to the top side, the horizontal sides, and the bottom side, in that order. With four arguments, the value is applied clockwise starting from the top side, followed by the right side, then the bottom, and finally the left. With more than four arguments no padding will be added. PaddingBottom adds padding to the bottom of the block. PaddingChar sets the character used for padding. This is useful for rendering blocks with a specific character, such as a space or a dot. Example of using [NBSP] as padding to prevent line breaks: ```go s := lipgloss.NewStyle().PaddingChar(lipgloss.NBSP) ``` PaddingLeft adds padding on the left. PaddingRight adds padding on the right. PaddingTop adds padding to the top of the block. Render applies the defined style formatting to a given string. Reverse sets a rule for inverting foreground and background colors. SetString sets the underlying string value for this style. To render once the underlying string is set, use the [Style.String]. This method is a convenience for cases when having a stringer implementation is handy, such as when using fmt.Sprintf. You can also simply define a style and render out strings directly with [Style.Render]. Strikethrough sets a strikethrough rule. By default, strikes will not be drawn on whitespace like margins and padding. To change this behavior set StrikethroughSpaces. StrikethroughSpaces determines whether to apply strikethroughs to spaces between words. By default, this is true. Spaces can also be struck without underlining the text itself. String implements stringer for a Style, returning the rendered result based on the rules in this style. An underlying string value must be set with Style.SetString prior to using this method. TabWidth sets the number of spaces that a tab (/t) should be rendered as. When set to 0, tabs will be removed. To disable the replacement of tabs with spaces entirely, set this to [NoTabConversion]. By default, tabs will be replaced with 4 spaces. Transform applies a given function to a string at render time, allowing for the string being rendered to be manipuated. Example: s := NewStyle().Transform(strings.ToUpper) fmt.Println(s.Render("raow!") // "RAOW!" Underline sets an underline rule. By default, underlines will not be drawn on whitespace like margins and padding. To change this behavior set [Style.UnderlineSpaces]. UnderlineColor sets the color of the underline. By default, the underline will be the same color as the foreground. Note that not all terminal emulators support colored underlines. If color is not supported, it might produce unexpected results. This depends on the terminal emulator being used. UnderlineSpaces determines whether to underline spaces between words. By default, this is true. Spaces can also be underlined without underlining the text itself. UnderlineStyle sets the underline style. This can be used to set the underline to be a single, double, curly, dotted, or dashed line. Note that not all terminal emulators support underline styles. If a style is not supported, it will typically fall back to a single underline but this is not guaranteed. This depends on the terminal emulator being used. UnsetAlign removes the horizontal and vertical text alignment style rule, if set. UnsetAlignHorizontal removes the horizontal text alignment style rule, if set. UnsetAlignVertical removes the vertical text alignment style rule, if set. UnsetBackground removes the background style rule, if set. UnsetBlink removes the blink style rule, if set. UnsetBold removes the bold style rule, if set. UnsetBorderBackground removes all border background color styles, if set. UnsetBorderBottom removes the border bottom style rule, if set. UnsetBorderBottomBackground removes the bottom border background color rule, if set. UnsetBorderBottomForeground removes the bottom border foreground color rule, if set. UnsetBorderForeground removes all border foreground color styles, if set. UnsetBorderForegroundBlend removes the border blend foreground color rules, if set. UnsetBorderForegroundBlendOffset removes the border blend offset style rule, if set. UnsetBorderLeft removes the border left style rule, if set. UnsetBorderLeftBackground removes the left border color rule, if set. UnsetBorderLeftForeground removes the left border foreground color rule, if set. UnsetBorderRight removes the border right style rule, if set. UnsetBorderRightBackground removes the right border background color rule, if set. UnsetBorderRightForeground removes the right border foreground color rule, if set. UnsetBorderStyle removes the border style rule, if set. UnsetBorderTop removes the border top style rule, if set. UnsetBorderTopBackground removes the top border background color rule, if set. UnsetBorderTopBackgroundColor removes the top border background color rule, if set. Deprecated: This function simply calls Style.UnsetBorderTopBackground. UnsetBorderTopForeground removes the top border foreground color rule, if set. UnsetColorWhitespace removes the rule for coloring padding, if set. UnsetFaint removes the faint style rule, if set. UnsetForeground removes the foreground style rule, if set. UnsetHeight removes the height style rule, if set. UnsetHyperlink removes the value set by Hyperlink. UnsetInline removes the inline style rule, if set. UnsetItalic removes the italic style rule, if set. UnsetMarginBackground removes the margin's background color. Note that the margin's background color can be set from the background color of another style during inheritance. UnsetMarginBottom removes the bottom margin style rule, if set. UnsetMarginLeft removes the left margin style rule, if set. UnsetMarginRight removes the right margin style rule, if set. UnsetMarginTop removes the top margin style rule, if set. UnsetMargins removes all margin style rules. UnsetMaxHeight removes the max height style rule, if set. UnsetMaxWidth removes the max width style rule, if set. UnsetPadding removes all padding style rules. UnsetPaddingBottom removes the bottom padding style rule, if set. UnsetPaddingChar removes the padding character style rule, if set. UnsetPaddingLeft removes the left padding style rule, if set. UnsetPaddingRight removes the right padding style rule, if set. UnsetPaddingTop removes the top padding style rule, if set. UnsetReverse removes the reverse style rule, if set. UnsetStrikethrough removes the strikethrough style rule, if set. UnsetStrikethroughSpaces removes the value set by StrikethroughSpaces. UnsetString sets the underlying string value to the empty string. UnsetTabWidth removes the tab width style rule, if set. UnsetTransform removes the value set by Transform. UnsetUnderline removes the underline style rule, if set. UnsetUnderlineSpaces removes the value set by UnderlineSpaces. UnsetWidth removes the width style rule, if set. Value returns the raw, unformatted, underlying string value for this style. Width sets the width of the block before applying margins. This means your styled content will exactly equal the size set here. Text will wrap based on Padding and Borders set on the style. Style : expvar.Var Style : fmt.Stringer func NewStyle() Style func Style.Align(p ...Position) Style func Style.AlignHorizontal(p Position) Style func Style.AlignVertical(p Position) Style func Style.Background(c color.Color) Style func Style.Blink(v bool) Style func Style.Bold(v bool) Style func Style.Border(b Border, sides ...bool) Style func Style.BorderBackground(c ...color.Color) Style func Style.BorderBottom(v bool) Style func Style.BorderBottomBackground(c color.Color) Style func Style.BorderBottomForeground(c color.Color) Style func Style.BorderForeground(c ...color.Color) Style func Style.BorderForegroundBlend(c ...color.Color) Style func Style.BorderForegroundBlendOffset(v int) Style func Style.BorderLeft(v bool) Style func Style.BorderLeftBackground(c color.Color) Style func Style.BorderLeftForeground(c color.Color) Style func Style.BorderRight(v bool) Style func Style.BorderRightBackground(c color.Color) Style func Style.BorderRightForeground(c color.Color) Style func Style.BorderStyle(b Border) Style func Style.BorderTop(v bool) Style func Style.BorderTopBackground(c color.Color) Style func Style.BorderTopForeground(c color.Color) Style func Style.ColorWhitespace(v bool) Style func Style.Copy() Style func Style.Faint(v bool) Style func Style.Foreground(c color.Color) Style func Style.Height(i int) Style func Style.Hyperlink(link string, params ...string) Style func Style.Inherit(i Style) Style func Style.Inline(v bool) Style func Style.Italic(v bool) Style func Style.Margin(i ...int) Style func Style.MarginBackground(c color.Color) Style func Style.MarginBottom(i int) Style func Style.MarginChar(r rune) Style func Style.MarginLeft(i int) Style func Style.MarginRight(i int) Style func Style.MarginTop(i int) Style func Style.MaxHeight(n int) Style func Style.MaxWidth(n int) Style func Style.Padding(i ...int) Style func Style.PaddingBottom(i int) Style func Style.PaddingChar(r rune) Style func Style.PaddingLeft(i int) Style func Style.PaddingRight(i int) Style func Style.PaddingTop(i int) Style func Style.Reverse(v bool) Style func Style.SetString(strs ...string) Style func Style.Strikethrough(v bool) Style func Style.StrikethroughSpaces(v bool) Style func Style.TabWidth(n int) Style func Style.Transform(fn func(string) string) Style func Style.Underline(v bool) Style func Style.UnderlineColor(c color.Color) Style func Style.UnderlineSpaces(v bool) Style func Style.UnderlineStyle(u Underline) Style func Style.UnsetAlign() Style func Style.UnsetAlignHorizontal() Style func Style.UnsetAlignVertical() Style func Style.UnsetBackground() Style func Style.UnsetBlink() Style func Style.UnsetBold() Style func Style.UnsetBorderBackground() Style func Style.UnsetBorderBottom() Style func Style.UnsetBorderBottomBackground() Style func Style.UnsetBorderBottomForeground() Style func Style.UnsetBorderForeground() Style func Style.UnsetBorderForegroundBlend() Style func Style.UnsetBorderForegroundBlendOffset() Style func Style.UnsetBorderLeft() Style func Style.UnsetBorderLeftBackground() Style func Style.UnsetBorderLeftForeground() Style func Style.UnsetBorderRight() Style func Style.UnsetBorderRightBackground() Style func Style.UnsetBorderRightForeground() Style func Style.UnsetBorderStyle() Style func Style.UnsetBorderTop() Style func Style.UnsetBorderTopBackground() Style func Style.UnsetBorderTopBackgroundColor() Style func Style.UnsetBorderTopForeground() Style func Style.UnsetColorWhitespace() Style func Style.UnsetFaint() Style func Style.UnsetForeground() Style func Style.UnsetHeight() Style func Style.UnsetHyperlink() Style func Style.UnsetInline() Style func Style.UnsetItalic() Style func Style.UnsetMarginBackground() Style func Style.UnsetMarginBottom() Style func Style.UnsetMarginLeft() Style func Style.UnsetMarginRight() Style func Style.UnsetMargins() Style func Style.UnsetMarginTop() Style func Style.UnsetMaxHeight() Style func Style.UnsetMaxWidth() Style func Style.UnsetPadding() Style func Style.UnsetPaddingBottom() Style func Style.UnsetPaddingChar() Style func Style.UnsetPaddingLeft() Style func Style.UnsetPaddingRight() Style func Style.UnsetPaddingTop() Style func Style.UnsetReverse() Style func Style.UnsetStrikethrough() Style func Style.UnsetStrikethroughSpaces() Style func Style.UnsetString() Style func Style.UnsetTabWidth() Style func Style.UnsetTransform() Style func Style.UnsetUnderline() Style func Style.UnsetUnderlineSpaces() Style func Style.UnsetWidth() Style func Style.Width(i int) Style func charm.land/lipgloss/v2/table.DefaultStyles(_, _ int) Style func NewRange(start, end int, style Style) Range func StyleRunes(str string, indices []int, matched, unmatched Style) string func WithWhitespaceStyle(s Style) WhitespaceOption func Style.Inherit(i Style) Style func charm.land/lipgloss/v2/table.(*Table).BaseStyle(baseStyle Style) *table.Table func charm.land/lipgloss/v2/table.(*Table).BorderStyle(style Style) *table.Table func charm.land/lipgloss/v2/tree.(*Tree).EnumeratorStyle(style Style) *tree.Tree func charm.land/lipgloss/v2/tree.(*Tree).IndenterStyle(style Style) *tree.Tree func charm.land/lipgloss/v2/tree.(*Tree).ItemStyle(style Style) *tree.Tree func charm.land/lipgloss/v2/tree.(*Tree).RootStyle(style Style) *tree.Tree
Underline is the style of the underline. Caveats: - Not all terminals support all underline styles. - Some terminals may render unsupported styles as standard underlines. - Terminal themes may affect the visibility of different underline styles.
WhitespaceOption sets a styling rule for rendering whitespace. func WithWhitespaceChars(s string) WhitespaceOption func WithWhitespaceStyle(s Style) WhitespaceOption func Place(width, height int, hPos, vPos Position, str string, opts ...WhitespaceOption) string func PlaceHorizontal(width int, pos Position, str string, opts ...WhitespaceOption) string func PlaceVertical(height int, pos Position, str string, opts ...WhitespaceOption) string
WrapWriter is a writer that writes to a buffer and keeps track of the current pen style and link state for the purpose of wrapping with newlines. When it encounters a newline, it resets the style and link, writes the newline, and then reapplies the style and link to the next line. Close closes the writer, resets the style and link if necessary, and releases its parser. Calling it is performance critical, but forgetting it does not cause safety issues or leaks. Link returns the current pen link. Style returns the current pen style. Write writes to the buffer. *WrapWriter : internal/bisect.Writer *WrapWriter : io.Closer *WrapWriter : io.WriteCloser *WrapWriter : io.Writer func NewWrapWriter(w io.Writer) *WrapWriter
Package-Level Functions (total 75, in which 50 are exported)
Alpha adjusts the alpha value of a color using a 0-1 (clamped) float scale 0 = transparent, 1 = opaque.
ASCIIBorder returns a table border with ASCII characters.
BackgroundColor queries the terminal's background color. Typically, you'll want to query against stdin and either stdout or stderr, depending on what you're writing to. This function is intended for standalone Lip Gloss use only. If you're using Bubble Tea, listen for tea.BackgroundColorMsg in your update function.
Blend1D blends a series of colors together in one linear dimension using multiple stops, into the provided number of steps. Uses the "CIE L*, a*, b*" (CIELAB) color-space. Note that if any of the provided colors are completely transparent, we will assume that the alpha value was lost in conversion from RGB -> RGBA, and we will set the alpha to opaque, as it's not possible to blend something completely transparent.
Blend2D blends a series of colors together in two linear dimensions using multiple stops, into the provided width/height. Uses the "CIE L*, a*, b*" (CIELAB) color-space. The angle parameter controls the rotation of the gradient (0-360°), where 0° is left-to-right, 45° is bottom-left to top-right (diagonal). The function returns colors in a 1D row-major order ([row1, row2, row3, ...]). Example of how to iterate over the result: gradient := colors.Blend2D(width, height, 180, color1, color2, color3, ...) gradientContent := strings.Builder{} for y := range height { for x := range width { index := y*width + x gradientContent.WriteString( lipgloss.NewStyle(). Background(gradient[index]). Render(" "), ) } if y < height-1 { // End of row. gradientContent.WriteString("\n") } } Note that if any of the provided colors are completely transparent, we will assume that the alpha value was lost in conversion from RGB -> RGBA, and we will set the alpha to opaque, as it's not possible to blend something completely transparent.
BlockBorder returns a border that takes the whole block.
Color specifies a color by hex or ANSI256 value. For example: ansiColor := lipgloss.Color("1") // The same as lipgloss.Red ansi256Color := lipgloss.Color("21") hexColor := lipgloss.Color("#0000ff")
Complementary returns the complementary color (180° away on color wheel) of the given color. This is useful for creating a contrasting color.
Complete returns a function that will return the appropriate color based on the given color profile. Example usage: p := colorprofile.Detect(os.Stderr, os.Environ()) complete := lipgloss.Complete(p) color := complete( lipgloss.Color(1), // ANSI lipgloss.Color(124), // ANSI256 lipgloss.Color("#ff34ac"), // TrueColor ) fmt.Println("Ooh, pretty color: ", color)
Darken takes a color and makes it darker by a specific percentage (0-1, clamped).
DoubleBorder returns a border comprised of two thin strokes.
EnableLegacyWindowsANSI is only needed on Windows.
Fprint pritnts to the given writer, automatically downsampling colors when necessary. Example: str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("guzzle") Fprint(os.Stderr, "I %s horchata pretty much all the time.\n", str)
Fprintf prints text to a writer, against the given format, automatically downsampling colors when necessary. Example: str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("artichokes") Fprintf(os.Stderr, "I really love %s!\n", food)
Fprintln prints to the given writer, automatically downsampling colors when necessary, and ending with a trailing newline. Example: str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("Sandwich time!") Fprintln(os.Stderr, str)
HasDarkBackground detects whether the terminal has a light or dark background. Typically, you'll want to query against stdin and either stdout or stderr depending on what you're writing to. hasDarkBG := HasDarkBackground(os.Stdin, os.Stdout) lightDark := LightDark(hasDarkBG) myHotColor := lightDark("#ff0000", "#0000ff") This is intended for use in standalone Lip Gloss only. In Bubble Tea, listen for tea.BackgroundColorMsg in your Update function. case tea.BackgroundColorMsg: hasDarkBackground = msg.IsDark() By default, this function will return true if it encounters an error.
Height returns height of a string in cells. This is done simply by counting \n characters. If your output has \r\n, that sequence will be replaced with a \n in [Style.Render].
HiddenBorder returns a border that renders as a series of single-cell spaces. It's useful for cases when you want to remove a standard border but maintain layout positioning. This said, you can still apply a background color to a hidden border.
InnerHalfBlockBorder returns a half-block border that sits inside the frame.
JoinHorizontal is a utility function for horizontally joining two potentially multi-lined strings along a vertical axis. The first argument is the position, with 0 being all the way at the top and 1 being all the way at the bottom. If you just want to align to the top, center or bottom you may as well just use the helper constants Top, Center, and Bottom. Example: blockB := "...\n...\n..." blockA := "...\n...\n...\n...\n..." // Join 20% from the top str := lipgloss.JoinHorizontal(0.2, blockA, blockB) // Join on the top edge str := lipgloss.JoinHorizontal(lipgloss.Top, blockA, blockB)
JoinVertical is a utility function for vertically joining two potentially multi-lined strings along a horizontal axis. The first argument is the position, with 0 being all the way to the left and 1 being all the way to the right. If you just want to align to the left, right or center you may as well just use the helper constants Left, Center, and Right. Example: blockB := "...\n...\n..." blockA := "...\n...\n...\n...\n..." // Join 20% from the top str := lipgloss.JoinVertical(0.2, blockA, blockB) // Join on the right edge str := lipgloss.JoinVertical(lipgloss.Right, blockA, blockB)
LightDark is a simple helper type that can be used to choose the appropriate color based on whether the terminal has a light or dark background. lightDark := lipgloss.LightDark(hasDarkBackground) red, blue := lipgloss.Color("#ff0000"), lipgloss.Color("#0000ff") myHotColor := lightDark(red, blue) In practice, there are slightly different workflows between Bubble Tea and Lip Gloss standalone. In Bubble Tea, listen for tea.BackgroundColorMsg, which automatically flows through Update on start. This message will be received whenever the background color changes: case tea.BackgroundColorMsg: m.hasDarkBackground = msg.IsDark() Later, when you're rendering use: lightDark := lipgloss.LightDark(m.hasDarkBackground) red, blue := lipgloss.Color("#ff0000"), lipgloss.Color("#0000ff") myHotColor := lightDark(red, blue) In standalone Lip Gloss, the workflow is simpler: hasDarkBG := lipgloss.HasDarkBackground(os.Stdin, os.Stdout) lightDark := lipgloss.LightDark(hasDarkBG) red, blue := lipgloss.Color("#ff0000"), lipgloss.Color("#0000ff") myHotColor := lightDark(red, blue)
Lighten makes a color lighter by a specific percentage (0-1, clamped).
MarkdownBorder return a table border in markdown style. Make sure to disable top and bottom border for the best result. This will ensure that the output is valid markdown. table.New().Border(lipgloss.MarkdownBorder()).BorderTop(false).BorderBottom(false)
NewCanvas creates a new [Canvas] with the given size.
NewCompositor creates a new Compositor with an internal root layer. Optional layers can be provided which will be added as children of the root. The layer hierarchy is flattened and sorted by z-index for efficient rendering and hit testing.
NewLayer creates a new [Layer] with the given content and optional child layers.
NewRange returns a range and style that can be used with [StyleRanges].
NewStyle returns a new, empty Style. While it's syntactic sugar for the [Style]{} primitive, it's recommended to use this function for creating styles in case the underlying implementation changes.
NewWrapWriter returns a new [WrapWriter].
NormalBorder returns a standard-type border with a normal weight and 90 degree corners.
OuterHalfBlockBorder returns a half-block border that sits outside the frame.
Place places a string or text block vertically in an unstyled box of a given width or height.
PlaceHorizontal places a string or text block horizontally in an unstyled block of a given width. If the given width is shorter than the max width of the string (measured by its longest line) this will be a noöp.
PlaceVertical places a string or text block vertically in an unstyled block of a given height. If the given height is shorter than the height of the string (measured by its newlines) then this will be a noöp.
Print to stdout, automatically downsampling colors when necessary. Example: str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("Who wants marmalade?\n") Print(str)
Printf prints formatted text to stdout, automatically downsampling colors when necessary. Example: str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("knuckle") Printf("Time for a %s sandwich!\n", str)
Println to stdout, automatically downsampling colors when necessary, ending with a trailing newline. Example: str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("breakfast") Println("Time for a", str, "sandwich!")
RoundedBorder returns a border with rounded corners.
Size returns the width and height of the string in cells. ANSI sequences are ignored and characters wider than one cell (such as Chinese characters and emojis) are appropriately measured.
Sprint returns a string for stdout, automatically downsampling colors when necessary. Example: str := NewStyle(). Faint(true). Foreground(lipgloss.Color("#6a00ff")). Render("I love to eat") str = Sprint(str)
Sprintf returns a formatted string for stdout, automatically downsampling colors when necessary. Example: str := NewStyle(). Bold(true). Foreground(lipgloss.Color("#fccaee")). Render("Cantaloupe") str = Sprintf("I really love %s!", str)
Sprintln returns a string for stdout, automatically downsampling colors when necessary, and ending with a trailing newline. Example: str := NewStyle(). Bold(true). Foreground(lipgloss.Color("#6a00ff")). Render("Yummy!") str = Sprintln(str)
StyleRanges applying styling to ranges in a string. Existing styles will be taken into account. Ranges should not overlap.
StyleRunes apply a given style to runes at the given indices in the string. Note that you must provide styling options for both matched and unmatched runes. Indices out of bounds will be ignored.
ThickBorder returns a border that's thicker than the one returned by NormalBorder.
Width returns the cell width of characters in the string. ANSI sequences are ignored and characters wider than one cell (such as Chinese characters and emojis) are appropriately measured. You should use this instead of len(string) or len([]rune(string) as neither will give you accurate results.
WithWhitespaceChars sets the characters to be rendered in the whitespace.
WithWhitespaceStyle sets the style for the whitespace.
Wrap wraps the given string to the given width, preserving ANSI styles and links.
Package-Level Variables (total 14, in which 1 is exported)
Writer is the default writer that prints to stdout, automatically downsampling colors when necessary.
Package-Level Constants (total 81, in which 29 are exported)
4-bit color constants.
4-bit color constants.
Position aliases.
4-bit color constants.
4-bit color constants.
4-bit color constants.
4-bit color constants.
4-bit color constants.
4-bit color constants.
4-bit color constants.
4-bit color constants.
Position aliases.
4-bit color constants.
4-bit color constants.
Position aliases.
4-bit color constants.
NBSP is the non-breaking space rune.
NoTabConversion can be passed to [Style.TabWidth] to disable the replacement of tabs with spaces at render time.
4-bit color constants.
Position aliases.
Position aliases.
UnderlineCurly is a curly underline.
UnderlineDashed is a dashed underline.
UnderlineDotted is a dotted underline.
UnderlineDouble is a double underline.
UnderlineNone is no underline.
UnderlineSingle is a single underline. This is the default when underline is enabled.
4-bit color constants.
4-bit color constants.