ui

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 15 Imported by: 0 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.

Documentation

Index

Constants

View Source
const (
	MenuArtists   = "artists"
	MenuRecent    = "recent"
	MenuPlaylists = "playlists"
	MenuServers   = "servers"
)
View Source
const (
	MinW, MinH = 80, 24
)

Variables

This section is empty.

Functions

func Clock

func Clock(d time.Duration) string

func DrawDeck

func DrawDeck(s tcell.Screen, r Rect, st DeckState)

func DrawHelp

func DrawHelp(s tcell.Screen, r Rect)

func DrawTooSmall

func DrawTooSmall(s tcell.Screen, w, h int)

func Fit

func Fit(text string, width int) string

Fit cuts or pads text to exactly width cells. A wide glyph that would straddle the cut is replaced by a space.

func Marquee

func Marquee(text string, width, tick int) string

Marquee returns a width-cell window onto text. Text that fits is padded; longer text scrolls one grapheme every 4 ticks with a gap before it repeats.

func PutStr

func PutStr(s tcell.Screen, x, y int, text string, style tcell.Style) int

PutStr writes text at x,y one grapheme cluster at a time, advancing by each cluster's display width, and returns the cells used. It does not clip; callers pass text already cut to width (see Fit).

func SeekBarHit

func SeekBarHit(r Rect, x int) float64

SeekBarHit maps a click at column x on the seek row to a fraction of the track, or -1 if the click is outside the bar.

Types

type Action

type Action int
const (
	ActNone Action = iota
	ActQuit
	ActTogglePause
	ActNext
	ActPrev
	ActSeekBack
	ActSeekFwd
	ActVolUp
	ActVolDown
	ActTab
	ActSearch
	ActEnter
	ActAppend
	ActBack
	ActShuffle
	ActRepeat
	ActHelp
	ActUp
	ActDown
	ActPageUp
	ActPageDown
	ActEscape
	ActVisual
	ActSave
	ActClear
	ActRemove
)

func ActionFor

func ActionFor(ev *tcell.EventKey) Action

type Analyzer

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

func NewAnalyzer

func NewAnalyzer(src SpectrumSource) *Analyzer

func (*Analyzer) Draw

func (a *Analyzer) Draw(s tcell.Screen, r Rect)

Draw paints the current mode's view of the last Update.

func (*Analyzer) Mode added in v0.3.0

func (a *Analyzer) Mode() Mode

func (*Analyzer) NextMode added in v0.3.0

func (a *Analyzer) NextMode() Mode

func (*Analyzer) SetMode added in v0.3.0

func (a *Analyzer) SetMode(m Mode)

func (*Analyzer) Update

func (a *Analyzer) Update(w, h int)

Update samples the tap and advances the smoother by one tick. The app calls it on the 30 Hz tick only, so decay runs on time, not on key repeat.

type App

type App struct {

	// OnVisual is told the new mode's name when v changes it, to persist it.
	OnVisual func(name string)
	// contains filtered or unexported fields
}

func New

func New(s tcell.Screen, ctrl *audio.Controller, eng *audio.Engine, lib library.Library, onVolume func(float64)) *App

func (*App) Draw

func (a *App) Draw()

func (*App) Handle

func (a *App) Handle(ev tcell.Event) bool

func (*App) Notify

func (a *App) Notify(msg string)

Notify shows msg in the deck for a few seconds. Safe from any goroutine.

func (*App) Run

func (a *App) Run(ctx context.Context) error

func (*App) SetSaver added in v0.9.0

func (a *App) SetSaver(s Saver)

SetSaver enables w, saving the queue as a playlist.

func (*App) SetSwitcher

func (a *App) SetSwitcher(sw Switcher)

SetSwitcher enables the Servers menu for a multi-server library.

func (*App) SetVisual added in v0.3.0

func (a *App) SetVisual(name string)

SetVisual selects the analyzer mode by its saved name; unknown names are ignored.

type Browser

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

Browser is the Library tab: a stack of views, each a title and a row set. The root is a small menu; Artists is an index of every artist that loads a page at a time as the selection moves.

func NewBrowser

func NewBrowser(lib library.Library) *Browser

func (*Browser) AlbumContext

func (b *Browser) AlbumContext() ([]library.Track, bool)

AlbumContext returns the album's tracks when the current view is an album.

func (*Browser) AlbumTracks

func (b *Browser) AlbumTracks(ctx context.Context, a library.Album) ([]library.Track, error)

AlbumTracks is what `a` on an album appends: the same call the view uses.

func (*Browser) Back

func (b *Browser) Back(context.Context) bool

func (*Browser) CurrentServerName

func (b *Browser) CurrentServerName() string

CurrentServerName is shown in the tab row; empty with a single server.

func (*Browser) JumpLetter

func (b *Browser) JumpLetter(ctx context.Context, r rune) bool

JumpLetter moves the selection to the first artist under r in the Artists view. It reports whether a jump happened.

func (*Browser) List

func (b *Browser) List() *List

func (*Browser) LoadRecent

func (b *Browser) LoadRecent(ctx context.Context) error

func (*Browser) LoadRoot

func (b *Browser) LoadRoot(context.Context) error

LoadRoot resets the stack to the root menu.

func (*Browser) OpenAlbum

func (b *Browser) OpenAlbum(ctx context.Context, a library.Album) error

func (*Browser) OpenArtist

func (b *Browser) OpenArtist(ctx context.Context, a library.Artist) error

func (*Browser) OpenArtists

func (b *Browser) OpenArtists(ctx context.Context) error

OpenArtists opens the index: one row per artist, with only the first page fetched. Rows past it are placeholders until Prepare reaches them.

func (*Browser) OpenPlaylist added in v0.9.0

func (b *Browser) OpenPlaylist(ctx context.Context, p library.Playlist) error

OpenPlaylist pushes a playlist's tracks. It carries them as an album view does, so Enter on a track plays the playlist from there.

func (*Browser) OpenPlaylists added in v0.9.0

func (b *Browser) OpenPlaylists(ctx context.Context) error

OpenPlaylists pushes the list of every server's playlists.

func (*Browser) OpenServers

func (b *Browser) OpenServers(context.Context) error

OpenServers lists the account's servers with the current one marked.

func (*Browser) PlaylistTracks added in v0.9.0

func (b *Browser) PlaylistTracks(ctx context.Context, p library.Playlist) ([]library.Track, error)

PlaylistTracks is what `a` on a playlist row appends: the same call the view uses.

func (*Browser) Prepare

func (b *Browser) Prepare(ctx context.Context, h int)

Prepare loads the rows around the selection before a draw of height h.

func (*Browser) RefreshRoot

func (b *Browser) RefreshRoot(ctx context.Context)

RefreshRoot rebuilds the root menu when the number of servers has changed since it was built, which happens as background connections finish. It does nothing when a deeper view is open.

func (*Browser) ReloadPlaylists added in v0.9.0

func (b *Browser) ReloadPlaylists(ctx context.Context)

ReloadPlaylists refetches the list when it is the open view, keeping the selection, so a playlist saved a moment ago appears. Deeper views are left alone.

func (*Browser) Search

func (b *Browser) Search(ctx context.Context, q string) error

func (*Browser) SetSwitcher

func (b *Browser) SetSwitcher(sw Switcher)

SetSwitcher enables the Servers menu and names servers in search results.

func (*Browser) SwitchServer

func (b *Browser) SwitchServer(ctx context.Context, id string) bool

SwitchServer makes id the current server for browsing and returns to the root menu. It reports whether the switch happened.

func (*Browser) Title

func (b *Browser) Title() string

type DeckState

type DeckState struct {
	Playing          bool
	Position, Length time.Duration
	Artist, Title    string
	Album            string
	Codec            string
	SampleRate       int
	BitDepth         int
	Bitrate          int
	Volume           float64
	Shuffle, Repeat  bool
	Notice           string
	Tick             int
}

type Layout

type Layout struct {
	Deck, Analyzer, Pane Rect
	TooSmall             bool
}

func Compute

func Compute(w, h int) Layout

type List

type List struct {
	Rows     []Row
	Sel, Top int
}

func (*List) Draw

func (l *List) Draw(s tcell.Screen, r Rect, focused bool)

func (*List) Move

func (l *List) Move(delta int)

func (*List) RowAt

func (l *List) RowAt(r Rect, y int) int

func (*List) Selected

func (l *List) Selected() *Row

func (*List) SetRows

func (l *List) SetRows(rows []Row)

type Mode added in v0.3.0

type Mode int

Mode selects what the analyzer pane draws from the tap.

const (
	ModeBars        Mode = iota // the spectrum analyzer
	ModeScope                   // the oscilloscope
	ModeSpectrogram             // the waterfall
	ModeStereo                  // the stereo field
)

func ParseMode added in v0.3.0

func ParseMode(name string) (Mode, bool)

ParseMode returns the mode for a saved name, and whether the name was known.

func (Mode) String added in v0.3.0

func (m Mode) String() string

type Rect

type Rect struct{ X, Y, W, H int }

type Row

type Row struct {
	Text, Right string
	Header      bool
	Menu        string // a root menu entry: MenuArtists, MenuRecent or MenuServers
	ServerID    string // a server row in the Servers view
	Album       *library.Album
	Track       *library.Track
	Artist      *library.Artist
	Playlist    *library.Playlist
	Playing     bool
	// contains filtered or unexported fields
}

func QueueRows

func QueueRows(ts []library.Track, playing int) []Row

type Saver added in v0.9.0

type Saver interface {
	SaveQueue(ctx context.Context, name string, tracks []library.Track) ([]library.Saved, error)
}

Saver saves a queue to the servers its tracks live on.

type SearchField

type SearchField struct {
	Text  string
	Open  bool
	Label string // drawn before the text; empty means the search's "/"
}

func (*SearchField) Draw

func (f *SearchField) Draw(s tcell.Screen, r Rect)

func (*SearchField) Key

func (f *SearchField) Key(ev *tcell.EventKey) (submit, cancel bool)

Key feeds a key event to the field. submit is true on Enter with text, cancel on Escape; both close the field.

type SpectrumSource

type SpectrumSource interface {
	Spectrum(n int, dst []float64) int // mono frames at the playhead
	Stereo(n int, l, r []float64) int  // the same frames, channels apart
	Rate() int                         // frames per second those are
}

type Switcher

type Switcher interface {
	Servers() []multi.Server
	Current() multi.Server
	SetCurrent(id string) bool
}

Switcher is the multi-server view the Library tab needs: which servers exist, which is current, and a way to change it.

Jump to

Keyboard shortcuts

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