package lipglossimport ()// Set a value on the underlying rules map.func ( *Style) ( propKey, any) {// We don't allow negative integers on any of our other values, so just keep // them at zero or above. We could use uints instead, but the // conversions are a little tedious, so we're sticking with ints for // sake of usability.switch {caseforegroundKey: .fgColor = colorOrNil()casebackgroundKey: .bgColor = colorOrNil()caseunderlineColorKey: .ulColor = colorOrNil()caseunderlineKey: .ul = .(Underline)casewidthKey: .width = max(0, .(int))caseheightKey: .height = max(0, .(int))casealignHorizontalKey: .alignHorizontal = .(Position)casealignVerticalKey: .alignVertical = .(Position)casepaddingTopKey: .paddingTop = max(0, .(int))casepaddingRightKey: .paddingRight = max(0, .(int))casepaddingBottomKey: .paddingBottom = max(0, .(int))casepaddingLeftKey: .paddingLeft = max(0, .(int))casepaddingCharKey: .paddingChar = .(rune)casemarginTopKey: .marginTop = max(0, .(int))casemarginRightKey: .marginRight = max(0, .(int))casemarginBottomKey: .marginBottom = max(0, .(int))casemarginLeftKey: .marginLeft = max(0, .(int))casemarginBackgroundKey: .marginBgColor = colorOrNil()casemarginCharKey: .marginChar = .(rune)caseborderStyleKey: .borderStyle = .(Border)caseborderTopForegroundKey: .borderTopFgColor = colorOrNil()caseborderRightForegroundKey: .borderRightFgColor = colorOrNil()caseborderBottomForegroundKey: .borderBottomFgColor = colorOrNil()caseborderLeftForegroundKey: .borderLeftFgColor = colorOrNil()caseborderForegroundBlendKey: .borderBlendFgColor = .([]color.Color)caseborderForegroundBlendOffsetKey: .borderForegroundBlendOffset = .(int)caseborderTopBackgroundKey: .borderTopBgColor = colorOrNil()caseborderRightBackgroundKey: .borderRightBgColor = colorOrNil()caseborderBottomBackgroundKey: .borderBottomBgColor = colorOrNil()caseborderLeftBackgroundKey: .borderLeftBgColor = colorOrNil()casemaxWidthKey: .maxWidth = max(0, .(int))casemaxHeightKey: .maxHeight = max(0, .(int))casetabWidthKey:// TabWidth is the only property that may have a negative value (and // that negative value can be no less than -1). .tabWidth = .(int)casetransformKey: .transform = .(func(string) string)caselinkKey: .link = .(string)caselinkParamsKey: .linkParams = .(string)default:if , := .(bool); { //nolint:nestifif { .attrs |= int64() } else { .attrs &^= int64() } } elseif , := .(int64); {// bool attrsif &int64() != 0 { .attrs |= int64() } else { .attrs &^= int64() } } }// Set the prop on .props = .props.set()}// setFrom sets the property from another style.func ( *Style) ( propKey, Style) {switch {caseforegroundKey: .set(foregroundKey, .fgColor)casebackgroundKey: .set(backgroundKey, .bgColor)caseunderlineColorKey: .set(underlineColorKey, .ulColor)caseunderlineKey: .set(underlineKey, .ul)casewidthKey: .set(widthKey, .width)caseheightKey: .set(heightKey, .height)casealignHorizontalKey: .set(alignHorizontalKey, .alignHorizontal)casealignVerticalKey: .set(alignVerticalKey, .alignVertical)casepaddingTopKey: .set(paddingTopKey, .paddingTop)casepaddingRightKey: .set(paddingRightKey, .paddingRight)casepaddingBottomKey: .set(paddingBottomKey, .paddingBottom)casepaddingLeftKey: .set(paddingLeftKey, .paddingLeft)casepaddingCharKey: .set(paddingCharKey, .paddingChar)casemarginTopKey: .set(marginTopKey, .marginTop)casemarginRightKey: .set(marginRightKey, .marginRight)casemarginBottomKey: .set(marginBottomKey, .marginBottom)casemarginLeftKey: .set(marginLeftKey, .marginLeft)casemarginBackgroundKey: .set(marginBackgroundKey, .marginBgColor)casemarginCharKey: .set(marginCharKey, .marginChar)caseborderStyleKey: .set(borderStyleKey, .borderStyle)caseborderTopForegroundKey: .set(borderTopForegroundKey, .borderTopFgColor)caseborderRightForegroundKey: .set(borderRightForegroundKey, .borderRightFgColor)caseborderBottomForegroundKey: .set(borderBottomForegroundKey, .borderBottomFgColor)caseborderLeftForegroundKey: .set(borderLeftForegroundKey, .borderLeftFgColor)caseborderForegroundBlendKey: .set(borderForegroundBlendKey, .borderBlendFgColor)caseborderForegroundBlendOffsetKey: .set(borderForegroundBlendOffsetKey, .borderForegroundBlendOffset)caseborderTopBackgroundKey: .set(borderTopBackgroundKey, .borderTopBgColor)caseborderRightBackgroundKey: .set(borderRightBackgroundKey, .borderRightBgColor)caseborderBottomBackgroundKey: .set(borderBottomBackgroundKey, .borderBottomBgColor)caseborderLeftBackgroundKey: .set(borderLeftBackgroundKey, .borderLeftBgColor)casemaxWidthKey: .set(maxWidthKey, .maxWidth)casemaxHeightKey: .set(maxHeightKey, .maxHeight)casetabWidthKey: .set(tabWidthKey, .tabWidth)casetransformKey: .set(transformKey, .transform)default:// Set attributes for set bool properties .set(, .attrs) }}func ( any) color.Color {if , := .(color.Color); {return }returnnil}// Bold sets a bold formatting rule.func ( Style) ( bool) Style { .set(boldKey, )return}// 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) ( bool) Style { .set(italicKey, )return}// 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].func ( Style) ( bool) Style {if {return .UnderlineStyle(UnderlineSingle) }return .UnderlineStyle(UnderlineNone)}// 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.func ( Style) ( Underline) Style { .set(underlineKey, )return}// 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.func ( Style) ( color.Color) Style { .set(underlineColorKey, )return}// 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) ( bool) Style { .set(strikethroughKey, )return}// Reverse sets a rule for inverting foreground and background colors.func ( Style) ( bool) Style { .set(reverseKey, )return}// Blink sets a rule for blinking foreground text.func ( Style) ( bool) Style { .set(blinkKey, )return}// Faint sets a rule for rendering the foreground color in a dimmer shade.func ( Style) ( bool) Style { .set(faintKey, )return}// 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) ( color.Color) Style { .set(foregroundKey, )return}// Background sets a background color.func ( Style) ( color.Color) Style { .set(backgroundKey, )return}// 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.func ( Style) ( int) Style { .set(widthKey, )return}// 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) ( int) Style { .set(heightKey, )return}// 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) ( ...Position) Style {iflen() > 0 { .set(alignHorizontalKey, [0]) }iflen() > 1 { .set(alignVerticalKey, [1]) }return}// AlignHorizontal sets a horizontal text alignment rule.func ( Style) ( Position) Style { .set(alignHorizontalKey, )return}// AlignVertical sets a vertical text alignment rule.func ( Style) ( Position) Style { .set(alignVerticalKey, )return}// 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) ( ...int) Style { , , , , := whichSidesInt(...)if ! {return } .set(paddingTopKey, ) .set(paddingRightKey, ) .set(paddingBottomKey, ) .set(paddingLeftKey, )return}// PaddingLeft adds padding on the left.func ( Style) ( int) Style { .set(paddingLeftKey, )return}// PaddingRight adds padding on the right.func ( Style) ( int) Style { .set(paddingRightKey, )return}// PaddingTop adds padding to the top of the block.func ( Style) ( int) Style { .set(paddingTopKey, )return}// PaddingBottom adds padding to the bottom of the block.func ( Style) ( int) Style { .set(paddingBottomKey, )return}// 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)// ```func ( Style) ( rune) Style { .set(paddingCharKey, )return}// 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) ( bool) Style { .set(colorWhitespaceKey, )return}// 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) ( ...int) Style { , , , , := whichSidesInt(...)if ! {return } .set(marginTopKey, ) .set(marginRightKey, ) .set(marginBottomKey, ) .set(marginLeftKey, )return}// MarginLeft sets the value of the left margin.func ( Style) ( int) Style { .set(marginLeftKey, )return}// MarginRight sets the value of the right margin.func ( Style) ( int) Style { .set(marginRightKey, )return}// MarginTop sets the value of the top margin.func ( Style) ( int) Style { .set(marginTopKey, )return}// MarginBottom sets the value of the bottom margin.func ( Style) ( int) Style { .set(marginBottomKey, )return}// 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) ( color.Color) Style { .set(marginBackgroundKey, )return}// 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.func ( Style) ( rune) Style { .set(marginCharKey, )return}// 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) ( Border, ...bool) Style { .set(borderStyleKey, ) , , , , := whichSidesBool(...)if ! { = true = true = true = true } .set(borderTopKey, ) .set(borderRightKey, ) .set(borderBottomKey, ) .set(borderLeftKey, )return}// 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) ( Border) Style { .set(borderStyleKey, )return}// BorderTop determines whether or not to draw a top border.func ( Style) ( bool) Style { .set(borderTopKey, )return}// BorderRight determines whether or not to draw a right border.func ( Style) ( bool) Style { .set(borderRightKey, )return}// BorderBottom determines whether or not to draw a bottom border.func ( Style) ( bool) Style { .set(borderBottomKey, )return}// BorderLeft determines whether or not to draw a left border.func ( Style) ( bool) Style { .set(borderLeftKey, )return}// 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) ( ...color.Color) Style {iflen() == 0 {return } , , , , := whichSidesColor(...)if ! {return } .set(borderTopForegroundKey, ) .set(borderRightForegroundKey, ) .set(borderBottomForegroundKey, ) .set(borderLeftForegroundKey, )return}// BorderTopForeground set the foreground color for the top of the border.func ( Style) ( color.Color) Style { .set(borderTopForegroundKey, )return}// BorderRightForeground sets the foreground color for the right side of the// border.func ( Style) ( color.Color) Style { .set(borderRightForegroundKey, )return}// BorderBottomForeground sets the foreground color for the bottom of the// border.func ( Style) ( color.Color) Style { .set(borderBottomForegroundKey, )return}// BorderLeftForeground sets the foreground color for the left side of the// border.func ( Style) ( color.Color) Style { .set(borderLeftForegroundKey, )return}// 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"),// )func ( Style) ( ...color.Color) Style {iflen() == 0 {return }// Insufficient colors to use blending, pass to BorderForeground.iflen() == 1 {return .BorderForeground(...) } .set(borderForegroundBlendKey, )return}// 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// └──────────┘// <---------func ( Style) ( int) Style { .set(borderForegroundBlendOffsetKey, )return}// 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) ( ...color.Color) Style {iflen() == 0 {return } , , , , := whichSidesColor(...)if ! {return } .set(borderTopBackgroundKey, ) .set(borderRightBackgroundKey, ) .set(borderBottomBackgroundKey, ) .set(borderLeftBackgroundKey, )return}// BorderTopBackground sets the background color of the top of the border.func ( Style) ( color.Color) Style { .set(borderTopBackgroundKey, )return}// BorderRightBackground sets the background color of right side the border.func ( Style) ( color.Color) Style { .set(borderRightBackgroundKey, )return}// BorderBottomBackground sets the background color of the bottom of the// border.func ( Style) ( color.Color) Style { .set(borderBottomBackgroundKey, )return}// BorderLeftBackground set the background color of the left side of the// border.func ( Style) ( color.Color) Style { .set(borderLeftBackgroundKey, )return}// 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) ( bool) Style { := // copy .set(inlineKey, )return}// 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) ( int) Style { := // copy .set(maxWidthKey, )return}// 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) ( int) Style { := // copy .set(maxHeightKey, )return}// NoTabConversion can be passed to [Style.TabWidth] to disable the replacement// of tabs with spaces at render time.constNoTabConversion = -1// 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) ( int) Style {if <= -1 { = -1 } .set(tabWidthKey, )return}// 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) ( bool) Style { .set(underlineSpacesKey, )return}// 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) ( bool) Style { .set(strikethroughSpacesKey, )return}// 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) ( func(string) string) Style { .set(transformKey, )return}// 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")func ( Style) ( string, ...string) Style { .set(linkKey, )iflen() > 0 { .set(linkParamsKey, strings.Join(, ":")) }return}// whichSidesInt is a helper method for setting values on sides of a block based// on the number of arguments. It follows the CSS shorthand rules for blocks// like margin, padding. and borders. Here are how the rules work://// 0 args: do nothing// 1 arg: all sides// 2 args: top -> bottom// 3 args: top -> horizontal -> bottom// 4 args: top -> right -> bottom -> left// 5+ args: do nothing.func ( ...int) (, , , int, bool) {switchlen() {case1: = [0] = [0] = [0] = [0] = truecase2: //nolint:mnd = [0] = [0] = [1] = [1] = truecase3: //nolint:mnd = [0] = [1] = [1] = [2] = truecase4: //nolint:mnd = [0] = [1] = [2] = [3] = true }return , , , , }// whichSidesBool is like whichSidesInt, except it operates on a series of// boolean values. See the comment on whichSidesInt for details on how this// works.func ( ...bool) (, , , bool, bool) {switchlen() {case1: = [0] = [0] = [0] = [0] = truecase2: //nolint:mnd = [0] = [0] = [1] = [1] = truecase3: //nolint:mnd = [0] = [1] = [1] = [2] = truecase4: //nolint:mnd = [0] = [1] = [2] = [3] = true }return , , , , }// whichSidesColor is like whichSides, except it operates on a series of// boolean values. See the comment on whichSidesInt for details on how this// works.func ( ...color.Color) (, , , color.Color, bool) {switchlen() {case1: = [0] = [0] = [0] = [0] = truecase2: //nolint:mnd = [0] = [0] = [1] = [1] = truecase3: //nolint:mnd = [0] = [1] = [1] = [2] = truecase4: //nolint:mnd = [0] = [1] = [2] = [3] = true }return , , , , }
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)