uiapp

package
v1.0.260758 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

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

func NewCanvas(cols, rows int) *Canvas

func (*Canvas) Bounds

func (c *Canvas) Bounds() (cols, rows int)

func (*Canvas) Cells

func (c *Canvas) Cells() []cell.Cell

func (*Canvas) DrawBox

func (c *Canvas) DrawBox(x, y, w, h int, fg, bg cell.Color)

func (*Canvas) DrawButton

func (c *Canvas) DrawButton(x, y, w int, label string, fg, bg cell.Color, active bool)

DrawButton draws a simple clickable-looking button.

func (*Canvas) DrawIcon

func (c *Canvas) DrawIcon(x, y int, icon, label string, fg, bg cell.Color, attr cell.Attr)

DrawIcon draws an optional icon glyph then a label (width-aware).

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

func (c *Canvas) DrawText(x, y int, text string, fg, bg cell.Color, attr cell.Attr)

func (*Canvas) FillRect

func (c *Canvas) FillRect(x, y, w, h int, bg cell.Color)

func (*Canvas) Resize

func (c *Canvas) Resize(cols, rows int)

func (*Canvas) SetPalette

func (c *Canvas) SetPalette(fg, bg cell.Color)

type Context

type Context struct {
	WindowID string
	Cols     int
	Rows     int
	// contains filtered or unexported fields
}

Context provides window services to an app.

func NewContext

func NewContext(windowID string, cols, rows int, onDirty func()) *Context

func (*Context) ClipboardGet

func (c *Context) ClipboardGet() string

ClipboardGet reads the shared system clipboard; see Host.ClipboardGet.

func (*Context) ClipboardSet

func (c *Context) ClipboardSet(text string)

ClipboardSet writes the shared system clipboard; see Host.ClipboardSet.

func (*Context) DrainTimers

func (c *Context) DrainTimers() []Event

DrainTimers returns due timer events and marks dirty.

func (*Context) Hooks

func (c *Context) Hooks() Hooks

func (*Context) Host

func (c *Context) Host() Host

func (*Context) Launch

func (c *Context) Launch(action string) error

Launch runs a desktop action (e.g. "terminal", "prog:id", "pty:htop").

func (*Context) LoadCredential

func (c *Context) LoadCredential(key string) ([]byte, error)

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

func (c *Context) Notify(title, body, icon string)

Notify posts a system notification (no-op if host unset).

func (*Context) OpenPath

func (c *Context) OpenPath(path string) error

OpenPath opens a file/directory with the desk default-app associations.

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

func (c *Context) RunHook(name string, cols, rows int, focused bool)

RunHook invokes a named lifecycle hook if set.

func (*Context) SaveCredential

func (c *Context) SaveCredential(key string, value []byte) error

SaveCredential persists a secret under key (no-op if host unset).

func (*Context) SetHooks

func (c *Context) SetHooks(h Hooks)

SetHooks registers lifecycle hooks (usually from HookProvider).

func (*Context) SetHost

func (c *Context) SetHost(h Host)

SetHost attaches shell services (notify, launch, …).

func (*Context) SetSize

func (c *Context) SetSize(cols, rows int)

func (*Context) SetTitle

func (c *Context) SetTitle(title string)

SetTitle updates the window title bar.

func (*Context) Size

func (c *Context) Size() (cols, rows int)

Size returns the current canvas size (thread-safe).

func (*Context) StartTimer

func (c *Context) StartTimer(every time.Duration)

StartTimer requests periodic EventTimer events.

func (*Context) Stop

func (c *Context) Stop()

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

func (m *MediaClock) Pause()

Pause freezes the current position.

func (*MediaClock) Play

func (m *MediaClock) Play()

Play resumes from the current position.

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.

func (*MediaClock) Toggle

func (m *MediaClock) Toggle()

Toggle switches between Play and Pause.

type ScrollHit

type ScrollHit int

ScrollHit is the result of hitting a drawn scrollbar.

const (
	ScrollHitNone ScrollHit = iota
	ScrollHitThumb
	ScrollHitTrackAbove
	ScrollHitTrackBelow
	ScrollHitArrowUp
	ScrollHitArrowDown
)

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.

Jump to

Keyboard shortcuts

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