ui

package
v1.0.0-rc.17 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 25 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 ui is the fullscreen Bubble Tea interface: the splash and the first run's login form, then the status bar, transcript and input line. The transcript keeps its own history rather than the terminal's, so paging keys and spoiler re-rendering are handled here.

Index

Constants

This section is empty.

Variables

View Source
var ErrDoorClosed = errors.New("login form closed")

ErrDoorClosed is what a prompt returns once the UI has gone: the user quit at the login form, or the program ended under it. The login flow aborts on it like on any prompter error.

View Source
var Keys = []Key{
	{"enter", "send"},
	{"tab", "complete @names, /commands, ng emotes, :emoji"},
	{"pgup/pgdn", "scroll a page"},
	{"up/down", "scroll a line (the mouse wheel, where it sends arrows)"},
	{"end", "jump to the newest message"},
	{"home", "jump to the oldest, on an empty line"},
	{"ctrl+p/ctrl+n", "recall earlier messages you sent, and back"},
	{"ctrl+s", "reveal or hide spoilers"},
	{"ctrl+t", "show or hide timestamps"},
	{"ctrl+r", "show or hide the roster pane"},
	{"/who", "list who is in the channel"},
	{"f1, /keys", "show this list"},
	{"ctrl+c", "quit; also ctrl+d on an empty line, or /quit"},
}

Keys is the key card. F1, the local /keys and `ngchat -help` all draw it from here, so the three cannot drift apart; a key added to Model.update's switch belongs here too. The completion list's own keys are left out: its header names them while it is open.

Functions

func KeyCard

func KeyCard(indent string) string

KeyCard lays Keys out as aligned lines, each prefixed with indent and none ending in a newline.

Types

type Door

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

Door is the other end of the login form. auth.Login runs on Start's goroutine, off the UI loop, and blocks in Line and Secret until the form answers; the lines it writes (the help under each prompt, a wrong password, where the credential was stored) arrive through Write. Door satisfies auth.Prompter and io.Writer for exactly that.

It is a pointer shared between main and the Model, which Bubble Tea copies on every Update, so all of its state is the channel and the close guard. Nothing is buffered: a prompt or a line waits until the loop pumps it (waitDoor), and Close releases every waiter.

func NewDoor

func NewDoor() *Door

NewDoor returns an open Door. Pass it as Options.Door and as the prompter and writer the login Start runs.

func (*Door) Close

func (d *Door) Close()

Close releases any prompt or write still waiting, with ErrDoorClosed. main calls it once the program has returned; calling it again is a no-op.

func (*Door) Line

func (d *Door) Line(prompt string) (string, error)

Line asks for a visible field and returns it trimmed, as the terminal prompter does.

func (*Door) Secret

func (d *Door) Secret(prompt string) (string, error)

Secret asks for a masked field and returns it as typed.

func (*Door) Write

func (d *Door) Write(p []byte) (int, error)

Write delivers each non-blank line of p as a note. A write after Close is dropped without an error: what it said has nowhere to go, and failing it would turn a stored credential into a failed login.

type Key

type Key struct {
	Press, Does string
}

Key is one line of the key card: what to press, and what it does.

type Model

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

Model is the Bubble Tea root model.

func New

func New(chat *client.Client, opts Options) Model

New builds the UI over a running chat client.

func (Model) Abandoned

func (m Model) Abandoned() bool

Abandoned reports whether the program ended before Start answered: the user quit at the login form, or while the run was starting.

func (Model) Denied

func (m Model) Denied() string

Denied returns the server's entry-gate notice (supporter-only, under 18, e-mail not validated, banned) as terminal text when that is why the client stopped, else "". main prints it after the program exits: the notice is the whole answer and nothing in the TUI can act on it.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (Model) SignedOut

func (m Model) SignedOut() bool

SignedOut reports whether the client stopped because the site refused the remember cookie. main reads it after the program exits.

func (Model) StartErr

func (m Model) StartErr() error

StartErr is why Options.Start could not start the run (a bad chat URL, a login the site refused for good), or nil. main prints it after the program exits.

func (Model) Unshown

func (m Model) Unshown() []string

Unshown returns the login's lines that never reached the screen: the run ended before the join that would have put them in the transcript. main prints them, since one may be where the credential was stored.

func (Model) Update

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

Update implements tea.Model. Whether the reader is away is settled after every message, since keys, focus and resizes can all change it.

func (Model) View

func (m Model) View() tea.View

View implements tea.Model. The alt screen, focus reporting and the window title are declared here rather than as program options: that is how v2 owns terminal modes.

type Options

type Options struct {
	// Channel is the name shown in the status bar and placeholder.
	Channel string
	// Quiet suppresses the terminal bell and the desktop notification
	// on mentions and DMs.
	Quiet bool
	// Theme colors the screen; the zero value means theme.Default().
	Theme theme.Theme
	// LightTheme, when set, replaces Theme if the terminal reports a
	// light background. Leave it zero when the user named a theme: an
	// explicit choice is never second-guessed. A terminal that does not
	// answer the query keeps Theme.
	LightTheme theme.Theme
	// Splash is the opening animation; nil plays none.
	Splash splash.Effect
	// UpdateNotice, when set, runs once off the UI loop at startup and
	// returns a line announcing a newer release, or "" for none. It may
	// block on the network; the UI never waits for it.
	UpdateNotice func() string
	// Start, when set and New was given no client, prepares the run and
	// starts the client off the UI loop, so the splash plays from the
	// first frame instead of after a login on stdin. An error ends the
	// program; StartErr returns it for main to print.
	Start func() (*client.Client, error)
	// Door is the login form Start's login talks to, when it may ask
	// for one. Lines written to it with no form up wait for the join
	// and land in the transcript, like the release notice.
	Door *Door
	// ShowTimes starts the transcript with timestamps on; ctrl+t still
	// toggles them. It is how NGCHAT_TIMES outlives a launch.
	ShowTimes bool
}

Options configures the UI beyond the client it wraps.

Jump to

Keyboard shortcuts

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