ui

package
v0.0.0-...-435d922 Latest Latest
Warning

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

Go to latest
Published: May 17, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package ui implements podbit's main UI and front end user code.

This package runs mostly in a separate UI thread and is as thread-safe as possible.

Due to limitations in the C library ncurses, the render loop is designed to only let one thread use ncurses callbacks at a time, with as little loss in performance as possible. Threads will wait for the time to redraw using channels and modes. Usually, three separate threads will run at a time: the menu thread, tray thread and main thread. These all interact using the aforementioned channels to draw the screen in sync.

The "redraw" chanel is the main channel around which the UI code revolves. It is an integer channel which receives a "mode". This mode allows you to select which part of the UI to redraw. This *can* be all of them. The UI threads wait around for the redraw channel to instruct them as to when they should draw the screen.

The "exit" channel simply instructs us to exit immediately. This should *NEVER* be used inside a render callback, least a deadlock in the UI code be caused.

Index

Constants

View Source
const (
	// MessageTime is the maximum time a message will show for.
	MessageTime time.Duration = 2 * time.Second
)

Variables

View Source
var (
	PlayerMenu   = new(Player)    // Full screen player.
	QueueMenu    = new(Queue)     // Player queue display.
	DownloadMenu = new(Downloads) // Shows ongoing downloads.
	LibraryMenu  = new(Library)   // Library of podcasts and episodes.
)

Menu singletons.

Functions

func ActivateMenu

func ActivateMenu(newMenu Menu)

ActivateMenu sets the current menu to the requested value. This DOES NOT redraw the screen until manually caused by an event.

func Exit

func Exit()

Exit requests that the input handler shuts down and gracefully exits the program via a return to the main function.

func InitUI

func InitUI(scr *goncurses.Window, initialMenu Menu, hndl *ev.Handler, k chan rune, m chan Menu, r chan int8)

InitUI initialises the UI subsystem.

func InputLoop

func InputLoop(exit chan struct{})

InputLoop - main UI input handler

Receives all key inputs serially, one character at a time If there is no global keybinding for this key, we pass it to the UI subsystem, which can deal with it from there.

Any and all key inputs causes an immediate and full UI redraw.

func PassKeystroke

func PassKeystroke(c rune)

PassKeystroke performs a keystroke passthrough for the active menu.

func RenderLoop

func RenderLoop()

RenderLoop is the main render callback for the program. This is intended to run in its own thread.

func RenderTray

func RenderTray(scr *goncurses.Window, w, h int)

RenderTray renders the statusbar tray at the bottom of the screen. Tray takes up two vertical cells and the entirety of the width. The top cell is a horizontal line denoting a player status bar. The bottom cell is the status text.

func StatusMessage

func StatusMessage(msg string)

StatusMessage sends a status message to the tray.

Will block for the previous message to finish first. Every message can be guaranteed MessageTime display time.

func UpdateDimensions

func UpdateDimensions(scr *goncurses.Window)

UpdateDimensions changes the dimensions of the drawable area.

Called automatically on detected terminal resizes by the resizeLoop thread.

Types

type Downloads

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

func (*Downloads) Cancel

func (q *Downloads) Cancel()

func (*Downloads) Enqueue

func (q *Downloads) Enqueue()

func (*Downloads) Input

func (q *Downloads) Input(c rune)

func (*Downloads) Name

func (q *Downloads) Name() string

func (*Downloads) Render

func (q *Downloads) Render(x, y int)

func (*Downloads) Should

func (q *Downloads) Should(event int) bool

type Library

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

Library represents the list menu type and state.

Library displays all detected and configured podcasts, along with associated episodes sorted into said podcasts.

func (*Library) ChangeSelection

func (l *Library) ChangeSelection(index int)

func (*Library) Input

func (l *Library) Input(c rune)

func (*Library) MoveSelection

func (l *Library) MoveSelection(direction int)

func (*Library) Name

func (l *Library) Name() string

func (*Library) Render

func (l *Library) Render(x, y int)

func (*Library) Should

func (l *Library) Should(event int) bool

func (*Library) StartDownload

func (l *Library) StartDownload()

StartDownload downloads the currently focused library entry.

func (*Library) StartPlaying

func (l *Library) StartPlaying(immediate bool)

StartPlaying begins playing the currently focused element. If the current focus requires downloading (and enough information is known to oblige) it will first be downloaded.

type Menu interface {
	Name() string
	Render(x, y int)
	Should(event int) bool
	Input(c rune)
}

A Menu is a renderable UI element which takes up most of primary. screen space and is capable of handling unhandled keybinds.

type Player

type Player struct{}

Player is the full screen player component.

Player displays the currently playing episode, the next up episode, progress through the episode etc.

This is mostly for user convenience and visual appeal.

func (*Player) Input

func (l *Player) Input(c rune)

func (*Player) Name

func (l *Player) Name() string

func (*Player) Render

func (l *Player) Render(x, y int)

func (*Player) Should

func (l *Player) Should(event int) bool

type Queue

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

Queue displays the current play queue. Not to be confused with the current download queue, Download.

func (*Queue) Input

func (q *Queue) Input(c rune)

func (*Queue) Name

func (q *Queue) Name() string

func (*Queue) Render

func (q *Queue) Render(x, y int)

func (*Queue) Should

func (q *Queue) Should(event int) bool

Directories

Path Synopsis
Package components implements re-usable sections of UI which can be used by multiple sections of the program in multiple different ways.
Package components implements re-usable sections of UI which can be used by multiple sections of the program in multiple different ways.

Jump to

Keyboard shortcuts

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