ui

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: GPL-3.0 Imports: 14 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 (
	RedrawAll    = iota // Redraw everything
	RedrawMenu          // Redraw just the menu
	RedrawTray          // Redraw just the tray
	RedrawResize        // Redraw and recalculate dimensions
)

Redraw types

View Source
const (
	InfoName = iota // Requesting the menu's name
)

Info request types

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

Variables

View Source
var (
	PlayerMenu   *Player    = new(Player) // Full screen player
	QueueMenu    *Queue     = new(Queue)  // Player queue display
	DownloadMenu *Downloads = new(Downloads)
	LibraryMenu  *Library   = 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 and orders a redraw of the menu area This function will block until the new menu is being drawn

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, r chan int, k chan rune, m chan Menu)

InitUI initialises the UI subsystem

func InputLoop

func InputLoop(exit chan int)

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 MenuActive(compare Menu) bool

MenuActive returns true if the current menu claims to be of the same class as the passed menu

"compare" does not necessarily have to be exactly the same type as the current menu

func PassKeystroke

func PassKeystroke(c rune)

PassKeystroke performs a keystroke passthrough for the active menu

func Redraw

func Redraw(mode int)

Redraw signals to redraw a specific part of the UI

This call *will* block if a redraw is in progress but will not fail

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

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 added in v1.1.1

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

func (*Downloads) Cancel added in v1.2.1

func (q *Downloads) Cancel()

func (*Downloads) Enqueue added in v1.1.1

func (q *Downloads) Enqueue()

func (*Downloads) Input added in v1.1.1

func (q *Downloads) Input(c rune)

func (*Downloads) Name added in v1.1.1

func (q *Downloads) Name() string

func (*Downloads) Render added in v1.1.1

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

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) 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)
	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 {
	// contains filtered or unexported fields
}

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)

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)

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