Documentation ¶
Index ¶
- Constants
- Variables
- func BackgroundColor(in *os.File, out *os.File) (bg color.Color, err error)
- func Color(c any) color.Color
- func EnableLegacyWindowsANSI(*os.File)
- func Fprint(w io.Writer, v ...interface{}) (int, error)
- func Fprintf(w io.Writer, format string, v ...interface{}) (int, error)
- func Fprintln(w io.Writer, v ...interface{}) (int, error)
- func HasDarkBackground(in *os.File, out *os.File) (bool, error)
- func Height(str string) int
- 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 Print(v ...interface{}) (int, error)
- func Printf(format string, v ...interface{}) (int, error)
- func Println(v ...interface{}) (int, error)
- func Size(str string) (width, height int)
- func Sprint(v ...interface{}) string
- func Sprintf(format string, v ...interface{}) string
- func Sprintln(v ...interface{}) string
- func StyleRunes(str string, indices []int, matched, unmatched Style) string
- func Width(str string) (width int)
- type ANSIColor
- type Border
- type CompleteFunc
- type LightDarkFunc
- type NoColor
- type Position
- type RGBColor
- type Style
- func (s Style) Align(p ...Position) Style
- func (s Style) AlignHorizontal(p Position) Style
- func (s Style) AlignVertical(p Position) Style
- func (s Style) Background(c color.Color) Style
- func (s Style) Blink(v bool) Style
- func (s Style) Bold(v bool) Style
- func (s Style) Border(b Border, sides ...bool) Style
- func (s Style) BorderBackground(c ...color.Color) Style
- func (s Style) BorderBottom(v bool) Style
- func (s Style) BorderBottomBackground(c color.Color) Style
- func (s Style) BorderBottomForeground(c color.Color) Style
- func (s Style) BorderForeground(c ...color.Color) Style
- func (s Style) BorderLeft(v bool) Style
- func (s Style) BorderLeftBackground(c color.Color) Style
- func (s Style) BorderLeftForeground(c color.Color) Style
- func (s Style) BorderRight(v bool) Style
- func (s Style) BorderRightBackground(c color.Color) Style
- func (s Style) BorderRightForeground(c color.Color) Style
- func (s Style) BorderStyle(b Border) Style
- func (s Style) BorderTop(v bool) Style
- func (s Style) BorderTopBackground(c color.Color) Style
- func (s Style) BorderTopForeground(c color.Color) Style
- func (s Style) ColorWhitespace(v bool) Styledeprecated
- func (s Style) Copy() Styledeprecated
- func (s Style) Faint(v bool) Style
- func (s Style) Foreground(c color.Color) Style
- func (s Style) GetAlign() Position
- func (s Style) GetAlignHorizontal() Position
- func (s Style) GetAlignVertical() Position
- func (s Style) GetBackground() color.Color
- func (s Style) GetBlink() bool
- func (s Style) GetBold() bool
- func (s Style) GetBorder() (b Border, top, right, bottom, left bool)
- func (s Style) GetBorderBottom() bool
- func (s Style) GetBorderBottomBackground() color.Color
- func (s Style) GetBorderBottomForeground() color.Color
- func (s Style) GetBorderBottomSize() int
- func (s Style) GetBorderLeft() bool
- func (s Style) GetBorderLeftBackground() color.Color
- func (s Style) GetBorderLeftForeground() color.Color
- func (s Style) GetBorderLeftSize() int
- func (s Style) GetBorderRight() bool
- func (s Style) GetBorderRightBackground() color.Color
- func (s Style) GetBorderRightForeground() color.Color
- func (s Style) GetBorderRightSize() int
- func (s Style) GetBorderStyle() Border
- func (s Style) GetBorderTop() bool
- func (s Style) GetBorderTopBackground() color.Color
- func (s Style) GetBorderTopForeground() color.Color
- func (s Style) GetBorderTopSize() int
- func (s Style) GetBorderTopWidth() intdeprecated
- func (s Style) GetColorWhitespace() bool
- func (s Style) GetFaint() bool
- func (s Style) GetForeground() color.Color
- func (s Style) GetFrameSize() (x, y int)
- func (s Style) GetHeight() int
- func (s Style) GetHorizontalBorderSize() int
- func (s Style) GetHorizontalFrameSize() int
- func (s Style) GetHorizontalMargins() int
- func (s Style) GetHorizontalPadding() int
- func (s Style) GetInline() bool
- func (s Style) GetItalic() bool
- func (s Style) GetMargin() (top, right, bottom, left int)
- func (s Style) GetMarginBottom() int
- func (s Style) GetMarginLeft() int
- func (s Style) GetMarginRight() int
- func (s Style) GetMarginTop() int
- func (s Style) GetMaxHeight() int
- func (s Style) GetMaxWidth() int
- func (s Style) GetPadding() (top, right, bottom, left int)
- func (s Style) GetPaddingBottom() int
- func (s Style) GetPaddingLeft() int
- func (s Style) GetPaddingRight() int
- func (s Style) GetPaddingTop() int
- func (s Style) GetReverse() bool
- func (s Style) GetStrikethrough() bool
- func (s Style) GetStrikethroughSpaces() bool
- func (s Style) GetTabWidth() int
- func (s Style) GetTransform() func(string) string
- func (s Style) GetUnderline() bool
- func (s Style) GetUnderlineSpaces() bool
- func (s Style) GetVerticalBorderSize() int
- func (s Style) GetVerticalFrameSize() int
- func (s Style) GetVerticalMargins() int
- func (s Style) GetVerticalPadding() int
- func (s Style) GetWidth() int
- func (s Style) Height(i int) Style
- func (s Style) Inherit(i Style) Style
- func (s Style) Inline(v bool) Style
- func (s Style) Italic(v bool) Style
- func (s Style) Margin(i ...int) Style
- func (s Style) MarginBackground(c color.Color) Style
- func (s Style) MarginBottom(i int) Style
- func (s Style) MarginLeft(i int) Style
- func (s Style) MarginRight(i int) Style
- func (s Style) MarginTop(i int) Style
- func (s Style) MaxHeight(n int) Style
- func (s Style) MaxWidth(n int) Style
- func (s Style) Padding(i ...int) Style
- func (s Style) PaddingBottom(i int) Style
- func (s Style) PaddingLeft(i int) Style
- func (s Style) PaddingRight(i int) Style
- func (s Style) PaddingTop(i int) Style
- func (s Style) Render(strs ...string) string
- func (s Style) Reverse(v bool) Style
- func (s Style) SetString(strs ...string) Style
- func (s Style) Strikethrough(v bool) Style
- func (s Style) StrikethroughSpaces(v bool) Style
- func (s Style) String() string
- func (s Style) TabWidth(n int) Style
- func (s Style) Transform(fn func(string) string) Style
- func (s Style) Underline(v bool) Style
- func (s Style) UnderlineSpaces(v bool) Style
- func (s Style) UnsetAlign() Style
- func (s Style) UnsetAlignHorizontal() Style
- func (s Style) UnsetAlignVertical() Style
- func (s Style) UnsetBackground() Style
- func (s Style) UnsetBlink() Style
- func (s Style) UnsetBold() Style
- func (s Style) UnsetBorderBackground() Style
- func (s Style) UnsetBorderBottom() Style
- func (s Style) UnsetBorderBottomBackground() Style
- func (s Style) UnsetBorderBottomForeground() Style
- func (s Style) UnsetBorderForeground() Style
- func (s Style) UnsetBorderLeft() Style
- func (s Style) UnsetBorderLeftBackground() Style
- func (s Style) UnsetBorderLeftForeground() Style
- func (s Style) UnsetBorderRight() Style
- func (s Style) UnsetBorderRightBackground() Style
- func (s Style) UnsetBorderRightForeground() Style
- func (s Style) UnsetBorderStyle() Style
- func (s Style) UnsetBorderTop() Style
- func (s Style) UnsetBorderTopBackground() Style
- func (s Style) UnsetBorderTopBackgroundColor() Styledeprecated
- func (s Style) UnsetBorderTopForeground() Style
- func (s Style) UnsetColorWhitespace() Style
- func (s Style) UnsetFaint() Style
- func (s Style) UnsetForeground() Style
- func (s Style) UnsetHeight() Style
- func (s Style) UnsetInline() Style
- func (s Style) UnsetItalic() Style
- func (s Style) UnsetMarginBackground() Style
- func (s Style) UnsetMarginBottom() Style
- func (s Style) UnsetMarginLeft() Style
- func (s Style) UnsetMarginRight() Style
- func (s Style) UnsetMarginTop() Style
- func (s Style) UnsetMargins() Style
- func (s Style) UnsetMaxHeight() Style
- func (s Style) UnsetMaxWidth() Style
- func (s Style) UnsetPadding() Style
- func (s Style) UnsetPaddingBottom() Style
- func (s Style) UnsetPaddingLeft() Style
- func (s Style) UnsetPaddingRight() Style
- func (s Style) UnsetPaddingTop() Style
- func (s Style) UnsetReverse() Style
- func (s Style) UnsetStrikethrough() Style
- func (s Style) UnsetStrikethroughSpaces() Style
- func (s Style) UnsetString() Style
- func (s Style) UnsetTabWidth() Style
- func (s Style) UnsetTransform() Style
- func (s Style) UnsetUnderline() Style
- func (s Style) UnsetUnderlineSpaces() Style
- func (s Style) UnsetWidth() Style
- func (s Style) Value() string
- func (s Style) Width(i int) Style
- type WhitespaceOption
Constants ¶
const ( Black ansi.BasicColor = iota Red Green Yellow Blue Magenta Cyan White BrightBlack BrightRed BrightGreen BrightYellow BrightBlue BrightMagenta BrightCyan BrightWhite )
4-bit color constants.
const NoTabConversion = -1
NoTabConversion can be passed to Style.TabWidth to disable the replacement of tabs with spaces at render time.
Variables ¶
var Writer = colorprofile.NewWriter(os.Stdout, os.Environ())
Writer is the default writer that prints to stdout, automatically downsampling colors when necessary.
Functions ¶
func BackgroundColor ¶
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.
func Color ¶
Color specifies a color by hex or ANSI256 value. For example:
ansiColor := lipgloss.Color(21) hexColor := lipgloss.Color("#0000ff") uint32Color := lipgloss.Color(0xff0000)
func EnableLegacyWindowsANSI ¶
EnableLegacyWindowsANSI is only needed on Windows.
func Fprint ¶
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)
func Fprintf ¶
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)
func Fprintln ¶
Fprint pritnts 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)
func HasDarkBackground ¶
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 intedded for use in standalone Lip Gloss only. In Bubble Tea, listen for tea.BackgroundColorMsg in your update function.
case tea.BackgroundColorMsg: hasDarkBackground = msg.IsDark()
func Height ¶
Height returns height of a string in cells. This is done simply by counting \n characters. If your strings use \r\n for newlines you should convert them to \n first, or simply write a separate function for measuring height.
func JoinHorizontal ¶
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)
func JoinVertical ¶
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)
func Place ¶
func Place(width, height int, hPos, vPos Position, str string, opts ...WhitespaceOption) string
Place places a string or text block vertically in an unstyled box of a given width or height.
func PlaceHorizontal ¶
func PlaceHorizontal(width int, pos Position, str string, opts ...WhitespaceOption) string
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 noop.
func PlaceVertical ¶
func PlaceVertical(height int, pos Position, str string, opts ...WhitespaceOption) string
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 noop.
func Print ¶
Print to stdout, automatically downsampling colors when necessary.
Example:
str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("Who wants marmalade?\n") Print(str)
func Printf ¶
Print 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)
func Println ¶
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!")
func Size ¶
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.
func Sprint ¶
func Sprint(v ...interface{}) string
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)
func Sprintf ¶
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)
func Sprintln ¶
func Sprintln(v ...interface{}) string
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)
func StyleRunes ¶
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.
func Width ¶
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) len([]rune(string) as neither will give you accurate results.
Types ¶
type ANSIColor ¶
type ANSIColor = ansi.ExtendedColor
ANSIColor is a color specified by an ANSI256 color value.
Example usage:
colorA := lipgloss.ANSIColor(8) colorB := lipgloss.ANSIColor(134)
type Border ¶
type Border struct { Top string Bottom string Left string Right string TopLeft string TopRight string BottomLeft string BottomRight string MiddleLeft string MiddleRight string Middle string MiddleTop string MiddleBottom string }
Border contains a series of values which comprise the various parts of a border.
func BlockBorder ¶
func BlockBorder() Border
BlockBorder returns a border that takes the whole block.
func DoubleBorder ¶
func DoubleBorder() Border
DoubleBorder returns a border comprised of two thin strokes.
func HiddenBorder ¶
func HiddenBorder() Border
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.
func InnerHalfBlockBorder ¶
func InnerHalfBlockBorder() Border
InnerHalfBlockBorder returns a half-block border that sits inside the frame.
func NormalBorder ¶
func NormalBorder() Border
NormalBorder returns a standard-type border with a normal weight and 90 degree corners.
func OuterHalfBlockBorder ¶
func OuterHalfBlockBorder() Border
OuterHalfBlockBorder returns a half-block border that sits outside the frame.
func RoundedBorder ¶
func RoundedBorder() Border
RoundedBorder returns a border with rounded corners.
func ThickBorder ¶
func ThickBorder() Border
ThickBorder returns a border that's thicker than the one returned by NormalBorder.
func (Border) GetBottomSize ¶
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.
func (Border) GetLeftSize ¶
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.
func (Border) GetRightSize ¶
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.
func (Border) GetTopSize ¶
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.
type CompleteFunc ¶
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 ¶
func Complete(p colorprofile.Profile) CompleteFunc
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)
type LightDarkFunc ¶
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) myHotColor := lightDark("#ff0000", "#0000ff")
For more info see LightDark.
func LightDark ¶
func LightDark(isDark bool) LightDarkFunc
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) theRightColor := lightDark("#0000ff", "#ff0000")
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, and whenever the background color changes:
case tea.BackgroundColorMsg: m.hasDarkBackground = msg.IsDark()
Later, when you're rendering:
lightDark := lipgloss.LightDark(m.hasDarkBackground) myHotColor := lightDark("#ff0000", "#0000ff")
In standalone Lip Gloss, the workflow is simpler:
hasDarkBG, _ := lipgloss.HasDarkBackground(os.Stdin, os.Stdout) lightDark := lipgloss.LightDark(hasDarkBG) myHotColor := lightDark("#ff0000", "#0000ff")
type NoColor ¶
type NoColor struct{}
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{})
type Position ¶
type Position float64
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.
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style contains a set of rules that comprise a style as a whole.
func NewStyle ¶
func NewStyle() Style
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.
func (Style) Align ¶
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.
func (Style) AlignHorizontal ¶
AlignHorizontal sets a horizontal text alignment rule.
func (Style) AlignVertical ¶
AlignVertical sets a vertical text alignment rule.
func (Style) Background ¶
Background sets a background color.
func (Style) Border ¶
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)
func (Style) BorderBackground ¶
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.
func (Style) BorderBottom ¶
BorderBottom determines whether or not to draw a bottom border.
func (Style) BorderBottomBackground ¶
BorderBottomBackground sets the background color of the bottom of the border.
func (Style) BorderBottomForeground ¶
BorderBottomForeground sets the foreground color for the bottom of the border.
func (Style) BorderForeground ¶
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.
func (Style) BorderLeft ¶
BorderLeft determines whether or not to draw a left border.
func (Style) BorderLeftBackground ¶
BorderLeftBackground set the background color of the left side of the border.
func (Style) BorderLeftForeground ¶
BorderLeftForeground sets the foreground color for the left side of the border.
func (Style) BorderRight ¶
BorderRight determines whether or not to draw a right border.
func (Style) BorderRightBackground ¶
BorderRightBackground sets the background color of right side the border.
func (Style) BorderRightForeground ¶
BorderRightForeground sets the foreground color for the right side of the border.
func (Style) BorderStyle ¶
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())
func (Style) BorderTopBackground ¶
BorderTopBackground sets the background color of the top of the border.
func (Style) BorderTopForeground ¶
BorderTopForeground set the foreground color for the top of the border.
func (Style) ColorWhitespace
deprecated
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.
func (Style) Foreground ¶
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)
func (Style) GetAlign ¶
GetAlign returns the style's implicit horizontal alignment setting. If no alignment is set Position.Left is returned.
func (Style) GetAlignHorizontal ¶
GetAlignHorizontal returns the style's implicit horizontal alignment setting. If no alignment is set Position.Left is returned.
func (Style) GetAlignVertical ¶
GetAlignVertical returns the style's implicit vertical alignment setting. If no alignment is set Position.Top is returned.
func (Style) GetBackground ¶
GetBackground returns the style's background color. If no value is set NoColor{} is returned.
func (Style) GetBlink ¶
GetBlink returns the style's blink value. If no value is set false is returned.
func (Style) GetBold ¶
GetBold returns the style's bold value. If no value is set false is returned.
func (Style) GetBorder ¶
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.
func (Style) GetBorderBottom ¶
GetBorderBottom returns the style's bottom border setting. If no value is set false is returned.
func (Style) GetBorderBottomBackground ¶
GetBorderBottomBackground returns the style's border bottom background color. If no value is set NoColor{} is returned.
func (Style) GetBorderBottomForeground ¶
GetBorderBottomForeground returns the style's border bottom foreground color. If no value is set NoColor{} is returned.
func (Style) GetBorderBottomSize ¶
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.
func (Style) GetBorderLeft ¶
GetBorderLeft returns the style's left border setting. If no value is set false is returned.
func (Style) GetBorderLeftBackground ¶
GetBorderLeftBackground returns the style's border left background color. If no value is set NoColor{} is returned.
func (Style) GetBorderLeftForeground ¶
GetBorderLeftForeground returns the style's border left foreground color. If no value is set NoColor{} is returned.
func (Style) GetBorderLeftSize ¶
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.
func (Style) GetBorderRight ¶
GetBorderRight returns the style's right border setting. If no value is set false is returned.
func (Style) GetBorderRightBackground ¶
GetBorderRightBackground returns the style's border right background color. If no value is set NoColor{} is returned.
func (Style) GetBorderRightForeground ¶
GetBorderRightForeground returns the style's border right foreground color. If no value is set NoColor{} is returned.
func (Style) GetBorderRightSize ¶
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.
func (Style) GetBorderStyle ¶
GetBorderStyle returns the style's border style (type Border). If no value is set Border{} is returned.
func (Style) GetBorderTop ¶
GetBorderTop returns the style's top border setting. If no value is set false is returned.
func (Style) GetBorderTopBackground ¶
GetBorderTopBackground returns the style's border top background color. If no value is set NoColor{} is returned.
func (Style) GetBorderTopForeground ¶
GetBorderTopForeground returns the style's border top foreground color. If no value is set NoColor{} is returned.
func (Style) GetBorderTopSize ¶
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.
func (Style) GetBorderTopWidth
deprecated
func (Style) GetColorWhitespace ¶
GetColorWhitespace returns the style's whitespace coloring setting. If no value is set false is returned.
func (Style) GetFaint ¶
GetFaint returns the style's faint value. If no value is set false is returned.
func (Style) GetForeground ¶
GetForeground returns the style's foreground color. If no value is set NoColor{} is returned.
func (Style) GetFrameSize ¶
GetFrameSize returns the sum of the margins, padding and border width for both the horizontal and vertical margins.
func (Style) GetHeight ¶
GetHeight returns the style's height setting. If no height is set 0 is returned.
func (Style) GetHorizontalBorderSize ¶
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.
func (Style) GetHorizontalFrameSize ¶
GetHorizontalFrameSize returns the sum of the style's horizontal margins, padding and border widths.
Provisional: this method may be renamed.
func (Style) GetHorizontalMargins ¶
GetHorizontalMargins returns the style's left and right margins. Unset values are measured as 0.
func (Style) GetHorizontalPadding ¶
GetHorizontalPadding returns the style's left and right padding. Unset values are measured as 0.
func (Style) GetInline ¶
GetInline returns the style's inline setting. If no value is set false is returned.
func (Style) GetItalic ¶
GetItalic returns the style's italic value. If no value is set false is returned.
func (Style) GetMargin ¶
GetMargin returns the style's top, right, bottom, and left margins, in that order. 0 is returned for unset values.
func (Style) GetMarginBottom ¶
GetMarginBottom returns the style's bottom margin. If no value is set 0 is returned.
func (Style) GetMarginLeft ¶
GetMarginLeft returns the style's left margin. If no value is set 0 is returned.
func (Style) GetMarginRight ¶
GetMarginRight returns the style's right margin. If no value is set 0 is returned.
func (Style) GetMarginTop ¶
GetMarginTop returns the style's top margin. If no value is set 0 is returned.
func (Style) GetMaxHeight ¶
GetMaxHeight returns the style's max height setting. If no value is set 0 is returned.
func (Style) GetMaxWidth ¶
GetMaxWidth returns the style's max width setting. If no value is set 0 is returned.
func (Style) GetPadding ¶
GetPadding returns the style's top, right, bottom, and left padding values, in that order. 0 is returned for unset values.
func (Style) GetPaddingBottom ¶
GetPaddingBottom returns the style's bottom padding. If no value is set 0 is returned.
func (Style) GetPaddingLeft ¶
GetPaddingLeft returns the style's left padding. If no value is set 0 is returned.
func (Style) GetPaddingRight ¶
GetPaddingRight returns the style's right padding. If no value is set 0 is returned.
func (Style) GetPaddingTop ¶
GetPaddingTop returns the style's top padding. If no value is set 0 is returned.
func (Style) GetReverse ¶
GetReverse returns the style's reverse value. If no value is set false is returned.
func (Style) GetStrikethrough ¶
GetStrikethrough returns the style's strikethrough value. If no value is set false is returned.
func (Style) GetStrikethroughSpaces ¶
GetStrikethroughSpaces returns whether or not the style is set to strikethrough spaces. If not value is set false is returned.
func (Style) GetTabWidth ¶
GetTabWidth returns the style's tab width setting. If no value is set 4 is returned which is the implicit default.
func (Style) GetTransform ¶
GetTransform returns the transform set on the style. If no transform is set nil is returned.
func (Style) GetUnderline ¶
GetUnderline returns the style's underline value. If no value is set false is returned.
func (Style) GetUnderlineSpaces ¶
GetUnderlineSpaces returns whether or not the style is set to underline spaces. If not value is set false is returned.
func (Style) GetVerticalBorderSize ¶
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.
func (Style) GetVerticalFrameSize ¶
GetVerticalFrameSize returns the sum of the style's vertical margins, padding and border widths.
Provisional: this method may be renamed.
func (Style) GetVerticalMargins ¶
GetVerticalMargins returns the style's top and bottom margins. Unset values are measured as 0.
func (Style) GetVerticalPadding ¶
GetVerticalPadding returns the style's top and bottom padding. Unset values are measured as 0.
func (Style) GetWidth ¶
GetWidth returns the style's width setting. If no width is set 0 is returned.
func (Style) Height ¶
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.
func (Style) Inherit ¶
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.
func (Style) Inline ¶
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))
func (Style) Italic ¶
Italic sets an italic formatting rule. In some terminal emulators this will render with "reverse" coloring if not italic font variant is available.
func (Style) Margin ¶
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.
func (Style) MarginBackground ¶
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.
func (Style) MarginBottom ¶
MarginBottom sets the value of the bottom margin.
func (Style) MarginLeft ¶
MarginLeft sets the value of the left margin.
func (Style) MarginRight ¶
MarginRight sets the value of the right margin.
func (Style) MaxHeight ¶
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.
func (Style) MaxWidth ¶
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))
func (Style) Padding ¶
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.
func (Style) PaddingBottom ¶
PaddingBottom adds padding to the bottom of the block.
func (Style) PaddingLeft ¶
PaddingLeft adds padding on the left.
func (Style) PaddingRight ¶
PaddingRight adds padding on the right.
func (Style) PaddingTop ¶
PaddingTop adds padding to the top of the block.
func (Style) SetString ¶
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.
func (Style) Strikethrough ¶
Strikethrough sets a strikethrough rule. By default, strikes will not be drawn on whitespace like margins and padding. To change this behavior set StrikethroughSpaces.
func (Style) 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.
func (Style) String ¶
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.
func (Style) TabWidth ¶
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.
func (Style) Transform ¶
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!"
func (Style) Underline ¶
Underline sets an underline rule. By default, underlines will not be drawn on whitespace like margins and padding. To change this behavior set UnderlineSpaces.
func (Style) UnderlineSpaces ¶
UnderlineSpaces determines whether to underline spaces between words. By default, this is true. Spaces can also be underlined without underlining the text itself.
func (Style) UnsetAlign ¶
UnsetAlign removes the horizontal and vertical text alignment style rule, if set.
func (Style) UnsetAlignHorizontal ¶
UnsetAlignHorizontal removes the horizontal text alignment style rule, if set.
func (Style) UnsetAlignVertical ¶
UnsetAlignVertical removes the vertical text alignment style rule, if set.
func (Style) UnsetBackground ¶
UnsetBackground removes the background style rule, if set.
func (Style) UnsetBlink ¶
UnsetBlink removes the blink style rule, if set.
func (Style) UnsetBorderBackground ¶
UnsetBorderBackground removes all border background color styles, if set.
func (Style) UnsetBorderBottom ¶
UnsetBorderBottom removes the border bottom style rule, if set.
func (Style) UnsetBorderBottomBackground ¶
UnsetBorderBottomBackground removes the bottom border background color rule, if set.
func (Style) UnsetBorderBottomForeground ¶
UnsetBorderBottomForeground removes the bottom border foreground color rule, if set.
func (Style) UnsetBorderForeground ¶
UnsetBorderForeground removes all border foreground color styles, if set.
func (Style) UnsetBorderLeft ¶
UnsetBorderLeft removes the border left style rule, if set.
func (Style) UnsetBorderLeftBackground ¶
UnsetBorderLeftBackground removes the left border color rule, if set.
func (Style) UnsetBorderLeftForeground ¶
UnsetBorderLeftForeground removes the left border foreground color rule, if set.
func (Style) UnsetBorderRight ¶
UnsetBorderRight removes the border right style rule, if set.
func (Style) UnsetBorderRightBackground ¶
UnsetBorderRightBackground removes the right border background color rule, if set.
func (Style) UnsetBorderRightForeground ¶
UnsetBorderRightForeground removes the right border foreground color rule, if set.
func (Style) UnsetBorderStyle ¶
UnsetBorderStyle removes the border style rule, if set.
func (Style) UnsetBorderTop ¶
UnsetBorderTop removes the border top style rule, if set.
func (Style) UnsetBorderTopBackground ¶
UnsetBorderTopBackground removes the top border background color rule, if set.
func (Style) UnsetBorderTopBackgroundColor
deprecated
func (Style) UnsetBorderTopForeground ¶
UnsetBorderTopForeground removes the top border foreground color rule, if set.
func (Style) UnsetColorWhitespace ¶
UnsetColorWhitespace removes the rule for coloring padding, if set.
func (Style) UnsetFaint ¶
UnsetFaint removes the faint style rule, if set.
func (Style) UnsetForeground ¶
UnsetForeground removes the foreground style rule, if set.
func (Style) UnsetHeight ¶
UnsetHeight removes the height style rule, if set.
func (Style) UnsetInline ¶
UnsetInline removes the inline style rule, if set.
func (Style) UnsetItalic ¶
UnsetItalic removes the italic style rule, if set.
func (Style) UnsetMarginBackground ¶
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.
func (Style) UnsetMarginBottom ¶
UnsetMarginBottom removes the bottom margin style rule, if set.
func (Style) UnsetMarginLeft ¶
UnsetMarginLeft removes the left margin style rule, if set.
func (Style) UnsetMarginRight ¶
UnsetMarginRight removes the right margin style rule, if set.
func (Style) UnsetMarginTop ¶
UnsetMarginTop removes the top margin style rule, if set.
func (Style) UnsetMargins ¶
UnsetMargins removes all margin style rules.
func (Style) UnsetMaxHeight ¶
UnsetMaxHeight removes the max height style rule, if set.
func (Style) UnsetMaxWidth ¶
UnsetMaxWidth removes the max width style rule, if set.
func (Style) UnsetPadding ¶
UnsetPadding removes all padding style rules.
func (Style) UnsetPaddingBottom ¶
UnsetPaddingBottom removes the bottom padding style rule, if set.
func (Style) UnsetPaddingLeft ¶
UnsetPaddingLeft removes the left padding style rule, if set.
func (Style) UnsetPaddingRight ¶
UnsetPaddingRight removes the right padding style rule, if set.
func (Style) UnsetPaddingTop ¶
UnsetPaddingTop removes the top padding style rule, if set.
func (Style) UnsetReverse ¶
UnsetReverse removes the reverse style rule, if set.
func (Style) UnsetStrikethrough ¶
UnsetStrikethrough removes the strikethrough style rule, if set.
func (Style) UnsetStrikethroughSpaces ¶
UnsetStrikethroughSpaces removes the value set by StrikethroughSpaces.
func (Style) UnsetString ¶
UnsetString sets the underlying string value to the empty string.
func (Style) UnsetTabWidth ¶
UnsetTabWidth removes the tab width style rule, if set.
func (Style) UnsetTransform ¶
UnsetTransform removes the value set by Transform.
func (Style) UnsetUnderline ¶
UnsetUnderline removes the underline style rule, if set.
func (Style) UnsetUnderlineSpaces ¶
UnsetUnderlineSpaces removes the value set by UnderlineSpaces.
func (Style) UnsetWidth ¶
UnsetWidth removes the width style rule, if set.
type WhitespaceOption ¶
type WhitespaceOption func(*whitespace)
WhitespaceOption sets a styling rule for rendering whitespace.
func WithWhitespaceChars ¶
func WithWhitespaceChars(s string) WhitespaceOption
WithWhitespaceChars sets the characters to be rendered in the whitespace.
func WithWhitespaceStyle ¶
func WithWhitespaceStyle(s Style) WhitespaceOption
WithWhitespaceStyle sets the style for the whitespace.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package compat is a compatibility layer for Lip Gloss that provides a way to deal with the hassle of setting up a writer.
|
Package compat is a compatibility layer for Lip Gloss that provides a way to deal with the hassle of setting up a writer. |
Package list allows you to build lists, as simple or complicated as you need.
|
Package list allows you to build lists, as simple or complicated as you need. |
Package tree allows you to build trees, as simple or complicated as you need.
|
Package tree allows you to build trees, as simple or complicated as you need. |