Documentation
¶
Overview ¶
Package lipgloss 为美观的终端布局提供样式定义。专为 TUI(终端用户界面)设计。
Index ¶
- Constants
- func ColorProfile() termenv.Profile
- func HasDarkBackground() bool
- 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 SetColorProfile(p termenv.Profile)
- func SetDefaultRenderer(r *Renderer)
- func SetHasDarkBackground(b bool)
- func Size(str string) (width, height int)
- func StyleRanges(s string, ranges ...Range) string
- func StyleRunes(str string, indices []int, matched, unmatched Style) string
- func Width(str string) (width int)
- type ANSIColor
- type AdaptiveColor
- type Border
- type Color
- type CompleteAdaptiveColor
- type CompleteColor
- type NoColor
- type Position
- type Range
- type Renderer
- func (r *Renderer) ColorProfile() termenv.Profile
- func (r *Renderer) HasDarkBackground() bool
- func (r *Renderer) NewStyle() Style
- func (r *Renderer) Output() *termenv.Output
- func (r *Renderer) Place(width, height int, hPos, vPos Position, str string, opts ...WhitespaceOption) string
- func (r *Renderer) PlaceHorizontal(width int, pos Position, str string, opts ...WhitespaceOption) string
- func (r *Renderer) PlaceVertical(height int, pos Position, str string, opts ...WhitespaceOption) string
- func (r *Renderer) SetColorProfile(p termenv.Profile)
- func (r *Renderer) SetHasDarkBackground(b bool)
- func (r *Renderer) SetOutput(o *termenv.Output)
- 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 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) BorderBackground(c ...TerminalColor) Style
- func (s Style) BorderBottom(v bool) Style
- func (s Style) BorderBottomBackground(c TerminalColor) Style
- func (s Style) BorderBottomForeground(c TerminalColor) Style
- func (s Style) BorderForeground(c ...TerminalColor) Style
- func (s Style) BorderLeft(v bool) Style
- func (s Style) BorderLeftBackground(c TerminalColor) Style
- func (s Style) BorderLeftForeground(c TerminalColor) Style
- func (s Style) BorderRight(v bool) Style
- func (s Style) BorderRightBackground(c TerminalColor) Style
- func (s Style) BorderRightForeground(c TerminalColor) Style
- func (s Style) BorderStyle(b Border) Style
- func (s Style) BorderTop(v bool) Style
- func (s Style) BorderTopBackground(c TerminalColor) Style
- func (s Style) BorderTopForeground(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) GetAlign() Position
- func (s Style) GetAlignHorizontal() Position
- func (s Style) GetAlignVertical() Position
- func (s Style) GetBackground() TerminalColor
- 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() TerminalColor
- func (s Style) GetBorderBottomForeground() TerminalColor
- func (s Style) GetBorderBottomSize() int
- func (s Style) GetBorderLeft() bool
- func (s Style) GetBorderLeftBackground() TerminalColor
- func (s Style) GetBorderLeftForeground() TerminalColor
- func (s Style) GetBorderLeftSize() int
- func (s Style) GetBorderRight() bool
- func (s Style) GetBorderRightBackground() TerminalColor
- func (s Style) GetBorderRightForeground() TerminalColor
- func (s Style) GetBorderRightSize() int
- func (s Style) GetBorderStyle() Border
- func (s Style) GetBorderTop() bool
- func (s Style) GetBorderTopBackground() TerminalColor
- func (s Style) GetBorderTopForeground() TerminalColor
- func (s Style) GetBorderTopSize() int
- func (s Style) GetBorderTopWidth() int
- func (s Style) GetColorWhitespace() bool
- func (s Style) GetFaint() bool
- func (s Style) GetForeground() TerminalColor
- 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 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(strs ...string) string
- func (s Style) Renderer(r *Renderer) Style
- 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() Style
- 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 TerminalColor
- type WhitespaceOption
Constants ¶
const NoTabConversion = -1
NoTabConversion 可以传递给 Style.TabWidth 以在渲染时禁用制表符替换为空格。
Variables ¶
This section is empty.
Functions ¶
func Height ¶
Height 返回字符串在单元格中的高度。这只是通过计算 \n 字符来完成的。如果您的字符串使用 \r\n 作为换行符,您应该先将它们转换为 \n,或者简单地编写一个单独的函数来测量高度。
func JoinHorizontal ¶
JoinHorizontal 是一个实用函数,用于沿着垂直轴水平连接两个可能多行的字符串。第一个参数是位置,0 表示完全在顶部,1 表示完全在底部。
如果你只是想对齐到顶部、中心或底部,你可以直接使用辅助常量 Top、Center 和 Bottom。
示例:
blockB := "...\n...\n..." blockA := "...\n...\n...\n...\n..." // 从顶部 20% 处连接 str := lipgloss.JoinHorizontal(0.2, blockA, blockB) // 在顶部边缘连接 str := lipgloss.JoinHorizontal(lipgloss.Top, blockA, blockB)
func JoinVertical ¶
JoinVertical 是一个实用函数,用于沿着水平轴垂直连接两个可能多行的字符串。第一个参数是位置,0 表示完全在左侧,1 表示完全在右侧。
如果你只是想对齐到左侧、中心或右侧,你可以直接使用辅助常量 Left、Center 和 Right。
示例:
blockB := "...\n...\n..." blockA := "...\n...\n...\n...\n..." // 从左侧 20% 处连接 str := lipgloss.JoinVertical(0.2, blockA, blockB) // 在右侧边缘连接 str := lipgloss.JoinVertical(lipgloss.Right, blockA, blockB)
func Place ¶
func Place(width, height int, hPos, vPos Position, str string, opts ...WhitespaceOption) string
Place 将字符串或文本块垂直放置在给定宽度或高度的无样式框中。
func PlaceHorizontal ¶
func PlaceHorizontal(width int, pos Position, str string, opts ...WhitespaceOption) string
PlaceHorizontal 将字符串或文本块水平放置在给定宽度的无样式块中。如果给定宽度短于字符串的最大宽度(由其最长行测量),则此操作将无效。
func PlaceVertical ¶
func PlaceVertical(height int, pos Position, str string, opts ...WhitespaceOption) string
PlaceVertical 将字符串或文本块垂直放置在给定高度的无样式块中。如果给定高度短于字符串的高度(由其换行符测量),则此操作将无效。
func SetColorProfile ¶
SetColorProfile 在默认渲染器上设置颜色配置文件。此函数主要用于测试目的,以便您可以确保针对特定配置文件进行测试。
在测试之外,您可能不想使用此函数,因为颜色配置文件会检测并缓存终端的颜色能力,并选择最佳可用配置文件。
可用的颜色配置文件有:
termenv.Ascii // 无颜色,1位 termenv.ANSI // 16 颜色,4位 termenv.ANSI256 // 256 颜色,8位 termenv.TrueColor // 16,777,216 颜色,24位
此函数是线程安全的。
func SetHasDarkBackground ¶
func SetHasDarkBackground(b bool)
SetHasDarkBackground 为默认渲染器设置背景颜色检测值。此函数主要用于测试目的,以便您可以确保针对特定背景颜色设置进行测试。
在测试之外,您可能不想使用此函数,因为背景值会自动检测并针对终端当前的背景颜色设置进行缓存。
此函数是线程安全的。
func StyleRanges ¶
StyleRanges 允许对给定字符串的不同范围应用不同的样式。 该函数会考虑现有的样式。 范围不应重叠。
func StyleRunes ¶
StyleRunes 将给定样式应用于字符串中给定索引处的符文。 注意,您必须为匹配和未匹配的符文都提供样式选项。超出范围的索引将被忽略。
Types ¶
type ANSIColor ¶
type ANSIColor uint
ANSIColor 是一种通过 ANSI 颜色值指定的颜色。它只是更通用的 Color 函数的语法糖。无效的颜色将渲染为黑色。
示例用法:
// 这两个语句是等价的。
colorA := lipgloss.ANSIColor(21)
colorB := lipgloss.Color("21")
type AdaptiveColor ¶
AdaptiveColor 为浅色和深色背景提供颜色选项。根据终端背景颜色的明暗程度, 将在运行时返回适当的颜色。
示例用法:
color := lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"}
func (AdaptiveColor) RGBA ¶
func (ac AdaptiveColor) RGBA() (r, g, b, a uint32)
RGBA 返回此颜色的 RGBA 值。这满足 Go 的 Color 接口。请注意,在出错时我们返回不透明度为 100% 的黑色,即:
红色:0x0,绿色:0x0,蓝色:0x0,透明度:0xFFFF。
已弃用。
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 包含一系列值,这些值组成了边框的各个部分。
func HiddenBorder ¶
func HiddenBorder() Border
HiddenBorder 返回一个渲染为一系列单单元格空格的边框。它在你想要移除标准边框但保持布局定位的情况下很有用。 也就是说,你仍然可以为隐藏的边框应用背景颜色。
func InnerHalfBlockBorder ¶
func InnerHalfBlockBorder() Border
InnerHalfBlockBorder 返回一个位于框架内部的半块边框。
func MarkdownBorder ¶
func MarkdownBorder() Border
MarkdownBorder 返回一个 Markdown 风格的表格边框。
为了获得最佳效果,请确保禁用顶部和底部边框。这将确保输出是有效的 Markdown。
table.New().Border(lipgloss.MarkdownBorder()).BorderTop(false).BorderBottom(false)
func OuterHalfBlockBorder ¶
func OuterHalfBlockBorder() Border
OuterHalfBlockBorder 返回一个位于框架外部的半块边框。
func (Border) GetBottomSize ¶
GetBottomSize 返回底部边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。 如果底部边缘不存在边框,则返回 0。
func (Border) GetLeftSize ¶
GetLeftSize 返回左侧边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。 如果左侧边缘不存在边框,则返回 0。
func (Border) GetRightSize ¶
GetRightSize 返回右侧边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。 如果右侧边缘不存在边框,则返回 0。
func (Border) GetTopSize ¶
GetTopSize 返回顶部边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。 如果顶部边缘不存在边框,则返回 0。
type Color ¶
type Color string
Color 通过十六进制或 ANSI 值指定颜色。例如:
ansiColor := lipgloss.Color("21")
hexColor := lipgloss.Color("#0000ff")
type CompleteAdaptiveColor ¶
type CompleteAdaptiveColor struct {
Light CompleteColor
Dark CompleteColor
}
CompleteAdaptiveColor 为 truecolor、ANSI256 和 ANSI 颜色配置文件指定精确的值, 并为浅色和深色背景提供单独的选项。不会执行自动颜色降级。
func (CompleteAdaptiveColor) RGBA ¶
func (cac CompleteAdaptiveColor) RGBA() (r, g, b, a uint32)
RGBA 返回此颜色的 RGBA 值。这满足 Go 的 Color 接口。请注意,在出错时我们返回不透明度为 100% 的黑色,即:
红色:0x0,绿色:0x0,蓝色:0x0,透明度:0xFFFF。
已弃用。
type CompleteColor ¶
CompleteColor 为 truecolor、ANSI256 和 ANSI 颜色配置文件指定精确的值。不会执行自动颜色降级。
func (CompleteColor) RGBA ¶
func (c CompleteColor) RGBA() (r, g, b, a uint32)
RGBA 返回此颜色的 RGBA 值。这满足 Go 的 Color 接口。请注意,在出错时我们返回不透明度为 100% 的黑色,即:
红色:0x0,绿色:0x0,蓝色:0x0,透明度:0xFFFF。
已弃用。
type NoColor ¶
type NoColor struct{}
NoColor 用于指定不存在颜色样式。当此选项激活时,前景色将使用终端的默认文本颜色渲染, 而背景色将完全不绘制。
示例用法:
var style = someStyle.Background(lipgloss.NoColor{})
type Position ¶
type Position float64
Position 表示沿着水平或垂直轴的位置。它用于涉及轴的情况,如对齐、连接、放置等。
值为 0 表示开始(左侧或顶部),1 表示结束(右侧或底部)。0.5 表示中心。
此包中提供了常量 Top、Bottom、Center、Left 和 Right,可用于提高可读性。
type Range ¶
Range 用于与 StyleRanges 一起使用。
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer 是 lipgloss 终端渲染器。
func NewRenderer ¶
func NewRenderer(w io.Writer, opts ...termenv.OutputOption) *Renderer
NewRenderer 创建一个新的 Renderer。
w 将用于确定终端的颜色能力。
func (*Renderer) ColorProfile ¶
ColorProfile 返回检测到的 termenv 颜色配置文件。
func (*Renderer) HasDarkBackground ¶
HasDarkBackground 返回渲染器是否将渲染到深色背景。深色背景可以自动检测,也可以在渲染器上显式设置。
func (*Renderer) NewStyle ¶
NewStyle 返回一个新的空 Style。虽然它是 Style{} 原始类型的语法糖,但建议使用此函数创建样式,以防底层实现发生变化。它接受一个可选的字符串值作为此样式的底层字符串值。
func (*Renderer) Place ¶
func (r *Renderer) Place(width, height int, hPos, vPos Position, str string, opts ...WhitespaceOption) string
Place 将字符串或文本块垂直放置在给定宽度或高度的无样式框中。
func (*Renderer) PlaceHorizontal ¶
func (r *Renderer) PlaceHorizontal(width int, pos Position, str string, opts ...WhitespaceOption) string
PlaceHorizontal 将字符串或文本块水平放置在给定宽度的无样式块中。如果给定宽度短于字符串的最大宽度(由其最长行测量),则此操作将无效。
func (*Renderer) PlaceVertical ¶
func (r *Renderer) PlaceVertical(height int, pos Position, str string, opts ...WhitespaceOption) string
PlaceVertical 将字符串或文本块垂直放置在给定高度的无样式块中。如果给定高度短于字符串的高度(由其换行符测量),则此操作将无效。
func (*Renderer) SetColorProfile ¶
SetColorProfile 在渲染器上设置颜色配置文件。此函数主要用于测试目的,以便您可以确保针对特定配置文件进行测试。
在测试之外,您可能不想使用此函数,因为颜色配置文件会检测并缓存终端的颜色能力,并选择最佳可用配置文件。
可用的颜色配置文件有:
termenv.Ascii // 无颜色,1位 termenv.ANSI // 16 颜色,4位 termenv.ANSI256 // 256 颜色,8位 termenv.TrueColor // 16,777,216 颜色,24位
此函数是线程安全的。
func (*Renderer) SetHasDarkBackground ¶
SetHasDarkBackground 在渲染器上设置背景颜色检测值。此函数主要用于测试目的,以便您可以确保针对特定背景颜色设置进行测试。
在测试之外,您可能不想使用此函数,因为背景值会自动检测并针对终端当前的背景颜色设置进行缓存。
此函数是线程安全的。
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style 包含一组规则,这些规则共同构成一个完整的样式。
func NewStyle ¶
func NewStyle() Style
NewStyle 返回一个新的空 Style。虽然它是 Style{} 原始类型的语法糖,但建议使用此函数创建样式,以防底层实现发生变化。它接受一个可选的字符串值作为此样式的底层字符串值。
func (Style) AlignHorizontal ¶
AlignHorizontal 设置水平文本对齐规则。
func (Style) AlignVertical ¶
AlignVertical 设置垂直文本对齐规则。
func (Style) Border ¶
Border 是同时设置边框样式和哪些边应该有边框的简写方法。可变参数 sides 的工作方式如下:
使用一个值时,值应用于所有边。
使用两个值时,值按顺序应用于垂直和水平边。
使用三个值时,值按顺序应用于顶部边、水平边和底部边。
使用四个值时,值按顺时针顺序应用,从顶部边开始,然后是右边,接着是底部,最后是左边。
使用超过四个参数时,边框将应用于所有边。
示例:
// 仅应用边框到顶部和底部 lipgloss.NewStyle().Border(lipgloss.NormalBorder(), true, false) // 仅应用圆角边框到右边和底部 lipgloss.NewStyle().Border(lipgloss.RoundedBorder(), false, true, true, false)
func (Style) BorderBackground ¶
func (s Style) BorderBackground(c ...TerminalColor) Style
BorderBackground 是一次性设置所有边框背景颜色的简写函数。参数的工作方式如下:
使用一个参数时,参数应用于所有边。
使用两个参数时,参数按顺序应用于垂直和水平边。
使用三个参数时,参数按顺序应用于顶部边、水平边和底部边。
使用四个参数时,参数按顺时针顺序应用,从顶部边开始,然后是右边,接着是底部,最后是左边。
使用超过四个参数时,将不设置任何内容。
func (Style) BorderBottomBackground ¶
func (s Style) BorderBottomBackground(c TerminalColor) Style
BorderBottomBackground 设置边框底部的背景颜色。
func (Style) BorderBottomForeground ¶
func (s Style) BorderBottomForeground(c TerminalColor) Style
BorderBottomForeground 设置边框底部的前景颜色。
func (Style) BorderForeground ¶
func (s Style) BorderForeground(c ...TerminalColor) Style
BorderForeground 是一次性设置所有边框前景颜色的简写函数。参数的工作方式如下:
使用一个参数时,参数应用于所有边。
使用两个参数时,参数按顺序应用于垂直和水平边。
使用三个参数时,参数按顺序应用于顶部边、水平边和底部边。
使用四个参数时,参数按顺时针顺序应用,从顶部边开始,然后是右边,接着是底部,最后是左边。
使用超过四个参数时,将不设置任何内容。
func (Style) BorderLeftBackground ¶
func (s Style) BorderLeftBackground(c TerminalColor) Style
BorderLeftBackground 设置边框左侧的背景颜色。
func (Style) BorderLeftForeground ¶
func (s Style) BorderLeftForeground(c TerminalColor) Style
BorderLeftForeground 设置边框左侧的前景颜色。
func (Style) BorderRightBackground ¶
func (s Style) BorderRightBackground(c TerminalColor) Style
BorderRightBackground 设置边框右侧的背景颜色。
func (Style) BorderRightForeground ¶
func (s Style) BorderRightForeground(c TerminalColor) Style
BorderRightForeground 设置边框右侧的前景颜色。
func (Style) BorderStyle ¶
BorderStyle 定义样式上的边框。Border 包含一系列边框边和角的定义。
请注意,如果在设置边框样式时未为任何边设置边框可见性,则在渲染期间将为所有边启用边框。
您可以根据需要定义边框字符,不过包含了几种默认样式:NormalBorder()、RoundedBorder()、BlockBorder()、 OuterHalfBlockBorder()、InnerHalfBlockBorder()、ThickBorder() 和 DoubleBorder()。
示例:
lipgloss.NewStyle().BorderStyle(lipgloss.ThickBorder())
func (Style) BorderTopBackground ¶
func (s Style) BorderTopBackground(c TerminalColor) Style
BorderTopBackground 设置边框顶部的背景颜色。
func (Style) BorderTopForeground ¶
func (s Style) BorderTopForeground(c TerminalColor) Style
BorderTopForeground 设置边框顶部的前景颜色。
func (Style) ColorWhitespace ¶
ColorWhitespace 确定是否应将背景颜色应用于内边距。默认情况下,这是 true,因为这很可能是期望和预期的行为,但可以为某些图形效果禁用它。
已弃用:只需使用边距和内边距。
func (Style) Foreground ¶
func (s Style) Foreground(c TerminalColor) Style
Foreground 设置前景颜色。
// 将前景设置为蓝色
s := lipgloss.NewStyle().Foreground(lipgloss.Color("#0000ff"))
// 移除前景颜色
s.Foreground(lipgloss.NoColor)
func (Style) GetAlignHorizontal ¶
GetAlignHorizontal 返回样式的隐式水平对齐设置。如果未设置对齐,则返回 Position.Left。
func (Style) GetAlignVertical ¶
GetAlignVertical 返回样式的隐式垂直对齐设置。如果未设置对齐,则返回 Position.Top。
func (Style) GetBackground ¶
func (s Style) GetBackground() TerminalColor
GetBackground 返回样式的背景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorder ¶
GetBorder 返回样式的边框样式(类型为 Border)以及上、右、下、左的值,按此顺序。如果未设置边框样式,则返回 Border{}。对于所有其他未设置的值,返回 false。
func (Style) GetBorderBottom ¶
GetBorderBottom 返回样式的下边框设置。如果未设置值,则返回 false。
func (Style) GetBorderBottomBackground ¶
func (s Style) GetBorderBottomBackground() TerminalColor
GetBorderBottomBackground 返回样式的下边框背景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorderBottomForeground ¶
func (s Style) GetBorderBottomForeground() TerminalColor
GetBorderBottomForeground 返回样式的下边框前景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorderBottomSize ¶
GetBorderBottomSize 返回下边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。如果左边缘不存在边框,则返回 0。
func (Style) GetBorderLeft ¶
GetBorderLeft 返回样式的左边框设置。如果未设置值,则返回 false。
func (Style) GetBorderLeftBackground ¶
func (s Style) GetBorderLeftBackground() TerminalColor
GetBorderLeftBackground 返回样式的左边框背景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorderLeftForeground ¶
func (s Style) GetBorderLeftForeground() TerminalColor
GetBorderLeftForeground 返回样式的左边框前景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorderLeftSize ¶
GetBorderLeftSize 返回左边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。如果左边缘不存在边框,则返回 0。
func (Style) GetBorderRight ¶
GetBorderRight 返回样式的右边框设置。如果未设置值,则返回 false。
func (Style) GetBorderRightBackground ¶
func (s Style) GetBorderRightBackground() TerminalColor
GetBorderRightBackground 返回样式的右边框背景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorderRightForeground ¶
func (s Style) GetBorderRightForeground() TerminalColor
GetBorderRightForeground 返回样式的右边框前景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorderRightSize ¶
GetBorderRightSize 返回右边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。如果右边缘不存在边框,则返回 0。
func (Style) GetBorderStyle ¶
GetBorderStyle 返回样式的边框样式(类型为 Border)。如果未设置值,则返回 Border{}。
func (Style) GetBorderTop ¶
GetBorderTop 返回样式的上边框设置。如果未设置值,则返回 false。
func (Style) GetBorderTopBackground ¶
func (s Style) GetBorderTopBackground() TerminalColor
GetBorderTopBackground 返回样式的上边框背景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorderTopForeground ¶
func (s Style) GetBorderTopForeground() TerminalColor
GetBorderTopForeground 返回样式的上边框前景色。如果未设置值,则返回 NoColor{}。
func (Style) GetBorderTopSize ¶
GetBorderTopSize 返回上边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。如果上边缘不存在边框,则返回 0。
func (Style) GetBorderTopWidth ¶
GetBorderTopWidth 返回上边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。如果上边缘不存在边框,则返回 0。
已弃用:此函数只是调用 Style.GetBorderTopSize。
func (Style) GetColorWhitespace ¶
GetColorWhitespace 返回样式的空白着色设置。如果未设置值,则返回 false。
func (Style) GetForeground ¶
func (s Style) GetForeground() TerminalColor
GetForeground 返回样式的前景色。如果未设置值,则返回 NoColor{}。
func (Style) GetFrameSize ¶
GetFrameSize 返回水平和垂直方向的外边距、内边距和边框宽度的总和。
func (Style) GetHorizontalBorderSize ¶
GetHorizontalBorderSize 返回水平边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。如果水平边缘不存在边框,则返回 0。
func (Style) GetHorizontalMargins ¶
GetHorizontalMargins 返回样式的左右外边距。未设置的值被视为 0。
func (Style) GetHorizontalPadding ¶
GetHorizontalPadding 返回样式的左右内边距。未设置的值被视为 0。
func (Style) GetMarginBottom ¶
GetMarginBottom 返回样式的下边距。如果未设置值,则返回 0。
func (Style) GetMarginLeft ¶
GetMarginLeft 返回样式的左边距。如果未设置值,则返回 0。
func (Style) GetMarginRight ¶
GetMarginRight 返回样式的右边距。如果未设置值,则返回 0。
func (Style) GetMaxHeight ¶
GetMaxHeight 返回样式的最大高度设置。如果未设置值,则返回 0。
func (Style) GetPadding ¶
GetPadding 返回样式的上、右、下、左内边距值,按此顺序。对于未设置的值,返回 0。
func (Style) GetPaddingBottom ¶
GetPaddingBottom 返回样式的下内边距。如果未设置值,则返回 0。
func (Style) GetPaddingLeft ¶
GetPaddingLeft 返回样式的左内边距。如果未设置值,则返回 0。
func (Style) GetPaddingRight ¶
GetPaddingRight 返回样式的右内边距。如果未设置值,则返回 0。
func (Style) GetPaddingTop ¶
GetPaddingTop 返回样式的上内边距。如果未设置值,则返回 0。
func (Style) GetStrikethrough ¶
GetStrikethrough 返回样式的删除线值。如果未设置值,则返回 false。
func (Style) GetStrikethroughSpaces ¶
GetStrikethroughSpaces 返回样式是否设置为删除线空格。如果未设置值,则返回 false。
func (Style) GetTabWidth ¶
GetTabWidth 返回样式的制表符宽度设置。如果未设置值,则返回 4,这是隐式默认值。
func (Style) GetTransform ¶
GetTransform 返回样式上设置的转换器。如果未设置转换器,则返回 nil。
func (Style) GetUnderline ¶
GetUnderline 返回样式的下划线值。如果未设置值,则返回 false。
func (Style) GetUnderlineSpaces ¶
GetUnderlineSpaces 返回样式是否设置为下划线空格。如果未设置值,则返回 false。
func (Style) GetVerticalBorderSize ¶
GetVerticalBorderSize 返回垂直边框的宽度。如果边框包含宽度不同的符文,则返回最宽的符文。如果垂直边缘不存在边框,则返回 0。
func (Style) GetVerticalMargins ¶
GetVerticalMargins 返回样式的上下外边距。未设置的值被视为 0。
func (Style) GetVerticalPadding ¶
GetVerticalPadding 返回样式的上下内边距。未设置的值被视为 0。
func (Style) Inherit ¶
Inherit 通过从参数样式中复制每个显式设置的值到本样式(如果本样式尚未显式设置该值),来将参数中的样式覆盖到本样式上。现有设置的值保持不变,不会被覆盖。
边距、内边距和底层字符串值不会被继承。
func (Style) Inline ¶
Inline 使渲染输出为一行,并禁用边距、内边距和边框的渲染。当您需要样式仅应用于字体渲染,而不希望它更改任何物理尺寸时,这很有用。它与 Style.MaxWidth 配合使用效果良好。
因为这旨在在渲染时使用,所以此方法不会修改样式,而是返回一个副本。
示例:
var userInput string = "..."
var userStyle = text.Style{ /* ... */ }
fmt.Println(userStyle.Inline(true).Render(userInput))
func (Style) Margin ¶
Margin 是一次性设置所有边边距的简写方法。
使用一个参数时,值应用于所有边。
使用两个参数时,值按顺序应用于垂直和水平边。
使用三个参数时,值按顺序应用于顶部边、水平边和底部边。
使用四个参数时,值按顺时针顺序应用,从顶部边开始,然后是右边,接着是底部,最后是左边。
使用超过四个参数时,不会添加边距。
func (Style) MarginBackground ¶
func (s Style) MarginBackground(c TerminalColor) Style
MarginBackground 设置边距的背景颜色。请注意,当从具有背景颜色的样式继承时,这也会被设置。在这种情况下,该样式上的背景颜色将设置此样式上的边距颜色。
func (Style) MaxHeight ¶
MaxHeight 对给定样式应用最大高度。这在渲染时强制特定高度时很有用,特别是对于任意字符串和样式。
因为这旨在在渲染时使用,所以此方法不会修改样式,而是返回一个副本。
func (Style) MaxWidth ¶
MaxWidth 对给定样式应用最大宽度。这在渲染时强制特定宽度时很有用,特别是对于任意字符串和样式。
因为这旨在在渲染时使用,所以此方法不会修改样式,而是返回一个副本。
示例:
var userInput string = "..."
var userStyle = text.Style{ /* ... */ }
fmt.Println(userStyle.MaxWidth(16).Render(userInput))
func (Style) Padding ¶
Padding 是一次性设置所有边内边距的简写方法。
使用一个参数时,值应用于所有边。
使用两个参数时,值按顺序应用于垂直和水平边。
使用三个参数时,值按顺序应用于顶部边、水平边和底部边。
使用四个参数时,值按顺时针顺序应用,从顶部边开始,然后是右边,接着是底部,最后是左边。
使用超过四个参数时,不会添加内边距。
func (Style) SetString ¶
SetString 设置此样式的底层字符串值。底层字符串设置后要渲染一次,请使用 Style.String。此方法在需要 stringer 实现的情况下很方便,例如在使用 fmt.Sprintf 时。您也可以简单地定义一个样式并使用 Style.Render 直接渲染字符串。
func (Style) Strikethrough ¶
Strikethrough 设置删除线规则。默认情况下,删除线不会绘制在边距和内边距等空白处。要更改此行为,请设置 StrikethroughSpaces。
func (Style) StrikethroughSpaces ¶
StrikethroughSpaces 确定是否对单词之间的空格应用删除线。默认情况下,这是 true。也可以在不删除线文本本身的情况下对空格应用删除线。
func (Style) String ¶
String 为 Style 实现 stringer 接口,基于此样式中的规则返回渲染结果。使用此方法之前,必须使用 Style.SetString 设置底层字符串值。
func (Style) TabWidth ¶
TabWidth 设置制表符 (/t) 应渲染为的空格数。当设置为 0 时,制表符将被移除。要完全禁用制表符替换为空格,请将此设置为 NoTabConversion。
默认情况下,制表符将被替换为 4 个空格。
func (Style) Transform ¶
Transform 在渲染时对字符串应用给定函数,允许对正在渲染的字符串进行操作。
示例:
s := NewStyle().Transform(strings.ToUpper)
fmt.Println(s.Render("raow!") // "RAOW!"
func (Style) UnderlineSpaces ¶
UnderlineSpaces 确定是否为单词之间的空格添加下划线。默认情况下,这是 true。也可以在不下划线文本本身的情况下为空格添加下划线。
func (Style) UnsetAlignHorizontal ¶
UnsetAlignHorizontal 移除水平文本对齐样式规则(如果已设置)。
func (Style) UnsetAlignVertical ¶
UnsetAlignVertical 移除垂直文本对齐样式规则(如果已设置)。
func (Style) UnsetBackground ¶
UnsetBackground 移除背景色样式规则(如果已设置)。
func (Style) UnsetBorderBackground ¶
UnsetBorderBackground 移除所有边框背景色样式(如果已设置)。
func (Style) UnsetBorderBottom ¶
UnsetBorderBottom 移除外边框样式规则(如果已设置)。
func (Style) UnsetBorderBottomBackground ¶
UnsetBorderBottomBackground 移除外边框背景色规则(如果已设置)。
func (Style) UnsetBorderBottomForeground ¶
UnsetBorderBottomForeground 移除外边框前景色规则(如果已设置)。
func (Style) UnsetBorderForeground ¶
UnsetBorderForeground 移除所有边框前景色样式(如果已设置)。
func (Style) UnsetBorderLeft ¶
UnsetBorderLeft 移除外边框样式规则(如果已设置)。
func (Style) UnsetBorderLeftBackground ¶
UnsetBorderLeftBackground 移除外边框颜色规则(如果已设置)。
func (Style) UnsetBorderLeftForeground ¶
UnsetBorderLeftForeground 移除外边框前景色规则(如果已设置)。
func (Style) UnsetBorderRight ¶
UnsetBorderRight 移除右边框样式规则(如果已设置)。
func (Style) UnsetBorderRightBackground ¶
UnsetBorderRightBackground 移除右边框背景色规则(如果已设置)。
func (Style) UnsetBorderRightForeground ¶
UnsetBorderRightForeground 移除右边框前景色规则(如果已设置)。
func (Style) UnsetBorderStyle ¶
UnsetBorderStyle 移除边框样式规则(如果已设置)。
func (Style) UnsetBorderTop ¶
UnsetBorderTop 移除顶部边框样式规则(如果已设置)。
func (Style) UnsetBorderTopBackground ¶
UnsetBorderTopBackground 移除顶部边框背景色规则(如果已设置)。
func (Style) UnsetBorderTopBackgroundColor ¶
UnsetBorderTopBackgroundColor 移除顶部边框背景色规则(如果已设置)。
已弃用:此函数仅调用 Style.UnsetBorderTopBackground。
func (Style) UnsetBorderTopForeground ¶
UnsetBorderTopForeground 移除顶部边框前景色规则(如果已设置)。
func (Style) UnsetColorWhitespace ¶
UnsetColorWhitespace 移除内边距着色规则(如果已设置)。
func (Style) UnsetForeground ¶
UnsetForeground 移除前景色样式规则(如果已设置)。
func (Style) UnsetMarginBackground ¶
UnsetMarginBackground 移除边距的背景颜色。请注意,边距的背景颜色可以在继承期间从另一个样式的背景颜色设置。
func (Style) UnsetMarginBottom ¶
UnsetMarginBottom 移除底部外边距样式规则(如果已设置)。
func (Style) UnsetMarginLeft ¶
UnsetMarginLeft 移除左边外边距样式规则(如果已设置)。
func (Style) UnsetMarginRight ¶
UnsetMarginRight 移除右边外边距样式规则(如果已设置)。
func (Style) UnsetMarginTop ¶
UnsetMarginTop 移除顶部外边距样式规则(如果已设置)。
func (Style) UnsetMaxHeight ¶
UnsetMaxHeight 移除最大高度样式规则(如果已设置)。
func (Style) UnsetPaddingBottom ¶
UnsetPaddingBottom 移除底部内边距样式规则(如果已设置)。
func (Style) UnsetPaddingLeft ¶
UnsetPaddingLeft 移除左边内边距样式规则(如果已设置)。
func (Style) UnsetPaddingRight ¶
UnsetPaddingRight 移除右边内边距样式规则(如果已设置)。
func (Style) UnsetPaddingTop ¶
UnsetPaddingTop 移除顶部内边距样式规则(如果已设置)。
func (Style) UnsetStrikethrough ¶
UnsetStrikethrough 移除删除线样式规则(如果已设置)。
func (Style) UnsetStrikethroughSpaces ¶
UnsetStrikethroughSpaces 移除由 StrikethroughSpaces 设置的值。
func (Style) UnsetTransform ¶
UnsetTransform 移除由 Transform 设置的值。
func (Style) UnsetUnderline ¶
UnsetUnderline 移除下划线样式规则(如果已设置)。
func (Style) UnsetUnderlineSpaces ¶
UnsetUnderlineSpaces 移除由 UnderlineSpaces 设置的值。
type TerminalColor ¶
type TerminalColor interface {
RGBA() (r, g, b, a uint32)
// contains filtered or unexported methods
}
TerminalColor 是一种旨在在终端中渲染的颜色。
type WhitespaceOption ¶
type WhitespaceOption func(*whitespace)
WhitespaceOption 设置空白字符渲染的样式规则
func WithWhitespaceBackground ¶
func WithWhitespaceBackground(c TerminalColor) WhitespaceOption
WithWhitespaceBackground 设置空白字符的背景色
func WithWhitespaceChars ¶
func WithWhitespaceChars(s string) WhitespaceOption
WithWhitespaceChars 设置要在空白字符中渲染的字符
func WithWhitespaceForeground ¶
func WithWhitespaceForeground(c TerminalColor) WhitespaceOption
WithWhitespaceForeground 设置空白字符中字符的前景色