Documentation
¶
Overview ¶
Package rego 提供 React Hooks 风格的 CLI/TUI 开发体验
Index ¶
- func Box(child Node) *boxNode
- func Divider() *dividerNode
- func Empty() *emptyNode
- func HStack(children ...Node) *hstackNode
- func If[T any](cond bool, a, b T) T
- func Markdown(content string) *markdownNode
- func Run(root func(C) Node) error
- func ScrollBox(c C, child Node) *componentNode
- func Spacer() *spacerNode
- func StringWidth(s string) int
- func TailBox(c C, child Node) *componentNode
- func Text(content string) *textNode
- func UseContext[T any](c C, ctx *Context[T]) T
- func UseEffect(c C, fn func() func(), deps ...any)
- func UseKey(c C, handler func(key Key, r rune))
- func UseMemo[T any](c C, fn func() T, deps ...any) T
- func UseMouse(c C, handler func(ev MouseEvent))
- func VStack(children ...Node) *vstackNode
- func When(condition bool, node Node) *whenNode
- func WhenElse(condition bool, trueNode, falseNode Node) *whenElseNode
- type Align
- type BorderChars
- type BorderStyle
- type Bridge
- type ButtonProps
- type C
- type CheckboxProps
- type Color
- type Context
- type FocusManager
- func (fm *FocusManager) Current() string
- func (fm *FocusManager) CurrentContext() *componentContext
- func (fm *FocusManager) Focus(key string)
- func (fm *FocusManager) IsFocused(key string) bool
- func (fm *FocusManager) Next()
- func (fm *FocusManager) Prev()
- func (fm *FocusManager) Register(key string, ctx *componentContext)
- func (fm *FocusManager) Reset()
- func (fm *FocusManager) Unregister(key string)
- type FocusState
- type Handle
- type Key
- type Modifiers
- type MouseButton
- type MouseEvent
- type MouseEventType
- type Node
- func Button(c C, props ButtonProps) Node
- func Center(child Node) Node
- func Checkbox(c C, props CheckboxProps) Node
- func Cursor(c C) Node
- func For[T any](items []T, render func(item T, index int) Node) Node
- func Spinner(c C, label string) Node
- func Stats(c C) Node
- func TextInput(c C, props TextInputProps) Node
- type Rect
- type Ref
- type Runtime
- type State
- type Style
- func (s Style) Align(a Align) Style
- func (s Style) Background(c Color) Style
- func (s Style) Blink() Style
- func (s Style) Bold() Style
- func (s Style) Border(style BorderStyle) Style
- func (s Style) BorderColor(c Color) Style
- func (s Style) Dim() Style
- func (s Style) Flex(f int) Style
- func (s Style) Foreground(c Color) Style
- func (s Style) Height(h int) Style
- func (s Style) Italic() Style
- func (s Style) Padding(v, h int) Style
- func (s Style) PaddingAll(top, right, bottom, left int) Style
- func (s Style) Underline() Style
- func (s Style) Valign(a Align) Style
- func (s Style) Width(w int) Style
- type TextInputProps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UseContext ¶
UseContext 获取 Context 的值 从当前组件向上查找,直到找到 Provider 或返回默认值
Types ¶
type BorderChars ¶
type BorderChars struct {
TopLeft rune
TopRight rune
BottomLeft rune
BottomRight rune
Horizontal rune
Vertical rune
}
BorderChars 边框字符
type BorderStyle ¶
type BorderStyle int
BorderStyle 边框样式
const ( BorderNone BorderStyle = iota BorderSingle BorderDouble BorderRounded BorderThick )
type Bridge ¶
Bridge 是 UI 侧持有的句柄,用于与 Core 通信
func (*Bridge[S, Q, A]) HasInteraction ¶
HasInteraction 检查是否有挂起的交互请求
func (*Bridge[S, Q, A]) Interaction ¶
func (b *Bridge[S, Q, A]) Interaction() Q
Interaction 返回当前的交互请求内容
type ButtonProps ¶
type C ¶
type C interface {
// Child 获取子组件上下文
Child(key string, index ...int) C
// Refresh 手动触发重渲染
Refresh()
// Quit 退出应用
Quit()
// SetCursor 设置光标位置(用于 IME 输入定位)
SetCursor(x, y int)
// Wrap 包装节点以追踪其位置(用于鼠标点击)
Wrap(node Node) *componentNode
// Rect 获取当前组件的屏幕区域
Rect() Rect
}
C 是组件上下文接口
type CheckboxProps ¶
type Context ¶
type Context[T any] struct { // contains filtered or unexported fields }
Context 表示一个可跨组件共享的上下文
func CreateContext ¶
CreateContext 创建一个新的 Context
type FocusManager ¶
type FocusManager struct {
// contains filtered or unexported fields
}
FocusManager 管理所有可聚焦组件
func (*FocusManager) CurrentContext ¶
func (fm *FocusManager) CurrentContext() *componentContext
CurrentContext 获取当前聚焦的组件上下文
func (*FocusManager) IsFocused ¶
func (fm *FocusManager) IsFocused(key string) bool
IsFocused 检查指定组件是否有焦点
func (*FocusManager) Register ¶
func (fm *FocusManager) Register(key string, ctx *componentContext)
Register 注册可聚焦组件
type FocusState ¶
type FocusState struct {
IsFocused bool // 当前是否有焦点
Focus func() // 获取焦点
Blur func() // 失去焦点
// contains filtered or unexported fields
}
FocusState 表示组件的焦点状态
type Key ¶
type Key int
Key 表示特殊按键
const ( KeyNone Key = iota KeyUp KeyDown KeyLeft KeyRight KeyEnter KeyEsc KeyBackspace KeyTab KeySpace KeyHome KeyEnd KeyPageUp KeyPageDown KeyDelete KeyInsert KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyCtrlA KeyCtrlB KeyCtrlC KeyCtrlD KeyCtrlE KeyCtrlF KeyCtrlG KeyCtrlH KeyCtrlI KeyCtrlJ KeyCtrlK KeyCtrlL KeyCtrlN KeyCtrlO KeyCtrlP KeyCtrlQ KeyCtrlR KeyCtrlS KeyCtrlT KeyCtrlU KeyCtrlV KeyCtrlW KeyCtrlX KeyCtrlY KeyCtrlZ )
按键常量
type MouseButton ¶
type MouseButton int
MouseButton 鼠标按钮
const ( MouseButtonNone MouseButton = iota MouseButtonLeft MouseButtonMiddle MouseButtonRight )
type MouseEvent ¶
type MouseEvent struct {
X, Y int
Button MouseButton
Type MouseEventType
}
MouseEvent 鼠标事件
type MouseEventType ¶
type MouseEventType int
MouseEventType 鼠标事件类型
const ( MouseEventPress MouseEventType = iota MouseEventRelease MouseEventClick MouseEventMove MouseEventScrollUp MouseEventScrollDown )
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node 是所有视图节点的接口
func Button ¶
func Button(c C, props ButtonProps) Node
func Checkbox ¶
func Checkbox(c C, props CheckboxProps) Node
func TextInput ¶
func TextInput(c C, props TextInputProps) Node
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime 是应用运行时
func NewTestRuntime ¶
NewTestRuntime 创建一个用于测试的运行时
func (*Runtime) DispatchKey ¶
DispatchKey 分发键盘事件(用于测试)
type State ¶
type State[T any] struct { Val T // contains filtered or unexported fields }
State 表示一个状态值
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style 表示样式
func (Style) Background ¶
func (Style) Border ¶
func (s Style) Border(style BorderStyle) Style
func (Style) BorderColor ¶
func (Style) Foreground ¶
func (Style) PaddingAll ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.