tui

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusPending   = types.StatusPending
	StatusRunning   = types.StatusRunning
	StatusSuccess   = types.StatusSuccess
	StatusFailed    = types.StatusFailed
	StatusSkipped   = types.StatusSkipped
	StatusCancelled = types.StatusCancelled
)

重新导出状态常量

Variables

View Source
var (
	NewOutputMsg           = types.NewOutputMsg
	NewOutputBatchMsg      = types.NewOutputBatchMsg
	NewTaskStatusMsg       = types.NewTaskStatusMsg
	NewTaskProgressMsg     = types.NewTaskProgressMsg
	NewStageStartMsg       = types.NewStageStartMsg
	NewStageCompleteMsg    = types.NewStageCompleteMsg
	NewPipelineCompleteMsg = types.NewPipelineCompleteMsg
	NewErrorMsg            = types.NewErrorMsg
)

重新导出构造函数

View Source
var (
	PrimaryColor   = lipgloss.Color("#7D56F4") // 主色调 - 紫色
	SecondaryColor = lipgloss.Color("#5B8DEF") // 次要色 - 蓝色
	SuccessColor   = lipgloss.Color("#73F59F") // 成功 - 绿色
	WarningColor   = lipgloss.Color("#EDFF82") // 警告 - 黄色
	ErrorColor     = lipgloss.Color("#FF6B6B") // 错误 - 红色
	SubtleColor    = lipgloss.Color("#383838") // 微妙色 - 深灰
	TextColor      = lipgloss.Color("#EEEEEE") // 文本色 - 浅灰
	MutedColor     = lipgloss.Color("#626262") // 静音色 - 中灰
)

颜色定义

View Source
var (
	// 应用标题样式
	AppTitleStyle = lipgloss.NewStyle().
					Bold(true).
					Foreground(PrimaryColor).
					Background(lipgloss.Color("#1a1a2e")).
					Padding(0, 1)

	// 版本号样式
	VersionStyle = lipgloss.NewStyle().
					Foreground(MutedColor).
					Italic(true)

	// 帮助提示样式
	HelpStyle = lipgloss.NewStyle().
				Foreground(MutedColor)

	// 分隔线样式
	DividerStyle = lipgloss.NewStyle().
					Foreground(SubtleColor)
)

通用样式

View Source
var (
	// 普通卡片边框
	CardStyle = lipgloss.NewStyle().
				Border(lipgloss.RoundedBorder()).
				BorderForeground(PrimaryColor).
				Padding(1, 2)

	// 成功状态卡片
	SuccessCardStyle = lipgloss.NewStyle().
						Border(lipgloss.RoundedBorder()).
						BorderForeground(SuccessColor).
						Padding(1, 2)

	// 错误状态卡片
	ErrorCardStyle = lipgloss.NewStyle().
					Border(lipgloss.RoundedBorder()).
					BorderForeground(ErrorColor).
					Padding(1, 2)

	// 运行中状态卡片
	RunningCardStyle = lipgloss.NewStyle().
						Border(lipgloss.RoundedBorder()).
						BorderForeground(WarningColor).
						Padding(1, 2)
)

卡片与边框样式

View Source
var (
	// 标题样式
	TitleStyle = lipgloss.NewStyle().
				Bold(true).
				Foreground(TextColor).
				MarginBottom(1)

	// 副标题样式
	SubtitleStyle = lipgloss.NewStyle().
					Foreground(MutedColor)

	// 成功文本
	SuccessTextStyle = lipgloss.NewStyle().
						Foreground(SuccessColor)

	// 错误文本
	ErrorTextStyle = lipgloss.NewStyle().
					Foreground(ErrorColor)

	// 警告文本
	WarningTextStyle = lipgloss.NewStyle().
						Foreground(WarningColor)

	// 高亮文本
	HighlightStyle = lipgloss.NewStyle().
					Foreground(PrimaryColor).
					Bold(true)
)

文本样式

View Source
var (
	IconPending = lipgloss.NewStyle().Foreground(MutedColor).Render("○")
	IconRunning = lipgloss.NewStyle().Foreground(WarningColor).Render("●")
	IconSuccess = lipgloss.NewStyle().Foreground(SuccessColor).Render("✓")
	IconFailed  = lipgloss.NewStyle().Foreground(ErrorColor).Render("✗")
	IconSkipped = lipgloss.NewStyle().Foreground(MutedColor).Render("⊘")
	IconArrow   = lipgloss.NewStyle().Foreground(PrimaryColor).Render("→")
	IconBullet  = lipgloss.NewStyle().Foreground(SecondaryColor).Render("•")
	IconSpinner = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
)

状态图标

View Source
var (
	StatusBarStyle = lipgloss.NewStyle().
					Background(SubtleColor).
					Foreground(TextColor).
					Padding(0, 1)

	StatusItemStyle = lipgloss.NewStyle().
					Foreground(TextColor).
					Padding(0, 1)

	StatusKeyStyle = lipgloss.NewStyle().
					Foreground(MutedColor)

	StatusValueStyle = lipgloss.NewStyle().
						Foreground(PrimaryColor).
						Bold(true)
)

状态栏样式

View Source
var (
	ProgressFilledStyle = lipgloss.NewStyle().
						Foreground(PrimaryColor)

	ProgressEmptyStyle = lipgloss.NewStyle().
						Foreground(SubtleColor)

	ProgressPercentStyle = lipgloss.NewStyle().
							Foreground(TextColor).
							Width(6).
							Align(lipgloss.Right)
)

进度条样式

View Source
var DefaultKeyMap = KeyMap{
	Quit: key.NewBinding(
		key.WithKeys("q", "ctrl+c"),
		key.WithHelp("q", "退出"),
	),
	Up: key.NewBinding(
		key.WithKeys("up", "k"),
		key.WithHelp("↑/k", "上移"),
	),
	Down: key.NewBinding(
		key.WithKeys("down", "j"),
		key.WithHelp("↓/j", "下移"),
	),
	Enter: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("enter", "确认"),
	),
	Help: key.NewBinding(
		key.WithKeys("?"),
		key.WithHelp("?", "帮助"),
	),
	Cancel: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "取消"),
	),
	ScrollUp: key.NewBinding(
		key.WithKeys("ctrl+u"),
		key.WithHelp("ctrl+u", "向上滚动"),
	),
	ScrollDown: key.NewBinding(
		key.WithKeys("ctrl+d"),
		key.WithHelp("ctrl+d", "向下滚动"),
	),
	PageUp: key.NewBinding(
		key.WithKeys("pgup"),
		key.WithHelp("pgup", "上一页"),
	),
	PageDown: key.NewBinding(
		key.WithKeys("pgdown"),
		key.WithHelp("pgdown", "下一页"),
	),
	Home: key.NewBinding(
		key.WithKeys("home"),
		key.WithHelp("home", "顶部"),
	),
	End: key.NewBinding(
		key.WithKeys("end"),
		key.WithHelp("end", "底部"),
	),
	LogPrev: key.NewBinding(
		key.WithKeys("[", "shift+tab"),
		key.WithHelp("[/⇧tab", "上一个日志页"),
	),
	LogNext: key.NewBinding(
		key.WithKeys("]", "tab"),
		key.WithHelp("]/tab", "下一个日志页"),
	),
	LogAll: key.NewBinding(
		key.WithKeys("ctrl+a"),
		key.WithHelp("ctrl+a", "全部日志并置底"),
	),
	LogResume: key.NewBinding(
		key.WithKeys("ctrl+r"),
		key.WithHelp("ctrl+r", "恢复自动滚动"),
	),
}

DefaultKeyMap 默认快捷键配置

Functions

func CenterText

func CenterText(text string, width int) string

CenterText 居中文本

func RenderBox

func RenderBox(content string, width int, style lipgloss.Style) string

RenderBox 渲染带边框的盒子

func RenderDivider

func RenderDivider(width int) string

布局辅助函数

func StatusIcon

func StatusIcon(s types.TaskStatus) string

Icon 返回状态图标 (需要在 tui 包中实现,因为依赖 styles)

func TruncateText

func TruncateText(text string, maxWidth int) string

TruncateText 截断文本(带省略号)

Types

type ErrorMsg

type ErrorMsg = types.ErrorMsg

重新导出 types 包中的类型,保持向后兼容

type KeyMap

type KeyMap struct {
	Quit       key.Binding
	Up         key.Binding
	Down       key.Binding
	Enter      key.Binding
	Help       key.Binding
	Cancel     key.Binding
	ScrollUp   key.Binding
	ScrollDown key.Binding
	PageUp     key.Binding
	PageDown   key.Binding
	Home       key.Binding
	End        key.Binding
	LogPrev    key.Binding
	LogNext    key.Binding
	LogAll     key.Binding
	LogResume  key.Binding
}

KeyMap 定义全局快捷键

func (KeyMap) FullHelp

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

FullHelp 返回完整帮助信息

func (KeyMap) ShortHelp

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

ShortHelp 返回简短帮助信息

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model 主 TUI Model

func New

func New(cfg *config.Config) Model

New 创建新的主 Model

func (Model) GetError

func (m Model) GetError() error

GetError 获取错误信息

func (Model) GetFailedOutput

func (m Model) GetFailedOutput() []string

GetFailedOutput 获取失败任务的输出日志

func (Model) GetFailedTaskID

func (m Model) GetFailedTaskID() string

GetFailedTaskID 获取失败任务的 ID

func (Model) GetFailedTaskName

func (m Model) GetFailedTaskName() string

GetFailedTaskName 获取失败任务的名称

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init 实现 tea.Model 接口

func (Model) IsFailed

func (m Model) IsFailed() bool

IsFailed 检查是否失败

func (*Model) SetProgram

func (m *Model) SetProgram(p *tea.Program)

SetProgram 设置 tea.Program 引用

func (*Model) Update

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

Update 实现 tea.Model 接口

func (*Model) View

func (m *Model) View() string

View 实现 tea.Model 接口

type OutputBatchMsg added in v0.0.6

type OutputBatchMsg = types.OutputBatchMsg

重新导出 types 包中的类型,保持向后兼容

type OutputLine added in v0.0.6

type OutputLine = types.OutputLine

重新导出 types 包中的类型,保持向后兼容

type OutputMsg

type OutputMsg = types.OutputMsg

重新导出 types 包中的类型,保持向后兼容

type PipelineCompleteMsg

type PipelineCompleteMsg = types.PipelineCompleteMsg

重新导出 types 包中的类型,保持向后兼容

type StageCompleteMsg

type StageCompleteMsg = types.StageCompleteMsg

重新导出 types 包中的类型,保持向后兼容

type StageStartMsg

type StageStartMsg = types.StageStartMsg

重新导出 types 包中的类型,保持向后兼容

type State

type State int

State 应用状态

const (
	StateInit State = iota
	StateRunning
	StateCompleted
	StateFailed
)

type TaskProgressMsg

type TaskProgressMsg = types.TaskProgressMsg

重新导出 types 包中的类型,保持向后兼容

type TaskStatus

type TaskStatus = types.TaskStatus

重新导出 types 包中的类型,保持向后兼容

type TaskStatusMsg

type TaskStatusMsg = types.TaskStatusMsg

重新导出 types 包中的类型,保持向后兼容

type TickMsg

type TickMsg = types.TickMsg

重新导出 types 包中的类型,保持向后兼容

Directories

Path Synopsis
components

Jump to

Keyboard shortcuts

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