Documentation
¶
Overview ¶
Package kit 为 MyGo 原生界面提供连续面板、直角控件和通用内容阅读组件。
Index ¶
- Constants
- Variables
- func ANSIOutput(c *ui.Context, source string, state *ui.ListState, opt ANSIOutputOpt) ui.Element
- func ActivityCard(c *ui.Context, open *bool, opt ActivityCardOpt, actions func(), detail func()) ui.Element
- func ApplyTheme(c *ui.Context, t Theme)
- func AttachmentChip(c *ui.Context, name string, thumb ui.ImageSource, onRemove func()) ui.Element
- func Badge(c *ui.Context, text string, kind BadgeKind) ui.Element
- func Button(c *ui.Context, label string) ui.Element
- func Callout(c *ui.Context, kind CalloutKind, title, detail string, actions func()) ui.Element
- func Checkbox(c *ui.Context, checked *bool, label string) ui.Element
- func CommandPalette(c *ui.Context, open *bool, commands []Command) string
- func CompletionMenu(c *ui.Context, anchor, input ui.Element, opt CompletionOpt) (selected int)
- func ContextMenu(c *ui.Context, target ui.Element, items []MenuItem) (closed bool)
- func DangerButton(c *ui.Context, label string) ui.Element
- func Dialog(c *ui.Context, open *bool, title string, content func()) ui.Element
- func DialogWith(c *ui.Context, open *bool, opt DialogOpt, body func()) (confirmed bool)
- func Diff(c *ui.Context, state *editor.DiffState) ui.Element
- func Disclosure(c *ui.Context, label string, open *bool, content func()) ui.Element
- func EmptyState(c *ui.Context, title, detail string) ui.Element
- func EmptyStateWith(c *ui.Context, title, detail string, opt EmptyStateOpt) ui.Element
- func Facts(c *ui.Context, facts ...Fact) ui.Element
- func Fade(c *ui.Context, element ui.Element, visible bool) ui.Element
- func Field(c *ui.Context, opt FieldOpt, control func() ui.Element)
- func FieldMessage(c *ui.Context, kind MessageKind, text string) ui.Element
- func FlushButton(c *ui.Context, label string) ui.Element
- func Header(c *ui.Context, title string, actions func()) ui.Element
- func HeaderWith(c *ui.Context, title string, opt HeaderOpt, actions func()) ui.Element
- func IconButton(c *ui.Context, icon *ui.SVG, label string) ui.Element
- func IconButtonTip(c *ui.Context, icon *ui.SVG, label string) ui.Element
- func Image(c *ui.Context, image ImageResource) ui.Element
- func ImagePreview(c *ui.Context, image ImageResource, state *ImagePreviewState) ui.Element
- func InlineHint(c *ui.Context, message string, loading bool) ui.Element
- func InlineHintWith(c *ui.Context, message string, loading bool, opt InlineHintOpt) ui.Element
- func JSONTree(c *ui.Context, s *JSONState, opt JSONOpt) ui.Element
- func Kbd(c *ui.Context, keys string) ui.Element
- func Link(c *ui.Context, label string) ui.Element
- func List(c *ui.Context, state *ui.ListState, count int, row func(int)) ui.Element
- func ListRow(c *ui.Context, opt ListRowOpt) ui.Element
- func Markdown(c *ui.Context, source string, opt MarkdownOpt) ui.Element
- func MenuButton(c *ui.Context, trigger ui.Element, items []MenuItem) (closed bool)
- func MessageScroller(c *ui.Context, state *ui.ListState, count int, opt MessageScrollerOpt, ...) ui.Element
- func MorphText(c *ui.Context, value string) ui.Element
- func PatchLines(c *ui.Context, state *ui.ListState, lines []PatchLine, opt PatchOpt) ui.Element
- func Popover(c *ui.Context, anchor ui.Element, open *bool, content func()) ui.Element
- func PrimaryButton(c *ui.Context, label string) ui.Element
- func ProgressBar(c *ui.Context, value float32) ui.Element
- func ProgressRing(c *ui.Context, value float32, size float32) ui.Element
- func RegisterFonts() error
- func Segmented(c *ui.Context, selected *int, labels []string) ui.Element
- func SegmentedWith(c *ui.Context, selected *int, items []SegmentedItem, opt SegmentedOpt) ui.Element
- func Select(c *ui.Context, value *string, opt SelectOpt) ui.Element
- func Separator(c *ui.Context) ui.Element
- func SettingPage(c *ui.Context, title string, actions, content func()) ui.Element
- func SettingRow(c *ui.Context, title, description string, control func()) ui.Element
- func SettingSection(c *ui.Context, title string, rows func()) ui.Element
- func Sheet(c *ui.Context, open *bool, side SheetSide, width float32, content func()) ui.Element
- func Shimmer(c *ui.Context, value string) ui.Element
- func ShowToast(c *ui.Context, opt ToastOpt)
- func SmallIconButton(c *ui.Context, icon *ui.SVG, label string) ui.Element
- func Spinner(c *ui.Context, size float32) ui.Element
- func Split(c *ui.Context, size *float32, first, second func()) ui.Element
- func StatusBar(c *ui.Context, content func()) ui.Element
- func StatusButton(c *ui.Context, icon *ui.SVG, label string, active bool) ui.Element
- func StatusDot(c *ui.Context, color ui.Color) ui.Element
- func StatusIcon(c *ui.Context, status ActivityStatus)
- func Switch(c *ui.Context, on *bool, label string) ui.Element
- func Tab(c *ui.Context, opt TabOpt) (clicked, closed bool)
- func Tabs(c *ui.Context, selected *int, labels []string) ui.Element
- func Terminal(c *ui.Context, state *TerminalState, opt TerminalOpt) ui.Element
- func TextArea(c *ui.Context, value *string) ui.Element
- func TextAreaWith(c *ui.Context, value *string, opt InputOpt) ui.Element
- func TextInput(c *ui.Context, value *string) ui.Element
- func TextInputWith(c *ui.Context, value *string, opt InputOpt) ui.Element
- func TitleBar(c *ui.Context, content func()) ui.Element
- func ToastHost(c *ui.Context) ui.Element
- func ToolButton(c *ui.Context, icon *ui.SVG, label string, chevron bool) ui.Element
- func Tooltip(c *ui.Context, anchor ui.Element, text string) ui.Element
- func Tree[K comparable](c *ui.Context, state *ui.OutlineState[K], roots []K, children func(K) []K, ...) ui.Element
- func Workspace(c *ui.Context, state *WorkspaceState, opt WorkspaceOpt) ui.Element
- type ANSIOutputOpt
- type ActivityCardOpt
- type ActivityStatus
- type ActivityTone
- type BadgeKind
- type CalloutKind
- type Colors
- type Command
- type CompletionItem
- type CompletionOpt
- type DialogOpt
- type DockState
- type EmptyStateOpt
- type Fact
- type FieldOpt
- type HeaderOpt
- type ImagePreviewState
- type ImageResource
- type InlineHintOpt
- type InputOpt
- type JSONOpt
- type JSONState
- type ListRowOpt
- type MarkdownOpt
- type MenuItem
- type MessageKind
- type MessageScrollerOpt
- type Metrics
- type Motion
- type Panel
- type PatchKind
- type PatchLine
- type PatchOpt
- type SegmentedItem
- type SegmentedOpt
- type SelectOpt
- type SelectOption
- type SheetSide
- type SyntaxColors
- type TabOpt
- type TerminalOpt
- type TerminalState
- type TextRole
- type Theme
- type ToastKind
- type ToastOpt
- type Typography
- type WorkspaceOpt
- type WorkspaceState
- func (s *WorkspaceState) IsNarrow() bool
- func (s *WorkspaceState) IsPanelShown(dock *DockState, panelID string) bool
- func (s *WorkspaceState) ShowPanel(dock *DockState, panelID string)
- func (s *WorkspaceState) ShowSidebar()
- func (s *WorkspaceState) ToggleDock(dock *DockState)
- func (s *WorkspaceState) TogglePanel(dock *DockState, panelID string)
- func (s *WorkspaceState) ToggleSidebar()
Constants ¶
const ( FontSans = "IBM Plex Sans" FontMono = "Lilex" )
界面与代码字体族名,与 Zed 默认的 .ZedSans、.ZedMono 一致。
const ( IconSizeSmall float32 = 12 IconSizeDefault float32 = 14 IconSizeLarge float32 = 16 )
图标尺寸三档,照 Zed agent_ui:14 是 28 高按钮、行首图标、标签和状态栏的默认值; 12 用于 20 高紧凑控件和行尾指示(下拉箭头);16 用于空状态和 36 高标题栏的主操作。
const RadiusFull float32 = 9999
RadiusFull 是圆形控件的圆角,大于任何控件边长的一半,实际绘制时贴合成圆。
Variables ¶
var ( IconPanelLeft = mustIcon("panel-left") IconPanelRight = mustIcon("panel-right") IconPanelBottom = mustIcon("panel-bottom") IconPlus = mustIcon("plus") IconSettings = mustIcon("settings") IconSearch = mustIcon("search") IconChevronDown = mustIcon("chevron-down") IconChevronLeft = mustIcon("chevron-left") IconChevronRight = mustIcon("chevron-right") IconX = mustIcon("x") IconEllipsis = mustIcon("ellipsis") IconArrowUp = mustIcon("arrow-up") IconArrowDown = mustIcon("arrow-down") IconStop = mustIcon("square") IconImagePlus = mustIcon("image-plus") IconFolder = mustIcon("folder") IconFold = mustIcon("fold-vertical") IconCopy = mustIcon("copy") IconAlert = mustIcon("circle-alert") IconLoader = mustIcon("loader-circle") IconBot = mustIcon("bot") IconBranch = mustIcon("git-branch") IconTerminal = mustIcon("terminal") IconInfo = mustIcon("info") IconCircleCheck = mustIcon("circle-check") IconCircleX = mustIcon("circle-x") IconCommand = mustIcon("command") IconFiles = mustIcon("files") IconBrain = mustIcon("brain") IconTriangleAlert = mustIcon("triangle-alert") IconFileText = mustIcon("file-text") IconPencil = mustIcon("pencil") IconGauge = mustIcon("gauge") IconListTree = mustIcon("list-tree") IconBug = mustIcon("bug") IconActivity = mustIcon("activity") IconWrench = mustIcon("wrench") IconArchive = mustIcon("archive") IconBookOpen = mustIcon("book-open") IconWebhook = mustIcon("webhook") IconGitFork = mustIcon("git-fork") IconReplace = mustIcon("replace") IconServerCog = mustIcon("server-cog") IconBan = mustIcon("ban") IconMessageSquare = mustIcon("message-square") IconBraces = mustIcon("braces") IconRotateCcw = mustIcon("rotate-ccw") IconCirclePause = mustIcon("circle-pause") IconCircleStop = mustIcon("circle-stop") IconRefresh = mustIcon("refresh-cw") IconCheck = mustIcon("check") IconListEnd = mustIcon("list-end") IconPanelBottomClose = mustIcon("panel-bottom-close") IconPanelRightClose = mustIcon("panel-right-close") IconPlay = mustIcon("play") IconTrash = mustIcon("trash-2") IconDownload = mustIcon("download") )
Lucide 线性图标,统一 1.5 描边,颜色跟随文字。
Functions ¶
func ANSIOutput ¶
ANSIOutput 显示可选择、横向滚动的虚拟输出行;跟随底部由 ListState.FollowEnd 控制。
func ActivityCard ¶
func ActivityCard(c *ui.Context, open *bool, opt ActivityCardOpt, actions func(), detail func()) ui.Element
ActivityCard 显示一行 28 高的条目标题行,detail 非空时可展开;展开状态由调用方持有。
[图标/箭头 16] 标题 状态 摘要 ········ [操作]
actions 是独立于展开按钮的右侧图标按钮,只在悬停或键盘聚焦本行时可见; detail 内容与标题文字左对齐,左侧竖线对齐图标中线,块之间间隔 12。
func ApplyTheme ¶
ApplyTheme 在本帧根节点保存主题并应用 MyGo 的文字、焦点和滚动条颜色。
func AttachmentChip ¶
AttachmentChip 显示一个待发送附件:20×20 缩略图、截断的文件名和 20 见方的移除按钮,整体高 28。 thumb 为 nil 时显示文件图标;onRemove 为 nil 时不显示移除按钮。
func Callout ¶
Callout 显示带色调的提示条:图标、标题、次要色详情,右侧是 actions 画出的操作。 detail 为空时只显示标题,actions 为 nil 时不留操作区。
func CommandPalette ¶
CommandPalette 显示可搜索的命令列表,选中后返回命令 ID 并关闭;本帧没有选中则返回空字符串。
func CompletionMenu ¶
CompletionMenu 在 anchor 上方显示补全浮层,输入框 input 保持焦点;返回本帧选中的候选序号,没有选中时返回 -1。 有候选时接管 Up/Down(循环移动)、Enter 和 Tab(选中),Esc 关闭到 Open 变回 false;没有候选时只接管 Esc;输入法组字期间不接管任何键。 最多显示 8 行(候选、加载行、错误行合计),超出滚动,行内容的左缘与 input 里的文字对齐。 接管按键用的是 input 上的 HandleInput,调用方不要再给同一个输入框设置 HandleInput;OnTextKey 不受影响。
func ContextMenu ¶
ContextMenu 给 target 附上右键菜单:右键时在指针处弹出,目标有焦点时 Shift+F10 或菜单键在目标下方弹出,键盘和选中行为与 MenuButton 相同。 target 是 Selectable 文字容器时,右键同样弹出这个菜单而不是系统的文字菜单,拖选不受影响; 打开时有选中文字,菜单顶部多一项「复制」,复制的就是选中的文字。Selectable 容器必须自己就是 target:挂在它的祖先上, 容器内的文字仍然显示系统菜单。返回值含义同 MenuButton:菜单在本帧关闭。
func DangerButton ¶
DangerButton 创建文字强调危险操作的按钮。
func DialogWith ¶
DialogWith 创建带固定标题栏、全宽滚动正文和固定页脚的模态对话框。 点击确认或按 Enter 时关闭并返回 true(焦点在单行 TextInput 里时 Enter 提交,在多行输入里时是换行,在按钮上时按下该按钮); 单行输入要用本库的 TextInput 或 TextInputWith 才会把 Enter 报告给对话框。 点击取消或按 Esc 只关闭,返回 false。打开时焦点落在正文里第一个可编辑的输入(只读输入除外), 页签、按钮等其他控件不会拿到初始焦点;正文里没有可编辑输入时落在确认按钮上,且不画焦点环(Enter 仍然确认,焦点移走后环照常显示)。
func Disclosure ¶
Disclosure 绘制无边框整行标题及可折叠内容。
func EmptyState ¶
EmptyState 在区域中央显示一行提示,可附带一行次要说明。
func EmptyStateWith ¶
EmptyStateWith 同 EmptyState,可在文字下方带一个主操作按钮。
func Field ¶
Field 创建竖排表单字段:标签在上、控件在中、说明或错误在下,各段间距 4。 标签和说明接到 control 返回元素的可访问名称与描述上,错误还会把它标为无效;点击标签聚焦控件。 说明和错误同时存在时只显示错误。输入类控件的危险色边线由调用方用 InputOpt.Invalid 设置。
func FieldMessage ¶
FieldMessage 创建一行 12/16 的说明、警告或错误文字,颜色由 kind 决定,可换行。
func FlushButton ¶
FlushButton 创建无水平内边距的文字按钮,文字贴齐所在列的左对齐线;悬停只改变文字颜色,不画底色。
func HeaderWith ¶
HeaderWith 创建共享底部分隔线的紧凑面板标题栏,左内边距和左侧内容由 opt 决定。
func IconButton ¶
IconButton 创建方形 ghost 工具按钮,图标与可访问名称分别传入。
func IconButtonTip ¶
IconButtonTip 创建带悬停提示的 IconButton:label 同时是可访问名称和提示文字,省去每次手写 Tooltip 和 Label;返回按钮,调用方用 Clicked 响应。
func ImagePreview ¶
func ImagePreview(c *ui.Context, image ImageResource, state *ImagePreviewState) ui.Element
ImagePreview 显示可切换适应/原尺寸及双向滚动的图片。
func InlineHint ¶
InlineHint 创建列表里的一行次要提示,用于加载中或空列表;loading 为真时行首显示转圈,message 为空时用库内置的「加载中」。
func InlineHintWith ¶
InlineHintWith 同 InlineHint,按 opt 指定左对齐线。
func ListRow ¶
func ListRow(c *ui.Context, opt ListRowOpt) ui.Element
ListRow 创建整行列表项:28 高(带说明时 44),整行是一个按钮,调用方用 Clicked 响应选择,用 FillWidth、Key、Label 调整。 图标在 16 宽的图标位里居中,标题和行尾文字按基线对齐,状态底色由 controlBackground 给出。
func MenuButton ¶
MenuButton 给 trigger 附上点击后在下方弹出的菜单:点击触发元素开关菜单,上下键、Home/End、首字母移动高亮, Enter 选中,Esc 关闭;返回值表示菜单在本帧关闭(Esc、点击外部或触发元素、Tab、选中条目),焦点回到触发元素, 想把焦点放到别处的调用方在返回 true 的那一帧自己设置焦点。
func MessageScroller ¶
func MessageScroller(c *ui.Context, state *ui.ListState, count int, opt MessageScrollerOpt, row func(int)) ui.Element
MessageScroller 创建跟随最新消息的虚拟列表;用户上滚后右下角浮出「回到底部」按钮,opt 指定滚到顶部的通知。 state 由调用方持有,建议设置 Key 以便前插历史时保持位置。
func PatchLines ¶
PatchLines 显示通用补丁片段的颜色、可选行号和全文复制。
func PrimaryButton ¶
PrimaryButton 创建突出主要操作的实色按钮。
func ProgressBar ¶
ProgressBar 创建 4 高的线性进度条,value 为 0 到 1 的比例:悬停色轨道,强调色填充,两端圆角,宽度由所在容器决定。
func ProgressRing ¶
ProgressRing 创建环形进度,value 为 0 到 1 的比例,用于上下文用量;达到 0.85 时改用警告色,达到 0.95 时改用危险色。 value 大于 0 时弧长至少 8°,value 为 0 时只有底环;可访问名称始终是真实百分比。
func RegisterFonts ¶
func RegisterFonts() error
RegisterFonts 注册库内置的 IBM Plex Sans 与 Lilex;重复调用只注册一次。
func SegmentedWith ¶
func SegmentedWith(c *ui.Context, selected *int, items []SegmentedItem, opt SegmentedOpt) ui.Element
SegmentedWith 创建 Zed ToggleButtonGroup 外观(Outlined)的分段控件:28 高,一圈 60% 透明度的边线, 圆角裁剪,各段之间 1 像素竖线分隔;*selected 是选中段序号,选中段用强调色浅底和强调色文字、图标, 其余段透明底,悬停和按下取控件状态底色。默认宽度贴合内容,放进纵向容器时调用方加 AlignSelf(ui.Start) 才靠左; FullWidth 时占满容器、各段等宽。方向键切换,整体是一个 Tab 停靠点,调用方用 Label 给出可访问名称。
func Select ¶
Select 显示工具栏选择器;整组禁用使用 opt.Disabled,同时禁用触发器和已打开的弹层。 带搜索的弹层里:输入过滤词,↑↓ 移动高亮,Enter 选中高亮项(没有高亮时选第一个匹配项)并关闭弹层,Esc 只关闭弹层。
func SettingPage ¶
SettingPage 创建设置页:页头是 36 高的标题栏,右侧是 actions,内容区在页头下方滚动,页头始终可见; 内容左右上下边距 16、最大宽度 720、靠左,小节之间间距 16。
func SettingRow ¶
SettingRow 创建一行设置:左侧是标题和可选说明,右侧是 control 绘制的控件,行高至少 36。
func SettingSection ¶
SettingSection 创建设置小节:上方是小节标题,下方是圆角框,框内是 rows 绘制的若干 SettingRow,行之间 1 像素分隔线。
func Sheet ¶
Sheet 创建贴靠窗口左侧或右侧的模态抽屉;点遮罩或按 Escape 把 *open 置为 false。 窗口里有 TitleBar 时抽屉和遮罩从顶栏下缘开始,顶栏和系统窗口按钮不被盖住;没有 TitleBar 时铺满整个窗口。
func SmallIconButton ¶
SmallIconButton 创建 20 见方的紧凑 ghost 图标按钮,图标 12,平时用弱化色、悬停用次要色,用于消息下方的复制、调试和标签关闭。
func StatusButton ¶
StatusButton 创建状态栏里 20 高的图标按钮,上下左右各留 4;active 为真时使用选中底色,label 作为可访问名称,无图标时显示 label 文字。
func StatusIcon ¶
func StatusIcon(c *ui.Context, status ActivityStatus)
StatusIcon 绘制活动状态图标;成功不显示任何内容。
func Switch ¶
Switch 创建 36×20 的开关:开时轨道用强调色,滑块随状态滑动;label 显示在轨道右侧并随整行点击切换, label 为空时只有轨道,调用方用 Label 给出可访问名称。Space 切换,禁用由框架统一半透明。
func Tab ¶
Tab 绘制 Zed 风格的可关闭标签,返回本帧是否点了标签和关闭按钮。 标签与所在标题栏同高、无圆角:选中时用正文底色、左右竖线、不画底线,与下方内容连成一片; 未选中时用面板底色、右侧竖线和底线。关闭按钮在悬停或选中时出现。
func Tabs ¶
Tabs 绘制连续页签条,方向键导航由 MyGo TabsBase 提供。 焦点环由页签自己在边界内绘制(见 paintFocusRing),只在键盘聚焦时显示,并始终跟随选中的页签。
func Terminal ¶
func Terminal(c *ui.Context, state *TerminalState, opt TerminalOpt) ui.Element
Terminal 绘制终端:等宽 12/16(Lilex),16 色用主题 ANSI,支持 256 色与真彩色、光标、滚动历史、选择复制(双击选词、三击选行)。 程序开启鼠标上报(DEC 模式 9、1000-1003,SGR 编码)后,点击、拖动、移动和滚轮交给程序,按住 Shift 仍可本地选择和回看。 元素默认填满父容器剩余空间,背景为编辑器色;点击获得焦点,焦点只体现在光标上。
func TextAreaWith ¶
TextAreaWith 创建最小两行高的多行输入,保留原生组字、选区和受控值处理。
func TextInputWith ¶
TextInputWith 创建 28 高的单行输入,文字在高度内垂直居中;在 DialogWith 的正文里,按 Enter 会确认对话框。
func ToolButton ¶
ToolButton 创建图标加文字的 ghost 工具按钮:28 高、图标 14,可选尾部下拉箭头。
func Tree ¶
func Tree[K comparable](c *ui.Context, state *ui.OutlineState[K], roots []K, children func(K) []K, row func(K)) ui.Element
Tree 显示紧凑虚拟树,沿用框架的稳定键、展开与方向键导航。
func Workspace ¶
func Workspace(c *ui.Context, state *WorkspaceState, opt WorkspaceOpt) ui.Element
Workspace 绘制顶栏、侧栏、中间区、右 Dock、下 Dock 和状态栏;拖动分隔线后把新尺寸写回 state。
Types ¶
type ANSIOutputOpt ¶
ANSIOutputOpt 设置输出工具栏标题及复制操作名称。
type ActivityCardOpt ¶
type ActivityCardOpt struct {
Icon *ui.SVG // 类型图标,可展开的条目在悬停、聚焦和展开时换成箭头
Title string
Summary string // 参数摘要,单行截断,不加悬停提示
Status ActivityStatus
Tone ActivityTone
Shimmer bool // 标题闪烁,用于思考、压缩、运行中
// Extra 是紧跟标题的自定义交互内容,例如 Session 链接;它在展开按钮之外,设置后不再显示 Summary。
Extra func()
}
ActivityCardOpt 指定条目标题行的图标、标题、摘要和状态。
type ActivityStatus ¶
type ActivityStatus string
ActivityStatus 是条目标题行里紧跟标题的状态;空值表示成功或没有状态,不显示图标。
const ( ActivityRunning ActivityStatus = "running" ActivityFailed ActivityStatus = "failed" ActivityInterrupted ActivityStatus = "interrupted" ActivityBlocked ActivityStatus = "blocked" ActivityStopped ActivityStatus = "stopped" )
条目标题行的非成功状态。
type ActivityTone ¶
type ActivityTone int
ActivityTone 是标题和类型图标的语义色;普通条目用次要色,悬停时变正文色。
const ( ActivityNormal ActivityTone = iota ActivityWarning ActivityDanger )
条目标题行的语义色。
type CalloutKind ¶
type CalloutKind string
CalloutKind 是提示条的严重程度。
const ( CalloutError CalloutKind = "error" CalloutWarning CalloutKind = "warning" CalloutInfo CalloutKind = "info" )
提示条的种类。
type Colors ¶
type Colors struct {
Background, Panel, Editor, Elevated ui.Color
Text, Muted, Placeholder, Disabled ui.Color
Border, BorderSubtle, Focus, Hover, Active, Selected ui.Color
Accent, AccentText, AccentSubtle ui.Color
Danger, Warning, Success ui.Color
Input, Selection, Added, Deleted ui.Color
ANSI [16]ui.Color
}
Colors 按界面职责保存颜色,不携带应用状态;AccentSubtle 是带透明度的强调色浅底,用于选中的分段等强调态。
type CompletionItem ¶
type CompletionItem struct {
Icon *ui.SVG
Title string
// Description 显示在标题右侧,次要色,放不下时截断。
Description string
}
CompletionItem 是补全浮层的一行候选。
type CompletionOpt ¶
type CompletionOpt struct {
// Open 为真时才显示浮层;调用方按输入内容决定,例如光标所在的词以 / 开头。
Open bool
Items []CompletionItem
// Loading 在候选后面(没有候选时单独)显示加载行。
Loading bool
// Error 非空时显示一行错误。
Error string
// Empty 是没有候选、没有加载也没有错误时的提示;为空用库内置的「没有匹配项」。
Empty string
}
CompletionOpt 是补全浮层的数据和状态。
type DialogOpt ¶
type DialogOpt struct {
Title string
// Description 显示在标题栏下方、滚动正文之前,次要色;为空时不显示。
Description string
// HeaderExtra 放在标题栏下方、滚动正文上方且不随正文滚动,例如弹窗内的分段切换。
HeaderExtra func()
// ConfirmLabel 是确认按钮的文字;为空用库内置的「确定」。
ConfirmLabel string
// Danger 让确认按钮用 DangerButton,否则用 PrimaryButton。
Danger bool
// ConfirmDisabled 禁用确认按钮,Enter 也不会确认。
ConfirmDisabled bool
}
DialogOpt 描述 DialogWith 的标题、固定头部附加区、说明和确认按钮。
type DockState ¶
type DockState struct {
Open bool `json:"open"`
ActivePanel string `json:"active_panel"`
Size float32 `json:"size"`
}
DockState 保存一个 Dock 是否打开、当前面板和尺寸。
type EmptyStateOpt ¶
type EmptyStateOpt struct {
// ActionLabel 非空时在文字下方居中显示一个主按钮,点击时调用 OnAction。
ActionLabel string
OnAction func()
}
EmptyStateOpt 设置空状态的可选主操作。
type FieldOpt ¶
type FieldOpt struct {
Label, Description, Error string
}
FieldOpt 是表单字段的标签、说明和错误;说明和错误都为空时控件下方不留空。
type HeaderOpt ¶
type HeaderOpt struct {
// Inset 是标题文字距左缘的距离,对齐所在列的左对齐线:侧栏和 Dock 用 12,对话区用 16;零值取 12。
Inset float32
// Leading 替换标题文字,例如放一组分段控件;为空时显示 title。内容从 Inset 处开始,标题栏高度和底线不变。
Leading func()
}
HeaderOpt 设置标题栏的左内边距和左侧内容。
type ImagePreviewState ¶
ImagePreviewState 保存预览缩放,Fit 为 true 时按可用尺寸适应。
type ImageResource ¶
type ImageResource struct {
Source ui.ImageSource
Alt string
Loading bool
Error string
Retry func()
}
ImageResource 是调用方准备好的图片及加载状态;本库不读磁盘或下载。
type InlineHintOpt ¶
type InlineHintOpt struct{ Inset float32 }
InlineHintOpt 设置 InlineHint 的左对齐线:列表里用 12(零值),对话列用 16。
type InputOpt ¶
type InputOpt struct {
Placeholder string
// Invalid 让边线显示危险色,优先于焦点色。
Invalid bool
// ReadOnly 把输入显示成一段可选中复制的值:没有边线、没有底色,文字起点和 28 高与普通输入一致(字段对齐不变),
// 不随焦点和悬停变化,键盘聚焦仍有焦点环;需要「看起来可编辑」时不要用它。放进 Field 作为只读字段的正文。
ReadOnly bool
// Borderless 去掉边框、底色、内边距和焦点环,用于侧栏搜索、输入区这类由所在容器决定外观的输入。
Borderless bool
// Leading 是输入框左侧的前缀图标,14,次要色;文字区从图标右侧开始,滚动的长文字被裁在图标之外。
Leading *ui.SVG
}
InputOpt 设置输入框的提示、状态和外观变体;零值就是普通的可编辑输入。
type JSONState ¶
type JSONState struct {
// contains filtered or unexported fields
}
JSONState 保存已解析的 JSON 与展开、选中、滚动状态。
func NewJSONState ¶
NewJSONState 解析任意 JSON 顶级值,包括 null、数组和标量。
type ListRowOpt ¶
type ListRowOpt struct {
// Icon 是行首图标,14,画在 16 宽的图标位中央;为空时不留图标位。
Icon *ui.SVG
Title string
// Description 非空时行变成两行、44 高(标题 20 加说明 16,上下各留 4),说明用 12/16 次要色单行截断。
Description string
Selected bool
// Depth 是缩进层级,每级向右 16。
Depth int
// Trailing 画行尾的状态或徽标;单行时与标题按基线对齐,两行时在整行垂直居中。
Trailing func()
// Actions 画行尾的操作按钮(28 见方的 IconButton);只在悬停、选中或键盘聚焦到行内时显示,不显示时仍占位,行内容不会跳动。
Actions func()
}
ListRowOpt 描述 ListRow 的内容和状态。
type MarkdownOpt ¶
type MarkdownOpt struct {
Streaming bool
OnLink func(string)
Image func(string) ImageResource
OnImage func(string)
CopyLabel, CodeCopyLabel string
// contains filtered or unexported fields
}
MarkdownOpt 指定流式显示、共享选区和应用提供的图片及链接行为。
type MenuItem ¶
type MenuItem struct {
// Icon 是条目图标,14;任一条目有图标时,没有图标的条目也留出图标位,标题对齐。
Icon *ui.SVG
Title string
// Shortcut 是行尾右对齐显示的快捷键提示,例如 "⌘N",只显示不注册。
Shortcut string
// Danger 让标题和图标用危险色。
Danger bool
// Disabled 让条目变淡且不可选,方向键、首字母跳转都会跳过它。
Disabled bool
Separator bool
// OnSelect 在条目被选中、菜单关闭的那一帧调用。
OnSelect func()
}
MenuItem 是菜单的一个条目;Separator 为真时只画一条分隔线,其余字段忽略。
type MessageKind ¶
type MessageKind int
MessageKind 是 FieldMessage 的语义:说明、警告或错误。
const ( MessageDescription MessageKind = iota MessageWarning MessageError )
提示文字的语义,分别用次要色、警告色和危险色。
type MessageScrollerOpt ¶
type MessageScrollerOpt struct {
// OnReachTop 在用户滚到列表顶部时调用一次,调用方据此加载更早的历史;
// 离开顶部后再次回到顶部才会再次调用。
OnReachTop func()
}
MessageScrollerOpt 指定消息滚动区的可选通知。
type Metrics ¶
type Metrics struct {
Grid float32
CompactHeight, ControlHeight, HeaderHeight float32 // 紧凑控件 20、普通控件和列表行 28、标题栏 36
StatusHeight float32
Radius, RadiusLarge float32 // 控件 4,浮层和卡片 8
}
Metrics 保存四像素网格、三档高度(20/28/36)及圆角尺寸。
type Panel ¶
type Panel struct {
ID string
Title string
Icon *ui.SVG
Content func()
// Header 替换 Dock 标题栏里的标题文字,例如放一排 Tab;Tab 从标题栏左缘开始、与标题栏同高。为空时显示 Title。
Header func()
// Actions 是标题栏右端、关闭按钮之前的按钮,例如新建。
Actions func()
// CloseIcon 覆盖关闭按钮图标;为空时跟随 Dock 所在边(下 Dock 用 IconPanelBottomClose,右 Dock 用 IconPanelRightClose)。
CloseIcon *ui.SVG
}
Panel 是 Dock 里的一个面板,应用每帧传入;同一 Dock 同时只显示一个。
type PatchOpt ¶
type PatchOpt struct{ Title, CopyLabel, Source string }
PatchOpt 保存工具栏名称及完整原文,复制时不从行片段重建补丁。
type SegmentedItem ¶
SegmentedItem 是分段控件的一段:Icon 可为空,Label 同时是可访问名称,Tooltip 可为空。
type SegmentedOpt ¶
type SegmentedOpt struct {
// FullWidth 让整条控件占满所在容器宽度、各段等宽;默认各段贴合自己的内容。
FullWidth bool
}
SegmentedOpt 指定分段控件的宽度方式。
type SelectOpt ¶
type SelectOpt struct {
Options []SelectOption
Placeholder, Label string
Disabled bool
Searchable bool
SearchPlaceholder string
// Bordered 让触发器与表单输入框外观一致;工具栏保持无边框。
Bordered bool
// TriggerLabel 非空时决定触发器上显示的文字,参数是当前选中的选项;选项行仍显示各自的 Label。
// 例如选项是「自动 / 低 / 中 / 高」,触发器显示「推理:自动」。没有选中任何选项时仍显示 Placeholder 或原值。
TriggerLabel func(selected SelectOption) string
}
SelectOpt 设置选项、空选择提示和可访问名称。
type SelectOption ¶
type SelectOption struct {
Value, Label string
// Description 显示在选项行右侧,12/16 次要色单行;触发器不显示它,例如模型选择里的 Provider。
Description string
Disabled bool
// Header 让这一项成为分组标题:只显示 Label,是 12/16 次要色的小标题,不可选,方向键跳过,Value 被忽略;
// 搜索时只在组内有匹配项时保留。
Header bool
}
SelectOption 保存独立的选项值、显示文字及禁用状态。
type SyntaxColors ¶
type SyntaxColors struct{ Keyword, String, Function, Type, Number, Comment, Property, Operator ui.Color }
SyntaxColors 保存代码语法角色的颜色。
type TabOpt ¶
type TabOpt struct {
Icon *ui.SVG
Title string
Selected bool
// Faded 让标题用弱化色,例如进程已结束的终端。
Faded bool
// CloseLabel 是关闭按钮的可访问名称。
CloseLabel string
}
TabOpt 指定一个可关闭标签的图标、标题和状态。
type TerminalOpt ¶
type TerminalOpt struct {
// OnInput 接收键盘、输入法上屏文字和粘贴编码后的字节。
// 程序查询光标位置等自动应答也从这里发出,此时在后台 goroutine 调用。
OnInput func(data []byte)
// OnResize 在面板尺寸换算出的行列数变化时调用。
OnResize func(rows, cols int)
}
TerminalOpt 指定终端向应用回传的输入和尺寸变化。
type TerminalState ¶
type TerminalState struct {
// contains filtered or unexported fields
}
TerminalState 保存一个终端的屏幕、滚动历史和选择;由应用持有,可在任意 goroutine 调用 Write。
func NewTerminalState ¶
func NewTerminalState(rows, cols int) *TerminalState
NewTerminalState 创建 rows 行 cols 列的空终端,并启动转发模拟器自动应答的 goroutine;不再使用时调用 Close。
func (*TerminalState) Close ¶
func (s *TerminalState) Close()
Close 结束转发自动应答的 goroutine;之后的 Write 被忽略。
func (*TerminalState) Write ¶
func (s *TerminalState) Write(data []byte)
Write 喂入 PTY 输出;在回看历史时保持当前位置不动。
type TextRole ¶
type TextRole int
TextRole 是组件选择的文字角色,字号、行高、字体、字重和数字样式由主题统一给出。
const ( TextProse TextRole = iota // 14/24:Markdown 正文、详情说明 TextUI // 14/20:行标题、按钮、输入框、工具名 TextCaption // 12/16:时间、提示、次要状态 TextToken // 12/20:token 数,等宽数字 TextCode // 12/20:代码、JSON、工具输出、RPC 行,等宽字体 TextCodeLabel // 12/16:工具详情里的小节标签和内容框标题,等宽字体,调用方配次要色 TextTitle // 16/24:小节和页面标题,字重 400 )
文字角色:每个角色对应一组固定字号与行高,都落在四像素网格上。
type Theme ¶
type Theme struct {
Dark bool
Colors Colors
Typography Typography
Metrics Metrics
Motion Motion
Syntax SyntaxColors
}
Theme 是可复制的主题值,由应用保存,每帧交给 ApplyTheme。
type ToastOpt ¶
type ToastOpt struct {
Title string
Description string
Kind ToastKind
Action string
OnAction func()
}
ToastOpt 描述一条通知;Action 非空时显示按钮,点击后执行 OnAction 并关闭通知。
type Typography ¶
type Typography struct {
Font, MonoFont string
BodySize, CaptionSize, HeadingSize, CodeSize float32
}
Typography 保存界面、正文和代码字体及字号。
type WorkspaceOpt ¶
type WorkspaceOpt struct {
TitleBar func() // 顶栏左侧内容(窗口按钮避让由 Workspace 处理)
Sidebar func()
Center func()
RightPanels []Panel
BottomPanels []Panel
StatusLeft func() // 状态栏左侧额外项,排在侧栏开关之后
StatusRight func() // 状态栏右侧额外项,排在面板按钮之前
}
WorkspaceOpt 指定各区域内容;nil 的区域不显示。
type WorkspaceState ¶
type WorkspaceState struct {
SidebarOpen bool `json:"sidebar_open"`
SidebarWidth float32 `json:"sidebar_width"`
Right DockState `json:"right"`
Bottom DockState `json:"bottom"`
// contains filtered or unexported fields
}
WorkspaceState 保存侧栏和两个 Dock 的布局;应用持有并负责持久化。 窄窗口里侧栏和右 Dock 的抽屉开关只存在于内存,不写入持久化数据。
func (*WorkspaceState) IsNarrow ¶
func (s *WorkspaceState) IsNarrow() bool
IsNarrow 最近一帧窗口是否处于窄窗口(宽度小于 900,侧栏和右 Dock 改用抽屉)?
func (*WorkspaceState) IsPanelShown ¶
func (s *WorkspaceState) IsPanelShown(dock *DockState, panelID string) bool
IsPanelShown 指定面板此刻是否正在显示(宽窗口里作为 Dock,窄窗口里作为右侧抽屉)?
func (*WorkspaceState) ShowPanel ¶
func (s *WorkspaceState) ShowPanel(dock *DockState, panelID string)
ShowPanel 打开 Dock 并显示指定面板;窄窗口里的右 Dock 打开抽屉并收起侧栏抽屉,不改写 Right.Open。
func (*WorkspaceState) ShowSidebar ¶
func (s *WorkspaceState) ShowSidebar()
ShowSidebar 显示侧栏:宽窗口里置 SidebarOpen,窄窗口里打开侧栏抽屉并收起右 Dock 抽屉。
func (*WorkspaceState) ToggleDock ¶
func (s *WorkspaceState) ToggleDock(dock *DockState)
ToggleDock 切换 Dock:窄窗口里的右 Dock 切换抽屉并收起侧栏抽屉,其余情况改写 Dock.Open。
func (*WorkspaceState) TogglePanel ¶
func (s *WorkspaceState) TogglePanel(dock *DockState, panelID string)
TogglePanel 显示指定面板;它已经是显示中的面板时关闭 Dock(窄窗口里关闭抽屉)。
func (*WorkspaceState) ToggleSidebar ¶
func (s *WorkspaceState) ToggleSidebar()
ToggleSidebar 切换侧栏:宽窗口改写 SidebarOpen,窄窗口切换侧栏抽屉并收起右 Dock 抽屉。
Source Files
¶
- activitycard.go
- ansi.go
- attachment.go
- badge.go
- button.go
- callout.go
- checkbox.go
- command.go
- completion.go
- dialog.go
- diff.go
- disclosure.go
- facts.go
- fonts.go
- form.go
- icons.go
- image.go
- input.go
- json.go
- kbd.go
- layout.go
- link.go
- listrow.go
- locale.go
- markdown.go
- menu.go
- motion.go
- patch.go
- progress.go
- scroller.go
- segmented.go
- select.go
- sheet.go
- shimmer.go
- spinner.go
- statusbar.go
- switch.go
- tabs.go
- terminal.go
- theme.go
- titlebar.go
- toast.go
- workspace.go