tui

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 33 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

Overview

Package tui is the terminal frontend.

It is a frontend on the same internal API the CLI uses, not a place where logic lives: every behaviour here is reachable headless. Two rules keep it honest, both from the spec:

  • No blocking I/O in Update. Every device call and every disk scan returns a tea.Cmd, so the display never stalls behind a slow Wi-Fi link.
  • Nothing writes to stdout or stderr. Those belong to the renderer; logs go to a file under XDG_STATE_HOME.

Index

Constants

View Source
const (
	GlyphSynced  = "●" // on the device and up to date
	GlyphPending = "◐" // needs upload or re-upload
	GlyphAbsent  = "○" // not on the device
	GlyphOrphan  = "✕" // on the device but not placed by shelf
	GlyphUnknown = "·" // no device selected, or status not yet known
)

Sync-state glyphs for the per-device column in the library table.

Single characters chosen to be legible in a monospace column and to survive terminals with poor emoji support -- a book list is not the place to discover that your font lacks a glyph.

Variables

This section is empty.

Functions

func OpenLog

func OpenLog(path string) (*slog.Logger, io.Closer, error)

OpenLog opens the TUI log file, creating its directory as needed.

The returned closer must be called on exit. If the file cannot be opened, logging is directed to io.Discard rather than failing: an unwritable log directory is not a reason to refuse to run.

func RenderCover

func RenderCover(img image.Image, mode GraphicsMode, cols, rows int) string

RenderCover renders an image into a block of terminal text.

cols and rows are character cells. The image is scaled to fit while keeping its aspect ratio, assuming a cell is roughly twice as tall as it is wide.

Types

type App

type App struct {
	Config *config.Config
	DB     *library.DB
	Log    *slog.Logger
}

App is the shared state the screens read.

type GraphicsMode

type GraphicsMode string

GraphicsMode selects a rendering backend.

const (
	GraphicsNone   GraphicsMode = "none"
	GraphicsBlocks GraphicsMode = "ascii"
	GraphicsSixel  GraphicsMode = "sixel"
	GraphicsKitty  GraphicsMode = "kitty"
)

func DetectGraphics

func DetectGraphics(pref string) GraphicsMode

DetectGraphics chooses a backend.

pref comes from config ui.graphics and wins unless it is "auto". Detection is by environment only: querying the terminal means writing an escape sequence and reading the reply, which fights with Bubble Tea for the same file descriptor and can hang on a terminal that never answers.

type KeyMap

type KeyMap struct {
	// Navigation
	Up       key.Binding
	Down     key.Binding
	Top      key.Binding
	Bottom   key.Binding
	PageUp   key.Binding
	PageDown key.Binding

	// Screens
	NextScreen key.Binding
	PrevScreen key.Binding
	Library    key.Binding
	Devices    key.Binding
	SyncScreen key.Binding

	// Selection
	Select    key.Binding
	VisualSel key.Binding
	SelectAll key.Binding
	ClearSel  key.Binding

	// Detail panel
	Detail     key.Binding
	DetailUp   key.Binding
	DetailDown key.Binding

	// Actions
	Filter  key.Binding
	Sync    key.Binding
	SyncAll key.Binding
	Refresh key.Binding
	Confirm key.Binding
	Cancel  key.Binding

	// Meta
	Help key.Binding
	Quit key.Binding
}

KeyMap is the global keymap. Vim-first, discoverable through bubbles/help.

Bindings live in one place rather than scattered across screens so the help view cannot drift out of sync with what the keys actually do.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the standard bindings.

func (KeyMap) FullHelp

func (k KeyMap) FullHelp() [][]key.Binding

FullHelp is the expanded help, grouped by column.

func (KeyMap) ShortHelp

func (k KeyMap) ShortHelp() []key.Binding

ShortHelp is the one-line help strip.

type Model

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

Model is the root tea.Model.

func New

func New(ctx context.Context, app *App) Model

New builds the root model.

func (Model) Init

func (m Model) Init() tea.Cmd

Init starts the initial loads.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update routes messages. It performs no I/O itself.

func (Model) View

func (m Model) View() string

View renders the frame.

type Screen

type Screen int

Screen identifies a top-level view.

const (
	ScreenLibrary Screen = iota
	ScreenDevices
	ScreenSync
)

func (Screen) String

func (s Screen) String() string

type Styles

type Styles struct {
	App       lipgloss.Style
	Title     lipgloss.Style
	TabActive lipgloss.Style
	TabIdle   lipgloss.Style
	TabBar    lipgloss.Style

	Header   lipgloss.Style
	Row      lipgloss.Style
	RowAlt   lipgloss.Style
	Selected lipgloss.Style
	Cursor   lipgloss.Style

	Status  lipgloss.Style
	Success lipgloss.Style
	Warning lipgloss.Style
	Error   lipgloss.Style
	Subtle  lipgloss.Style
	Accent  lipgloss.Style

	// Header
	Rule      lipgloss.Style
	StatValue lipgloss.Style
	StatLabel lipgloss.Style

	// Detail panel
	Panel        lipgloss.Style
	DetailTitle  lipgloss.Style
	DetailAuthor lipgloss.Style
	Chip         lipgloss.Style

	Box      lipgloss.Style
	Progress lipgloss.Style
	Help     lipgloss.Style
}

Styles holds every lipgloss style the TUI uses.

Colors are given as adaptive pairs so the same build reads correctly on a light and a dark terminal; lipgloss picks per background at runtime.

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles builds the standard theme.

func (Styles) GlyphStyle

func (s Styles) GlyphStyle(glyph string) lipgloss.Style

GlyphStyle colors a sync-state glyph.

Jump to

Keyboard shortcuts

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