Documentation
¶
Overview ¶
Package uiapp is the in-process App SDK for TTYPE Desk.
Native apps implement App and receive a Context with Host services (notifications, launch, title, close) plus optional lifecycle Hooks. Custom shell programs registered via Add Program run in PTY windows and do not use this SDK — the SDK is for first-party / rich UI apps that need more than a terminal.
Index ¶
- Constants
- type App
- type AudioPlayback
- type Canvas
- func (c *Canvas) Bounds() (cols, rows int)
- func (c *Canvas) Cells() []cell.Cell
- func (c *Canvas) DrawBox(x, y, w, h int, fg, bg cell.Color)
- func (c *Canvas) DrawButton(x, y, w int, label string, fg, bg cell.Color, active bool)
- func (c *Canvas) DrawIcon(x, y int, icon, label string, fg, bg cell.Color, attr cell.Attr)
- func (c *Canvas) DrawScrollbar(x, y, h int, state ScrollState, style ScrollbarStyle)
- func (c *Canvas) DrawText(x, y int, text string, fg, bg cell.Color, attr cell.Attr)
- func (c *Canvas) FillRect(x, y, w, h int, bg cell.Color)
- func (c *Canvas) Resize(cols, rows int)
- func (c *Canvas) SetPalette(fg, bg cell.Color)
- type Context
- func (c *Context) ClipboardGet() string
- func (c *Context) ClipboardSet(text string)
- func (c *Context) DrainTimers() []Event
- func (c *Context) Hooks() Hooks
- func (c *Context) Host() Host
- func (c *Context) Launch(action string) error
- func (c *Context) LoadCredential(key string) ([]byte, error)
- func (c *Context) MarkDirty()
- func (c *Context) Notify(title, body, icon string)
- func (c *Context) OpenPath(path string) error
- func (c *Context) PickFile(startDir string, extensions []string, onResult func(path string, ok bool))
- func (c *Context) PlayAudio(pcm <-chan []int16) (AudioPlayback, error)
- func (c *Context) RequestClose()
- func (c *Context) RunHook(name string, cols, rows int, focused bool)
- func (c *Context) SaveCredential(key string, value []byte) error
- func (c *Context) SetHooks(h Hooks)
- func (c *Context) SetHost(h Host)
- func (c *Context) SetSize(cols, rows int)
- func (c *Context) SetTitle(title string)
- func (c *Context) Size() (cols, rows int)
- func (c *Context) StartTimer(every time.Duration)
- func (c *Context) Stop()
- type Event
- type HookProvider
- type Hooks
- type Host
- type MediaClock
- type ScrollHit
- type ScrollState
- type ScrollbarStyle
Constants ¶
const ( EventKey = "key" EventMouse = "mouse" EventResize = "resize" EventFocus = "focus" EventBlur = "blur" EventTimer = "timer" EventHook = "hook" // Data carries hook name for generic listeners )
Event kinds.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface {
Init(ctx *Context) error
Handle(Event) error
Draw(*Canvas) error
Close() error
}
App is a first-class windowed application (no PTY).
type AudioPlayback ¶
type AudioPlayback interface {
Pause()
Resume()
Playing() bool
Stop()
}
AudioPlayback controls audio started via Host.PlayAudio. Pause/Resume don't restart or re-seek anything — see internal/audio.Playback, the concrete implementation, for why pausing is also free backpressure on whatever's decoding upstream.
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas is a retained-mode cell grid.
func (*Canvas) DrawButton ¶
DrawButton draws a simple clickable-looking button.
func (*Canvas) DrawScrollbar ¶
func (c *Canvas) DrawScrollbar(x, y, h int, state ScrollState, style ScrollbarStyle)
DrawScrollbar paints a vertical scrollbar at (x,y) of height h.
func (*Canvas) SetPalette ¶
type Context ¶
Context provides window services to an app.
func NewContext ¶
func (*Context) ClipboardGet ¶
ClipboardGet reads the shared system clipboard; see Host.ClipboardGet.
func (*Context) ClipboardSet ¶
ClipboardSet writes the shared system clipboard; see Host.ClipboardSet.
func (*Context) DrainTimers ¶
DrainTimers returns due timer events and marks dirty.
func (*Context) LoadCredential ¶
LoadCredential reads back a secret saved under key.
func (*Context) MarkDirty ¶
func (c *Context) MarkDirty()
MarkDirty requests a redraw on the next frame.
func (*Context) PickFile ¶
func (c *Context) PickFile(startDir string, extensions []string, onResult func(path string, ok bool))
PickFile opens a modal file browser; see Host.PickFile.
func (*Context) PlayAudio ¶
func (c *Context) PlayAudio(pcm <-chan []int16) (AudioPlayback, error)
PlayAudio streams pcm to the shared audio output; see Host.PlayAudio.
func (*Context) RequestClose ¶
func (c *Context) RequestClose()
RequestClose asks the shell to close this window.
func (*Context) SaveCredential ¶
SaveCredential persists a secret under key (no-op if host unset).
func (*Context) StartTimer ¶
StartTimer requests periodic EventTimer events.
type Event ¶
type Event struct {
Kind string
Rune rune
Key string
Ctrl bool
Alt bool
Shift bool
X, Y int
Button int
Action string
Cols int
Rows int
Focused bool
Name string // for EventHook
}
Event delivered to apps.
type HookProvider ¶
type HookProvider interface {
Hooks() Hooks
}
HookProvider is an optional interface: apps may return lifecycle hooks.
type Hooks ¶
type Hooks struct {
OnInit func(ctx *Context)
OnClose func(ctx *Context)
OnFocus func(ctx *Context, focused bool)
OnResize func(ctx *Context, cols, rows int)
OnTimer func(ctx *Context)
OnDraw func(ctx *Context, cv *Canvas) // after Draw, for overlays
}
Hooks are optional lifecycle callbacks (beyond Handle events).
type Host ¶
type Host interface {
Notify(title, body, icon string)
Launch(action string) error
OpenPath(path string) error
SetTitle(title string)
RequestClose()
WindowID() string
// SaveCredential/LoadCredential persist a secret (OAuth2 tokens, a
// session token, …) under ~/.config/ttypedesk/credentials/ — never in
// config.json or git. LoadCredential's error wraps os.ErrNotExist when
// nothing has been saved under key yet.
SaveCredential(key string, value []byte) error
LoadCredential(key string) ([]byte, error)
// PickFile opens a small modal file browser rooted at startDir,
// restricted to the given extensions if any are given (without the
// leading dot; empty means no filter). onResult fires exactly once,
// asynchronously, with ok=false if the user cancels.
PickFile(startDir string, extensions []string, onResult func(path string, ok bool))
// PlayAudio streams pcm (interleaved int16 samples, at the fixed
// internal/audio.SampleRate/Channels — decode to that rate/channel
// count, there is no per-call resampling) to the shared audio output.
PlayAudio(pcm <-chan []int16) (AudioPlayback, error)
// ClipboardGet/ClipboardSet read/write the shared system clipboard
// (internal/clip — OSC 52 plus wl-copy/xclip/xsel where available).
// ClipboardGet returns "" if nothing's there yet.
ClipboardGet() string
ClipboardSet(text string)
}
Host is the desktop shell API exposed to native apps.
type MediaClock ¶
type MediaClock struct {
// contains filtered or unexported fields
}
MediaClock is a play/pause/position ticker for transport UI and frame pacing — used by Amp (audio) and Vid (video), not backed by any Host resource, so it's a plain constructable type rather than routed through Host: there's no shared desktop-level state here, just local timing math each window's own player state needs.
func NewMediaClock ¶
func NewMediaClock() *MediaClock
NewMediaClock returns a clock starting paused at position zero.
func (*MediaClock) Playing ¶
func (m *MediaClock) Playing() bool
Playing reports whether the clock is currently running.
func (*MediaClock) Position ¶
func (m *MediaClock) Position() time.Duration
Position returns the current elapsed position.
func (*MediaClock) SetPosition ¶
func (m *MediaClock) SetPosition(d time.Duration)
SetPosition jumps to d (e.g. after a scrub/seek), preserving play state.
type ScrollHit ¶
type ScrollHit int
ScrollHit is the result of hitting a drawn scrollbar.
func HitScrollbar ¶
func HitScrollbar(mx, my, x, y, h int, state ScrollState, showArrows bool) ScrollHit
HitScrollbar hit-tests a vertical bar drawn with DrawScrollbar.
type ScrollState ¶
type ScrollState struct {
Offset int // first visible content unit
Content int // total content units
Viewport int // visible units
}
ScrollState tracks a 1D scrollable viewport (row units for vertical bars).
func (*ScrollState) ApplyScrollHit ¶
func (s *ScrollState) ApplyScrollHit(hit ScrollHit)
ApplyScrollHit updates state for a click (not drag). Page = Viewport.
func (*ScrollState) Clamp ¶
func (s *ScrollState) Clamp()
func (*ScrollState) EnsureVisible ¶
func (s *ScrollState) EnsureVisible(index int)
EnsureVisible scrolls so index is inside the viewport.
func (*ScrollState) MaxOffset ¶
func (s *ScrollState) MaxOffset() int
func (*ScrollState) ScrollBy ¶
func (s *ScrollState) ScrollBy(delta int)
func (ScrollState) ThumbGeom ¶
func (s ScrollState) ThumbGeom(trackH int) (thumbY, thumbH int)
ThumbGeom returns thumb start/height within the track (excluding arrows).
type ScrollbarStyle ¶
type ScrollbarStyle struct {
TrackFG, TrackBG cell.Color
ThumbFG, ThumbBG cell.Color
ArrowFG, ArrowBG cell.Color
ShowArrows bool
}
ScrollbarStyle controls DrawScrollbar colors.
func DefaultScrollbarStyle ¶
func DefaultScrollbarStyle() ScrollbarStyle
DefaultScrollbarStyle is a DOS-ish gray track with dark thumb.