table

package
v0.0.0-...-3a35617 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package table 为 Bubble Tea 应用程序提供一个简单的表格组件。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Title string // 列标题
	Width int    // 列宽度
}

Column 定义表格结构。

type KeyMap

type KeyMap struct {
	LineUp       key.Binding // 向上移动一行
	LineDown     key.Binding // 向下移动一行
	PageUp       key.Binding // 向上翻页
	PageDown     key.Binding // 向下翻页
	HalfPageUp   key.Binding // 向上翻半页
	HalfPageDown key.Binding // 向下翻半页
	GotoTop      key.Binding // 跳转到顶部
	GotoBottom   key.Binding // 跳转到底部
}

KeyMap 定义键绑定。它满足 help.KeyMap 接口, 该接口用于渲染帮助菜单。

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap 返回默认的键绑定集合。

func (KeyMap) FullHelp

func (km KeyMap) FullHelp() [][]key.Binding

FullHelp 实现 KeyMap 接口。

func (KeyMap) ShortHelp

func (km KeyMap) ShortHelp() []key.Binding

ShortHelp 实现 KeyMap 接口。

type Model

type Model struct {
	KeyMap KeyMap     // 键位映射
	Help   help.Model // 帮助模型
	// contains filtered or unexported fields
}

Model 定义表格小部件的状态。

func New

func New(opts ...Option) Model

New 为表格小部件创建一个新模型。

func (*Model) Blur

func (m *Model) Blur()

Blur 模糊表格,防止选择或移动。

func (Model) Columns

func (m Model) Columns() []Column

Columns 返回当前列。

func (Model) Cursor

func (m Model) Cursor() int

Cursor 返回选中行的索引。

func (*Model) Focus

func (m *Model) Focus()

Focus 聚焦表格,允许用户在行之间移动并 进行交互。

func (Model) Focused

func (m Model) Focused() bool

Focused 返回表格的聚焦状态。

func (*Model) FromValues

func (m *Model) FromValues(value, separator string)

FromValues 从简单字符串创建表格行。默认情况下,它使用 `\n` 来获取所有行,并使用给定的分隔符来分隔每行的字段。

func (*Model) GotoBottom

func (m *Model) GotoBottom()

GotoBottom 将选择移动到最后一行。

func (*Model) GotoTop

func (m *Model) GotoTop()

GotoTop 将选择移动到第一行。

func (Model) Height

func (m Model) Height() int

Height 返回表格视口的高度。

func (Model) HelpView

func (m Model) HelpView() string

HelpView 是从键映射渲染帮助菜单的辅助方法。 请注意,默认情况下不会渲染此视图,您必须在应用程序中 手动调用它(如果适用)。

func (*Model) MoveDown

func (m *Model) MoveDown(n int)

MoveDown 将选择向下移动任意行数。 它不能低于最后一行。

func (*Model) MoveUp

func (m *Model) MoveUp(n int)

MoveUp 将选择向上移动任意行数。 它不能超过第一行。

func (Model) Rows

func (m Model) Rows() []Row

Rows 返回当前行。

func (Model) SelectedRow

func (m Model) SelectedRow() Row

SelectedRow 返回选中的行。 您可以将其转换为您自己的实现。

func (*Model) SetColumns

func (m *Model) SetColumns(c []Column)

SetColumns 设置新的列状态。

func (*Model) SetCursor

func (m *Model) SetCursor(n int)

SetCursor 设置表格中的光标位置。

func (*Model) SetHeight

func (m *Model) SetHeight(h int)

SetHeight 设置表格视口的高度。

func (*Model) SetRows

func (m *Model) SetRows(r []Row)

SetRows 设置新的行状态。

func (*Model) SetStyles

func (m *Model) SetStyles(s Styles)

SetStyles 设置表格样式。

func (*Model) SetWidth

func (m *Model) SetWidth(w int)

SetWidth 设置表格视口的宽度。

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update 是 Bubble Tea 更新循环。

func (*Model) UpdateViewport

func (m *Model) UpdateViewport()

UpdateViewport 根据先前定义的列和行更新列表内容。

func (Model) View

func (m Model) View() string

View 渲染组件。

func (Model) Width

func (m Model) Width() int

Width 返回表格视口的宽度。

type Option

type Option func(*Model)

Option 用于在 New 中设置选项。例如:

table := New(WithColumns([]Column{{Title: "ID", Width: 10}}))

func WithColumns

func WithColumns(cols []Column) Option

WithColumns 设置表格列(表头)。

func WithFocused

func WithFocused(f bool) Option

WithFocused 设置表格的聚焦状态。

func WithHeight

func WithHeight(h int) Option

WithHeight 设置表格的高度。

func WithKeyMap

func WithKeyMap(km KeyMap) Option

WithKeyMap 设置键映射。

func WithRows

func WithRows(rows []Row) Option

WithRows 设置表格行(数据)。

func WithStyles

func WithStyles(s Styles) Option

WithStyles 设置表格样式。

func WithWidth

func WithWidth(w int) Option

WithWidth 设置表格的宽度。

type Row

type Row []string

Row 表示表格中的一行。

type Styles

type Styles struct {
	Header   lipgloss.Style // 表头样式
	Cell     lipgloss.Style // 单元格样式
	Selected lipgloss.Style // 选中样式
}

Styles 包含此列表组件的样式定义。默认情况下, 这些值由 DefaultStyles 生成。

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles 返回此表格的默认样式定义集合。

Jump to

Keyboard shortcuts

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