Documentation
¶
Index ¶
- Variables
- 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 Width(str string) (width int)
- type AdaptiveColor
- type Border
- type Color
- type NoColor
- type Position
- type Style
- func (s Style) Align(p Position) Style
- func (s Style) Background(c TerminalColor) 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) BorderBackgroundColor(c ...TerminalColor) Style
- func (s Style) BorderBottom(v bool) Style
- func (s Style) BorderBottomBackgroundColor(c TerminalColor) Style
- func (s Style) BorderBottomForegroundColor(c TerminalColor) Style
- func (s Style) BorderForegroundColor(c ...TerminalColor) Style
- func (s Style) BorderLeft(v bool) Style
- func (s Style) BorderLeftBackgroundColor(c TerminalColor) Style
- func (s Style) BorderLeftForegroundColor(c TerminalColor) Style
- func (s Style) BorderRight(v bool) Style
- func (s Style) BorderRightBackgroundColor(c TerminalColor) Style
- func (s Style) BorderRightForegroundColor(c TerminalColor) Style
- func (s Style) BorderStyle(b Border) Style
- func (s Style) BorderTop(v bool) Style
- func (s Style) BorderTopBackgroundColor(c TerminalColor) Style
- func (s Style) BorderTopForegroundColor(c TerminalColor) Style
- func (s Style) ColorWhitespace(v bool) Style
- func (s Style) Copy() Style
- func (s Style) Faint(v bool) Style
- func (s Style) Foreground(c TerminalColor) Style
- func (s Style) Height(i int) Style
- func (o 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 TerminalColor) 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(str string) string
- func (s Style) Reverse(v bool) Style
- func (s Style) SetString(str string) Style
- func (s Style) Strikethrough(v bool) Style
- func (s Style) StrikethroughSpaces(v bool) Style
- func (s Style) String() string
- func (s Style) Underline(v bool) Style
- func (s Style) UnderlineSpaces(v bool) Style
- func (s Style) UnsetAlign() Style
- func (s Style) UnsetBackground() Style
- func (s Style) UnsetBlink() Style
- func (s Style) UnsetBold() Style
- func (s Style) UnsetBorderBackgroundColor() Style
- func (s Style) UnsetBorderBottom() Style
- func (s Style) UnsetBorderBottomBackgroundColor() Style
- func (s Style) UnsetBorderBottomForegroundColor() Style
- func (s Style) UnsetBorderColor() Style
- func (s Style) UnsetBorderForegroundColor() Style
- func (s Style) UnsetBorderLeft() Style
- func (s Style) UnsetBorderLeftBackgroundColor() Style
- func (s Style) UnsetBorderLeftForegroundColor() Style
- func (s Style) UnsetBorderRight() Style
- func (s Style) UnsetBorderRightBackgroundColor() Style
- func (s Style) UnsetBorderRightForegroundColor() Style
- func (s Style) UnsetBorderStyle() Style
- func (s Style) UnsetBorderTop() Style
- func (s Style) UnsetBorderTopBackgroundColor() Style
- func (s Style) UnsetBorderTopForegroundColor() 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) UnsetUnderline() Style
- func (s Style) UnsetUnderlineSpaces() Style
- func (s Style) UnsetWidth() Style
- func (s Style) Width(i int) Style
- type TerminalColor
- type WhitespaceOption
Constants ¶
This section is empty.
Variables ¶
var (
ColorProfile termenv.Profile = termenv.ColorProfile()
)
Functions ¶
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 left, right or center you may as well just use the helper constants JoinTop, JoinCenter, and JoinBottom.
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.JoinTop, 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 JoinLeft, JoinCenter, and JoinRight.
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.JoinRight, 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 it's longest line) this will be a noöp.
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 it's newlines) then this will be a noöp.
Types ¶
type AdaptiveColor ¶
AdaptiveColor provides color options for light and dark backgrounds. The appropriate color with be returned at runtime based on the darkness of the terminal background color.
Example usage:
color := lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"}
func (AdaptiveColor) RGBA ¶
func (ac AdaptiveColor) RGBA() (r, g, b, a uint32)
RGBA returns the RGBA value of this color. This satisfies the Go Color interface. Note that on error we return black with 100% opacity, or:
Red: 0x0, Green: 0x0, Blue: 0x0, Alpha: 0xFFFF
This is inline with go-colorful's default behavior.
type Border ¶
type Border struct { Top string Bottom string Left string Right string TopLeft string TopRight string BottomRight string BottomLeft string }
Border contains a series of values which comprise the various parts of a border.
func DoubleBorder ¶
func DoubleBorder() Border
DoubleBorder returns a border comprised of two thin strokes.
func NormalBorder ¶
func NormalBorder() Border
NormalBorder returns a standard-type border with a normal weight and 90 degree corners.
func RoundedBorder ¶
func RoundedBorder() Border
RoundedBorder returns a border with rounded corners.
func ThickBorder ¶
func ThickBorder() Border
Thick border returns a border that's thicker than the one returned by NormalBorder.
type Color ¶
type Color string
Color specifies a color by hex or ANSI value. For example:
ansiColor := lipgloss.Color("21") hexColor := lipgloss.Color("#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.Copy().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 incase the underlying implementation changes.
func (Style) Background ¶
func (s Style) Background(c TerminalColor) Style
Background sets a background color.
func (Style) Border ¶
Border is shorthand for setting a 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) BorderBackgroundColor ¶
func (s Style) BorderBackgroundColor(c ...TerminalColor) Style
BorderBackgroundColor 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) BorderBottomBackgroundColor ¶
func (s Style) BorderBottomBackgroundColor(c TerminalColor) Style
BorderBottomBackgroundColor set the top color of the border.
func (Style) BorderBottomForegroundColor ¶
func (s Style) BorderBottomForegroundColor(c TerminalColor) Style
BorderBottomForegroundColor set the top color of the border.
func (Style) BorderForegroundColor ¶
func (s Style) BorderForegroundColor(c ...TerminalColor) Style
BorderForegroundColor 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) BorderLeftBackgroundColor ¶
func (s Style) BorderLeftBackgroundColor(c TerminalColor) Style
BorderLeftBackgroundColor set the top color of the border.
func (Style) BorderLeftForegroundColor ¶
func (s Style) BorderLeftForegroundColor(c TerminalColor) Style
BorderLeftForegroundColor set the top color of the border.
func (Style) BorderRight ¶
BorderRight determines whether or not to draw a right border.
func (Style) BorderRightBackgroundColor ¶
func (s Style) BorderRightBackgroundColor(c TerminalColor) Style
BorderRightBackgroundColor set the top color of the border.
func (Style) BorderRightForegroundColor ¶
func (s Style) BorderRightForegroundColor(c TerminalColor) Style
BorderRightForegroundColor set the top color 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(), ThickBorder(), and DoubleBorder().
Example:
lipgloss.NewStyle().BorderStyle(lipgloss.ThickBorder())
func (Style) BorderTopBackgroundColor ¶
func (s Style) BorderTopBackgroundColor(c TerminalColor) Style
BorderTopBackgroundColor set the top color of the border.
func (Style) BorderTopForegroundColor ¶
func (s Style) BorderTopForegroundColor(c TerminalColor) Style
BorderTopForegroundColor set the top color of the border.
func (Style) ColorWhitespace ¶
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.
func (Style) Foreground ¶
func (s Style) Foreground(c TerminalColor) Style
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) Height ¶
Height sets the width 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 takes values from the style in the argument applies them to this style, overwriting existing definitions. Only values explicitly set on the style in argument will be applied.
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().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 ¶
func (s Style) MarginBackground(c TerminalColor) Style
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 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.
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 ¶
BottomPadding adds padding to the bottom of the block.
func (Style) PaddingLeft ¶
LeftPadding adds padding on the left.
func (Style) PaddingRight ¶
Right Padding adds padding on the right.
func (Style) PaddingTop ¶
TopPadding addds 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 renderStrikethroughOnSpaces.
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) Underline ¶
Underine sets an underline rule. By default, underlines will not be drawn on whitespace like margins and padding. To change this behavior set renderUnderlinesOnSpaces.
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 text alignment style rule, if set.
func (Style) UnsetBackground ¶
UnsetBackground removes the background style rule, if set.
func (Style) UnsetBlink ¶
UnsetBlink removes the bold style rule, if set.
func (Style) UnsetBorderBackgroundColor ¶
UnsetBorderBackgroundColor removes all border background color styles, if set.
func (Style) UnsetBorderBottom ¶
UnsetBorderTop removes the border bottom style rule, if set.
func (Style) UnsetBorderBottomBackgroundColor ¶
UnsetBorderBottomBackgroundColor removes the top border background color rule, if set.
func (Style) UnsetBorderBottomForegroundColor ¶
UnsetBorderBottomForegroundColor removes the top border foreground color rule, if set.
func (Style) UnsetBorderColor ¶
UnsetBorderColor removes all border foreground and background colors, if set.
func (Style) UnsetBorderForegroundColor ¶
UnsetBorderForegroundColor removes all border foreground colors styles, if set.
func (Style) UnsetBorderLeft ¶
UnsetBorderLeft removes the border left style rule, if set.
func (Style) UnsetBorderLeftBackgroundColor ¶
UnsetBorderLeftBackgroundColor removes the top border color rule, if set.
func (Style) UnsetBorderLeftForegroundColor ¶
UnsetBorderLeftForegroundColor removes the top border foreground color rule, if set.
func (Style) UnsetBorderRight ¶
UnsetBorderTop removes the border right style rule, if set.
func (Style) UnsetBorderRightBackgroundColor ¶
UnsetBorderRightBackgroundColor removes the top border background color rule, if set.
func (Style) UnsetBorderRightForegroundColor ¶
UnsetBorderRightForgroundColor removes the top 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) UnsetBorderTopBackgroundColor ¶
UnsetBorderTopBackgroundColor removes the top border background color rule, if set.
func (Style) UnsetBorderTopForegroundColor ¶
UnsetBorderTopForegroundColor 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 ¶
UnsetForegroundremoves 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. The margin's background color is set from the background color of another style during inheritance.
func (Style) UnsetMarginBottom ¶
UnsetBottomMargin removes the bottom margin style rule, if set.
func (Style) UnsetMarginLeft ¶
UnsetLeftMargin removes the left margin style rule, if set.
func (Style) UnsetMarginRight ¶
UnsetRightMargin removes the right margin style rule, if set.
func (Style) UnsetMarginTop ¶
UnsetTopMargin removes the top margin style rule, if set.
func (Style) UnsetMargins ¶
UnsetMargins removes all margin style rules.
func (Style) UnsetMaxHeight ¶
UnsetMaxHeight removes the max width 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 ¶
UnsetBottomPadding removes the bottom style rule, if set.
func (Style) UnsetPaddingLeft ¶
UnsetLeftPadding removes the left padding style rule, if set.
func (Style) UnsetPaddingRight ¶
UnsetRightPadding removes the left padding style rule, if set.
func (Style) UnsetPaddingTop ¶
UnsetTopPadding 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 ¶
UnsetUnderlineSpaces removes the value set by UnsetStrikethroughSpaces.
func (Style) UnsetString ¶
UnsetString sets the underlying string value to the empty string.
func (Style) UnsetUnderline ¶
UnsetItalic 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 TerminalColor ¶
type TerminalColor interface { RGBA() (r, g, b, a uint32) // contains filtered or unexported methods }
TerminalColor is a color intended to be rendered in the terminal. It satisfies the Go color.Color interface.
type WhitespaceOption ¶
type WhitespaceOption func(*whitespace)
WhiteSpaceOption sets a styling rule for rendering whitespace.
func WithWhitespaceBackground ¶
func WithWhitespaceBackground(c TerminalColor) WhitespaceOption
WithWhiteSpaceBackground sets the background color of the whitespace.
func WithWhitespaceChars ¶
func WithWhitespaceChars(s string) WhitespaceOption
WithWhitespaceChars sets the characters to be rendered in the whitespace.
func WithWhitespaceForeground ¶
func WithWhitespaceForeground(c TerminalColor) WhitespaceOption
WithWhitespaceForeground sets the color of the characters in the whitespace.