banner

package
v3.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AtCenter = -1
	AtRight  = -2
)

特殊margin定义banner 居中,居右

Variables

View Source
var (
	/*
		SimpleBorderStyle example:

		 +-----+
		 | hi  |
		 +-----+
	*/
	SimpleBorderStyle = BorderStyle{TopLeft: '+', TopRight: '+', BottomLeft: '+', BottomRight: '+', Horizontal: '-', Vertical: '|'}
	/*
		RoundedBorderStyle example
		 ╭─────╮
		 │  hi │
		 ╰─────╯
	*/
	RoundedBorderStyle = BorderStyle{TopLeft: '╭', TopRight: '╮', BottomLeft: '╰', BottomRight: '╯', Horizontal: '─', Vertical: '│'}
	/*
		SharpBorderStyle example:
		 ┌─────┐
		 │  hi │
		 └─────┘
	*/
	SharpBorderStyle = BorderStyle{TopLeft: '┌', TopRight: '┐', BottomLeft: '└', BottomRight: '┘', Horizontal: '─', Vertical: '│'}
	/*
		DoubleBorderStyle example:
		 ╔═════╗
		 ║ hi  ║
		 ╚═════╝
	*/
	DoubleBorderStyle = BorderStyle{TopLeft: '╔', TopRight: '╗', BottomLeft: '╚', BottomRight: '╝', Horizontal: '═', Vertical: '║'}
)

预定义的边框样式

Functions

This section is empty.

Types

type Banner struct {
	// use for internal
	showcom.Base
	// Options banner options
	Options
	// Prefix 横幅前缀
	Prefix string
	// Contents 横幅显示的内容
	Contents []string
	// contains filtered or unexported fields
}

Banner 在终端中绘制横幅样式的信息

func New

func New(content any, fns ...OptionFunc) *Banner

New 创建新的 Banner 实例

func (*Banner) Format

func (b *Banner) Format()

Format 绘制横幅

func (*Banner) Render

func (b *Banner) Render() string

Render 绘制横幅样式的信息

func (*Banner) WithContents

func (b *Banner) WithContents(content any) *Banner

WithContents 设置横幅显示的内容

content: string, []string, []any, ...

func (*Banner) WithOptionFn

func (b *Banner) WithOptionFn(fns ...OptionFunc) *Banner

WithOptionFn 设置 Banner 的选项

func (*Banner) WithOptionFns

func (b *Banner) WithOptionFns(fns []OptionFunc) *Banner

WithOptionFns 设置 Banner 的选项

type BorderStyle

type BorderStyle struct {
	TopLeft     rune
	TopRight    rune
	BottomLeft  rune
	BottomRight rune
	Horizontal  rune // top, bottom
	Vertical    rune // left, right
	// Color 边框颜色 tag
	Color string
}

BorderStyle 边框样式

type OptionFunc

type OptionFunc func(b *Options)

OptionFunc definition

func WithAlignment

func WithAlignment(alignment comdef.Align) OptionFunc

WithAlignment 设置内容对齐方式

func WithBannerCenter

func WithBannerCenter() OptionFunc

WithBannerCenter 设置banner居中

func WithBannerRight

func WithBannerRight() OptionFunc

WithBannerRight 设置banner居右

func WithHeight

func WithHeight(height int) OptionFunc

WithHeight 设置内容高度行数

func WithMarginLeft

func WithMarginLeft(margin int) OptionFunc

WithMarginLeft 设置左边距

func WithMarginTopBottom

func WithMarginTopBottom(marginTop, marginBottom int) OptionFunc

WithMarginTopBottom 添加上下边距

func WithMinWidth

func WithMinWidth(minWidth int) OptionFunc

WithMinWidth 设置最小宽度

func WithOverflowFlag

func WithOverflowFlag(flag showcom.OverflowFlag) OptionFunc

WithOverflowFlag 设置内容溢出处理方式

func WithPercentWidth

func WithPercentWidth(percent int) OptionFunc

WithPercentWidth 使用终端宽度的百分比宽度

func WithWidth

func WithWidth(width int) OptionFunc

WithWidth 设置横幅宽度

type Options

type Options struct {
	// Padding 内边距 default: 1
	Padding int
	// MarginL 左外边距
	//  - >0 表示左外边距
	//  - 0 表示无外边距 居左显示banner(默认)
	//  - -1 表示居中显示banner
	//  - -2 表示居右显示banner
	MarginL int
	MarginR int // TODO
	// MarginTB 上下外边距 TODO
	MarginTB []int
	// Width 横幅宽度
	//  - 0 表示自动计算内容宽度
	Width int
	// Height 内容高度行数,默认为内容行数
	Height int
	// MinWidth 最小宽度
	//  0: 表示不限制最小宽度
	MinWidth int
	// PercentWidth 使用终端宽度的百分比宽度 (1-100)
	//  0 表示不使用百分比宽度
	PercentWidth int
	// OverflowFlag 内容溢出处理 default: wrap
	OverflowFlag showcom.OverflowFlag
	// Alignment 内容对齐方式
	Alignment comdef.Align
	// TextColor 文本颜色 tag
	TextColor string
	// BorderStyle 边框样式
	BorderStyle BorderStyle
}

Options banner options

宽度设置优先级: MinWidth > Width > PercentWidth > contentWidth

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL