kit

package module
v0.0.0-...-766251f Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 25 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mygo-kit

English | 简体中文

A native Go component library built on MyGo, styled after Zed: continuous panels, compact toolbars, controls with small corner radii, and One Light / One Dark color schemes. Components return MyGo’s ui.Element directly. They do not create a separate application runtime or access the network. Only the terminal starts background goroutines.

mygo-kit settings page example

Documentation · Live gallery (WebAssembly version running in the browser)

Components

  • Controls: buttons, inputs, Select, switches, segmented controls, tabs, menus, completion overlays, dialogs, Toast, and a command palette.
  • Forms: fields, settings pages, settings sections, and settings rows.
  • Reading: streaming Markdown, JSON trees, ANSI output, diffs, patch snippets, images, and a vt-based terminal.
  • Layout: a workspace with left, right, and bottom docks, title bars, status bars, split panes, virtual lists, and trees.

Installation

go get github.com/VaalaCat/mygo-kit

Requires Go 1.27.3 and MyGo v0.7.3. Linux requires GTK3. macOS uses system frameworks.

Quick start

package main

import (
	"log"
	"strconv"

	kit "github.com/VaalaCat/mygo-kit"
	"github.com/egoist/mygo"
	"github.com/egoist/mygo/ui"
)

var count int

func main() {
	if err := kit.RegisterFonts(); err != nil {
		log.Fatal(err)
	}
	mygo.App.WhenReady(func() {
		mygo.NewWindow(mygo.WindowOptions{Title: "Hello", Width: 480, Height: 320, Content: ui.View(view)})
	})
	if err := mygo.App.Run(); err != nil {
		log.Fatal(err)
	}
}

func view(c *ui.Context) {
	theme := kit.OneLight()
	kit.ApplyTheme(c, theme)
	ui.Column(c).Fill().Children(func() {
		kit.Header(c, "Hello", nil)
		ui.Column(c).Padding(theme.Space(4)).Gap(theme.Space(2)).Children(func() {
			ui.Text(c, "Clicks: "+strconv.Itoa(count))
			if kit.PrimaryButton(c, "Click me").Clicked() {
				count++
			}
		})
	})
}

Your application owns the theme and calls ApplyTheme once per frame. See the documentation for theme customization, dark mode, and component usage.

Run locally

go run ./cmd/gallery                 # Component gallery
cd website && bun install && bun run dev   # Docs site with live previews

License

MIT. See THIRD_PARTY_NOTICES.md for third-party sources and licenses.

Documentation

Overview

Package kit 为 MyGo 原生界面提供连续面板、直角控件和通用内容阅读组件。

Index

Constants

View Source
const (
	FontSans = "IBM Plex Sans"
	FontMono = "Lilex"
)

界面与代码字体族名,与 Zed 默认的 .ZedSans、.ZedMono 一致。

View Source
const (
	IconSizeSmall   float32 = 12
	IconSizeDefault float32 = 14
	IconSizeLarge   float32 = 16
)

图标尺寸三档,照 Zed agent_ui:14 是 28 高按钮、行首图标、标签和状态栏的默认值; 12 用于 20 高紧凑控件和行尾指示(下拉箭头);16 用于空状态和 36 高标题栏的主操作。

View Source
const RadiusFull float32 = 9999

RadiusFull 是圆形控件的圆角,大于任何控件边长的一半,实际绘制时贴合成圆。

Variables

View Source
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

func ANSIOutput(c *ui.Context, source string, state *ui.ListState, opt ANSIOutputOpt) ui.Element

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

func ApplyTheme(c *ui.Context, t Theme)

ApplyTheme 在本帧根节点保存主题并应用 MyGo 的文字、焦点和滚动条颜色。

func AttachmentChip

func AttachmentChip(c *ui.Context, name string, thumb ui.ImageSource, onRemove func()) ui.Element

AttachmentChip 显示一个待发送附件:20×20 缩略图、截断的文件名和 20 见方的移除按钮,整体高 28。 thumb 为 nil 时显示文件图标;onRemove 为 nil 时不显示移除按钮。

func Badge

func Badge(c *ui.Context, text string, kind BadgeKind) ui.Element

Badge 创建一枚紧凑的状态徽标,文字颜色和浅底色由 kind 决定。

func Button

func Button(c *ui.Context, label string) ui.Element

Button 创建无常驻边框的工具按钮,保留 MyGo 键盘与焦点行为。

func Callout

func Callout(c *ui.Context, kind CalloutKind, title, detail string, actions func()) ui.Element

Callout 显示带色调的提示条:图标、标题、次要色详情,右侧是 actions 画出的操作。 detail 为空时只显示标题,actions 为 nil 时不留操作区。

func Checkbox

func Checkbox(c *ui.Context, checked *bool, label string) ui.Element

Checkbox 创建直角选择框及可点击标签。

func CommandPalette

func CommandPalette(c *ui.Context, open *bool, commands []Command) string

CommandPalette 显示可搜索的命令列表,选中后返回命令 ID 并关闭;本帧没有选中则返回空字符串。

func CompletionMenu

func CompletionMenu(c *ui.Context, anchor, input ui.Element, opt CompletionOpt) (selected int)

CompletionMenu 在 anchor 上方显示补全浮层,输入框 input 保持焦点;返回本帧选中的候选序号,没有选中时返回 -1。 有候选时接管 Up/Down(循环移动)、Enter 和 Tab(选中),Esc 关闭到 Open 变回 false;没有候选时只接管 Esc;输入法组字期间不接管任何键。 最多显示 8 行(候选、加载行、错误行合计),超出滚动,行内容的左缘与 input 里的文字对齐。 接管按键用的是 input 上的 HandleInput,调用方不要再给同一个输入框设置 HandleInput;OnTextKey 不受影响。

func ContextMenu

func ContextMenu(c *ui.Context, target ui.Element, items []MenuItem) (closed bool)

ContextMenu 给 target 附上右键菜单:右键时在指针处弹出,目标有焦点时 Shift+F10 或菜单键在目标下方弹出,键盘和选中行为与 MenuButton 相同。 target 是 Selectable 文字容器时,右键同样弹出这个菜单而不是系统的文字菜单,拖选不受影响; 打开时有选中文字,菜单顶部多一项「复制」,复制的就是选中的文字。Selectable 容器必须自己就是 target:挂在它的祖先上, 容器内的文字仍然显示系统菜单。返回值含义同 MenuButton:菜单在本帧关闭。

func DangerButton

func DangerButton(c *ui.Context, label string) ui.Element

DangerButton 创建文字强调危险操作的按钮。

func Dialog

func Dialog(c *ui.Context, open *bool, title string, content func()) ui.Element

Dialog 创建模态对话框:标题栏加可滚动正文,焦点陷阱和 Escape 由框架处理;需要确认和取消按钮时用 DialogWith。

func DialogWith

func DialogWith(c *ui.Context, open *bool, opt DialogOpt, body func()) (confirmed bool)

DialogWith 创建带固定标题栏、全宽滚动正文和固定页脚的模态对话框。 点击确认或按 Enter 时关闭并返回 true(焦点在单行 TextInput 里时 Enter 提交,在多行输入里时是换行,在按钮上时按下该按钮); 单行输入要用本库的 TextInput 或 TextInputWith 才会把 Enter 报告给对话框。 点击取消或按 Esc 只关闭,返回 false。打开时焦点落在正文里第一个可编辑的输入(只读输入除外), 页签、按钮等其他控件不会拿到初始焦点;正文里没有可编辑输入时落在确认按钮上,且不画焦点环(Enter 仍然确认,焦点移走后环照常显示)。

func Diff

func Diff(c *ui.Context, state *editor.DiffState) ui.Element

Diff 显示原生 diff、增删行号、选择和复制,调用方持有原框架 DiffState。

func Disclosure

func Disclosure(c *ui.Context, label string, open *bool, content func()) ui.Element

Disclosure 绘制无边框整行标题及可折叠内容。

func EmptyState

func EmptyState(c *ui.Context, title, detail string) ui.Element

EmptyState 在区域中央显示一行提示,可附带一行次要说明。

func EmptyStateWith

func EmptyStateWith(c *ui.Context, title, detail string, opt EmptyStateOpt) ui.Element

EmptyStateWith 同 EmptyState,可在文字下方带一个主操作按钮。

func Facts

func Facts(c *ui.Context, facts ...Fact) ui.Element

Facts 创建两列事实组(标签列宽 112,同一组事实的值共用一条左对齐线):左列标签用 12/16 次要色,右列值用等宽 12/20 并可选择,两列按首行基线对齐。

func Fade

func Fade(c *ui.Context, element ui.Element, visible bool) ui.Element

Fade 更新元素可见透明度;系统或主题请求减少动画时立即到达目标。

func Field

func Field(c *ui.Context, opt FieldOpt, control func() ui.Element)

Field 创建竖排表单字段:标签在上、控件在中、说明或错误在下,各段间距 4。 标签和说明接到 control 返回元素的可访问名称与描述上,错误还会把它标为无效;点击标签聚焦控件。 说明和错误同时存在时只显示错误。输入类控件的危险色边线由调用方用 InputOpt.Invalid 设置。

func FieldMessage

func FieldMessage(c *ui.Context, kind MessageKind, text string) ui.Element

FieldMessage 创建一行 12/16 的说明、警告或错误文字,颜色由 kind 决定,可换行。

func FlushButton

func FlushButton(c *ui.Context, label string) ui.Element

FlushButton 创建无水平内边距的文字按钮,文字贴齐所在列的左对齐线;悬停只改变文字颜色,不画底色。

func Header(c *ui.Context, title string, actions func()) ui.Element

Header 创建共享底部分隔线的紧凑面板标题栏,标题距左缘 12。

func HeaderWith

func HeaderWith(c *ui.Context, title string, opt HeaderOpt, actions func()) ui.Element

HeaderWith 创建共享底部分隔线的紧凑面板标题栏,左内边距和左侧内容由 opt 决定。

func IconButton

func IconButton(c *ui.Context, icon *ui.SVG, label string) ui.Element

IconButton 创建方形 ghost 工具按钮,图标与可访问名称分别传入。

func IconButtonTip

func IconButtonTip(c *ui.Context, icon *ui.SVG, label string) ui.Element

IconButtonTip 创建带悬停提示的 IconButton:label 同时是可访问名称和提示文字,省去每次手写 Tooltip 和 Label;返回按钮,调用方用 Clicked 响应。

func Image

func Image(c *ui.Context, image ImageResource) ui.Element

Image 显示直角图片或明确的加载/错误内容。

func ImagePreview

func ImagePreview(c *ui.Context, image ImageResource, state *ImagePreviewState) ui.Element

ImagePreview 显示可切换适应/原尺寸及双向滚动的图片。

func InlineHint

func InlineHint(c *ui.Context, message string, loading bool) ui.Element

InlineHint 创建列表里的一行次要提示,用于加载中或空列表;loading 为真时行首显示转圈,message 为空时用库内置的「加载中」。

func InlineHintWith

func InlineHintWith(c *ui.Context, message string, loading bool, opt InlineHintOpt) ui.Element

InlineHintWith 同 InlineHint,按 opt 指定左对齐线。

func JSONTree

func JSONTree(c *ui.Context, s *JSONState, opt JSONOpt) ui.Element

JSONTree 显示可键盘展开、选择和复制的虚拟 JSON 树。

func Kbd

func Kbd(c *ui.Context, keys string) ui.Element

Kbd 创建显示快捷键的小标签,例如 "⌘N";只负责外观,不注册快捷键。

func Link(c *ui.Context, label string) ui.Element

Link 创建强调色链接按钮;文字始终靠左;在纵向容器里要贴合文字宽度(只有文字可点)时,调用方自己加 AlignSelf(ui.Start)。

func List

func List(c *ui.Context, state *ui.ListState, count int, row func(int)) ui.Element

List 创建紧凑虚拟列表,行位置和稳定 Key 由调用方的 ListState 管理。

func ListRow

func ListRow(c *ui.Context, opt ListRowOpt) ui.Element

ListRow 创建整行列表项:28 高(带说明时 44),整行是一个按钮,调用方用 Clicked 响应选择,用 FillWidth、Key、Label 调整。 图标在 16 宽的图标位里居中,标题和行尾文字按基线对齐,状态底色由 controlBackground 给出。

func Markdown

func Markdown(c *ui.Context, source string, opt MarkdownOpt) ui.Element

Markdown 显示可选择的流式 Markdown,使用直角代码块、任务框和图片。

func MenuButton(c *ui.Context, trigger ui.Element, items []MenuItem) (closed bool)

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 MorphText

func MorphText(c *ui.Context, value string) ui.Element

MorphText 显示单行状态文字,只对变化字素短上推并渐显;共同前后缀及中段匹配保持身份,纯追加不动画。

func PatchLines

func PatchLines(c *ui.Context, state *ui.ListState, lines []PatchLine, opt PatchOpt) ui.Element

PatchLines 显示通用补丁片段的颜色、可选行号和全文复制。

func Popover

func Popover(c *ui.Context, anchor ui.Element, open *bool, content func()) ui.Element

Popover 创建直角浮层并复用框架的定位、关闭和焦点处理。

func PrimaryButton

func PrimaryButton(c *ui.Context, label string) ui.Element

PrimaryButton 创建突出主要操作的实色按钮。

func ProgressBar

func ProgressBar(c *ui.Context, value float32) ui.Element

ProgressBar 创建 4 高的线性进度条,value 为 0 到 1 的比例:悬停色轨道,强调色填充,两端圆角,宽度由所在容器决定。

func ProgressRing

func ProgressRing(c *ui.Context, value float32, size float32) ui.Element

ProgressRing 创建环形进度,value 为 0 到 1 的比例,用于上下文用量;达到 0.85 时改用警告色,达到 0.95 时改用危险色。 value 大于 0 时弧长至少 8°,value 为 0 时只有底环;可访问名称始终是真实百分比。

func RegisterFonts

func RegisterFonts() error

RegisterFonts 注册库内置的 IBM Plex Sans 与 Lilex;重复调用只注册一次。

func Segmented

func Segmented(c *ui.Context, selected *int, labels []string) ui.Element

Segmented 创建只有文字的分段控件,宽度贴合内容;见 SegmentedWith。

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

func Select(c *ui.Context, value *string, opt SelectOpt) ui.Element

Select 显示工具栏选择器;整组禁用使用 opt.Disabled,同时禁用触发器和已打开的弹层。 带搜索的弹层里:输入过滤词,↑↓ 移动高亮,Enter 选中高亮项(没有高亮时选第一个匹配项)并关闭弹层,Esc 只关闭弹层。

func Separator

func Separator(c *ui.Context) ui.Element

Separator 创建单条水平分隔线。

func SettingPage

func SettingPage(c *ui.Context, title string, actions, content func()) ui.Element

SettingPage 创建设置页:页头是 36 高的标题栏,右侧是 actions,内容区在页头下方滚动,页头始终可见; 内容左右上下边距 16、最大宽度 720、靠左,小节之间间距 16。

func SettingRow

func SettingRow(c *ui.Context, title, description string, control func()) ui.Element

SettingRow 创建一行设置:左侧是标题和可选说明,右侧是 control 绘制的控件,行高至少 36。

func SettingSection

func SettingSection(c *ui.Context, title string, rows func()) ui.Element

SettingSection 创建设置小节:上方是小节标题,下方是圆角框,框内是 rows 绘制的若干 SettingRow,行之间 1 像素分隔线。

func Sheet

func Sheet(c *ui.Context, open *bool, side SheetSide, width float32, content func()) ui.Element

Sheet 创建贴靠窗口左侧或右侧的模态抽屉;点遮罩或按 Escape 把 *open 置为 false。 窗口里有 TitleBar 时抽屉和遮罩从顶栏下缘开始,顶栏和系统窗口按钮不被盖住;没有 TitleBar 时铺满整个窗口。

func Shimmer

func Shimmer(c *ui.Context, value string) ui.Element

Shimmer 显示次要色单行文字,并让高亮从左向右扫过;减少动画时保持静态。

func ShowToast

func ShowToast(c *ui.Context, opt ToastOpt)

ShowToast 在窗口右上角显示一条通知;需要窗口里已有 ToastHost。空闲窗口也会立即出现,调用方不用自己请求重绘。

func SmallIconButton

func SmallIconButton(c *ui.Context, icon *ui.SVG, label string) ui.Element

SmallIconButton 创建 20 见方的紧凑 ghost 图标按钮,图标 12,平时用弱化色、悬停用次要色,用于消息下方的复制、调试和标签关闭。

func Spinner

func Spinner(c *ui.Context, size float32) ui.Element

Spinner 创建旋转的加载图标,颜色跟随文字;减少动画时保持静止。

func Split

func Split(c *ui.Context, size *float32, first, second func()) ui.Element

Split 创建两个可拖宽的连续面板,不添加重复外框。

func StatusBar

func StatusBar(c *ui.Context, content func()) ui.Element

StatusBar 创建窗口底部的状态栏,与标题栏同色并共用顶部分隔线。

func StatusButton

func StatusButton(c *ui.Context, icon *ui.SVG, label string, active bool) ui.Element

StatusButton 创建状态栏里 20 高的图标按钮,上下左右各留 4;active 为真时使用选中底色,label 作为可访问名称,无图标时显示 label 文字。

func StatusDot

func StatusDot(c *ui.Context, color ui.Color) ui.Element

StatusDot 创建 8 见方的圆点,用于连接状态和未读标记,颜色由调用方决定;调用方用 Label 给出可访问名称。

func StatusIcon

func StatusIcon(c *ui.Context, status ActivityStatus)

StatusIcon 绘制活动状态图标;成功不显示任何内容。

func Switch

func Switch(c *ui.Context, on *bool, label string) ui.Element

Switch 创建 36×20 的开关:开时轨道用强调色,滑块随状态滑动;label 显示在轨道右侧并随整行点击切换, label 为空时只有轨道,调用方用 Label 给出可访问名称。Space 切换,禁用由框架统一半透明。

func Tab

func Tab(c *ui.Context, opt TabOpt) (clicked, closed bool)

Tab 绘制 Zed 风格的可关闭标签,返回本帧是否点了标签和关闭按钮。 标签与所在标题栏同高、无圆角:选中时用正文底色、左右竖线、不画底线,与下方内容连成一片; 未选中时用面板底色、右侧竖线和底线。关闭按钮在悬停或选中时出现。

func Tabs

func Tabs(c *ui.Context, selected *int, labels []string) ui.Element

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 TextArea

func TextArea(c *ui.Context, value *string) ui.Element

TextArea 创建多行输入,内容与撤销状态由 MyGo 管理;等于零值 InputOpt 的 TextAreaWith。

func TextAreaWith

func TextAreaWith(c *ui.Context, value *string, opt InputOpt) ui.Element

TextAreaWith 创建最小两行高的多行输入,保留原生组字、选区和受控值处理。

func TextInput

func TextInput(c *ui.Context, value *string) ui.Element

TextInput 创建单行输入,返回原生元素以设置提示和键盘处理;等于零值 InputOpt 的 TextInputWith。

func TextInputWith

func TextInputWith(c *ui.Context, value *string, opt InputOpt) ui.Element

TextInputWith 创建 28 高的单行输入,文字在高度内垂直居中;在 DialogWith 的正文里,按 Enter 会确认对话框。

func TitleBar

func TitleBar(c *ui.Context, content func()) ui.Element

TitleBar 创建窗口顶栏,可拖动窗口,并避开系统窗口按钮占用的位置。

func ToastHost

func ToastHost(c *ui.Context) ui.Element

ToastHost 在窗口右上角、顶栏下方绘制通知,最新的在最上面;每个窗口的视图里调用一次。

func ToolButton

func ToolButton(c *ui.Context, icon *ui.SVG, label string, chevron bool) ui.Element

ToolButton 创建图标加文字的 ghost 工具按钮:28 高、图标 14,可选尾部下拉箭头。

func Tooltip

func Tooltip(c *ui.Context, anchor ui.Element, text string) ui.Element

Tooltip 每个锚点独立停留 600ms 后显示,保留键盘焦点与 Escape 行为。

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

type ANSIOutputOpt struct {
	Title, CopyLabel string
	Plain            bool
}

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 BadgeKind

type BadgeKind int

BadgeKind 选择徽标表达的语义颜色。

const (
	BadgeNeutral BadgeKind = iota
	BadgeAccent
	BadgeSuccess
	BadgeWarning
	BadgeDanger
)

徽标语义:中性、强调、成功、警告和危险。

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 Command

type Command struct {
	ID, Title, Group string
	Keys             string
	Icon             *ui.SVG
	Disabled         bool
}

Command 是命令面板里的一条命令;Keys 只用于显示,不注册快捷键。

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 Fact

type Fact struct{ Label, Value string }

Fact 是一行事实:标签与值。

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

type ImagePreviewState struct {
	Fit  bool
	Zoom float32
}

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 JSONOpt

type JSONOpt struct{ Title, CopyLabel string }

JSONOpt 设置 JSON 工具栏标题及复制按钮的显示和可访问名称。

type JSONState

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

JSONState 保存已解析的 JSON 与展开、选中、滚动状态。

func NewJSONState

func NewJSONState(data []byte) (*JSONState, error)

NewJSONState 解析任意 JSON 顶级值,包括 null、数组和标量。

func (*JSONState) Set

func (s *JSONState) Set(data []byte) error

Set 解析新内容,成功后替换树,保留仍存在的展开路径;根节点只在第一次设置时展开。

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
	ShareSelection           bool
	OnLink                   func(string)
	Image                    func(string) ImageResource
	OnImage                  func(string)
	CopyLabel, CodeCopyLabel string
	// contains filtered or unexported fields
}

MarkdownOpt 指定流式显示、共享选区和应用提供的图片及链接行为。

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 Motion

type Motion struct {
	Fade, DisclosureOpen, DisclosureClose time.Duration
	Reduced                               bool
}

Motion 保存通用界面过渡时长;Reduced 关闭本库的动画。

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 PatchKind

type PatchKind string

PatchKind 描述片段行的展示类型,不代表完整文件差异。

const (
	PatchContext PatchKind = "context"
	PatchAdded   PatchKind = "added"
	PatchDeleted PatchKind = "deleted"
	PatchHeader  PatchKind = "header"
)

type PatchLine

type PatchLine struct {
	Kind             PatchKind
	Text             string
	OldLine, NewLine *int
}

PatchLine 是调用方已解析的一行片段;缺失行号保持空白,不推测真实位置。

type PatchOpt

type PatchOpt struct{ Title, CopyLabel, Source string }

PatchOpt 保存工具栏名称及完整原文,复制时不从行片段重建补丁。

type SegmentedItem

type SegmentedItem struct {
	Icon    *ui.SVG
	Label   string
	Tooltip string
}

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 SheetSide

type SheetSide int

SheetSide 选择侧边抽屉贴靠的窗口边缘。

const (
	SheetLeft SheetSide = iota
	SheetRight
)

抽屉贴靠左侧或右侧。

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) Size

func (s *TerminalState) Size() (rows, cols int)

Size 返回终端当前的行数和列数。

func (*TerminalState) Text

func (s *TerminalState) Text() string

Text 返回当前屏幕的纯文本,每行去掉行尾空格,末尾空行去掉。

func (*TerminalState) Title

func (s *TerminalState) Title() string

Title 返回程序通过 OSC 设置的窗口标题。

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。

func GetTheme

func GetTheme(c *ui.Context) Theme

GetTheme 返回本窗口的主题值;未设置时采用 One Light。

func OneDark

func OneDark() Theme

OneDark 返回基于 Zed One Dark 的暗色工作台主题。

func OneLight

func OneLight() Theme

OneLight 返回基于 Zed One Light 的明色工作台主题。

func (Theme) Space

func (t Theme) Space(n int) float32

Space 返回 n 个网格单位的间距;只用 1、2、3、4、6、8 档,即 4、8、12、16、24、32,5(20)只用于行高。

func (Theme) TextRole

func (t Theme) TextRole(e ui.Element, role TextRole) ui.Element

TextRole 把文字角色的字号、固定行高、字体和字重应用到文本或容器元素上,颜色和对齐仍由调用方决定。

type ToastKind

type ToastKind string

ToastKind 选择通知的语义图标和颜色。

const (
	ToastInfo    ToastKind = "info"
	ToastSuccess ToastKind = "success"
	ToastError   ToastKind = "error"
)

通知语义:信息、成功和错误。

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 抽屉。

Directories

Path Synopsis
cmd
gallery command

Jump to

Keyboard shortcuts

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