Documentation
¶
Overview ¶
Package tuibase is the consumer-facing entry point for building multi-page terminal applications on the tui-base framework.
It wraps the router package (the root model that owns navigation, theming, the status bar, notifications, and the Ctrl+D inspector) so a full app needs only one import:
err := tuibase.Run(tuibase.Options{
AppName: "My App",
ExtraPages: []tuibase.RegisteredPage{
{Title: "Dashboard", Model: dashboard.New()},
},
})
Apps that need to customize the Bubble Tea program (extra options, custom signal handling) can build the pieces themselves via NewWithOptions and the router package; Run is the batteries-included path.
The runnable reference application lives in cmd/tui-base.
Index ¶
- func EnsureWindowsTerminal()
- func InstallWindowsTerminalProfile(p WindowsTerminalProfile) (fragmentFile string, err error)
- func Run(opts Options, options ...Option) error
- func RunContext(ctx context.Context, opts Options, options ...Option) error
- func UninstallWindowsTerminalProfile(appName string) error
- type Option
- func WithAppName(name string) Option
- func WithAppVersion(version string) Option
- func WithConfigDir(dir string) Option
- func WithConfigDirName(name string) Option
- func WithDebugOverlay(m tea.Model) Option
- func WithDefaultPage(title string) Option
- func WithGates(g *gate.GateRegistry) Option
- func WithInitialLogLevel(level string) Option
- func WithKeyMap(km *keys.AppKeyMap) Option
- func WithPages(pages ...RegisteredPage) Option
- func WithSettingsSections(sections ...config.Section[string]) Option
- func WithWatchSettingsFile() Option
- func WithoutTerminalRelaunch() Option
- type Options
- type RegisteredPage
- type RouterModel
- type WindowsTerminalProfile
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureWindowsTerminal ¶
func EnsureWindowsTerminal()
EnsureWindowsTerminal relaunches the process inside Windows Terminal when it was started under the legacy Windows console (conhost) and, having done so, exits the original process. Call it as the very first statement in main — before any other setup — so apps that bootstrap their own state before tuibase.Run still get the modern terminal without doing that work twice:
func main() {
tuibase.EnsureWindowsTerminal()
// ... app setup, then tuibase.Run(...) ...
}
It does nothing (and returns) on non-Windows platforms, when already in a modern terminal, in a non-interactive session, when wt.exe is missing, or when opted out via TUI_BASE_NO_WT_RELAUNCH. tuibase.Run/RunContext already perform this check, so calling it here is only needed for apps that run setup before Run and want it moved as early as possible. See router.MaybeRelaunchInWindowsTerminal for the full policy.
func InstallWindowsTerminalProfile ¶
func InstallWindowsTerminalProfile(p WindowsTerminalProfile) (fragmentFile string, err error)
InstallWindowsTerminalProfile re-exports router.InstallWindowsTerminalProfile: it registers the app as a Windows Terminal profile (branded name + icon in the new-tab dropdown). Call it from an installer or a setup flag, not on every launch.
func Run ¶
Run builds the router for opts, wraps it in a Bubble Tea program with tui-base's standard options (including the app-derived color-profile env var), and blocks until the program exits. Functional options, when given, apply on top of the struct (see Option).
Example ¶
ExampleRun shows the minimal bootstrap for an application built on tui-base: one call wires the router, theming, status bar, notifications, and the Ctrl+D inspector around your pages.
It has no Output comment on purpose: the example is compile-checked but not executed, because Run blocks on a live terminal.
package main
import (
tuibase "github.com/jarvisfriends/tui-base"
)
func main() {
err := tuibase.Run(tuibase.Options{
AppName: "My App",
ExtraPages: []tuibase.RegisteredPage{
// {Title: "Dashboard", Model: dashboard.New()},
},
})
if err != nil {
panic(err)
}
}
Output:
func RunContext ¶
RunContext is Run bound to ctx: cancel it (e.g. from signal.NotifyContext on SIGINT/SIGTERM) and the program shuts down cleanly with the terminal restored — the graceful-shutdown path for services and wrappers embedding a tui-base app.
func UninstallWindowsTerminalProfile ¶
UninstallWindowsTerminalProfile re-exports router.UninstallWindowsTerminalProfile: it removes the fragment previously installed for appName.
Types ¶
type Option ¶
type Option func(*Options)
Option is a functional option for building an app, Bubble Tea-style (SP-11, shape per Q-21): the struct Options and With* options coexist — pass a struct, a list of options, or both. All options are applied first, then defaults fill anything left unset, exactly like tea.NewProgram:
err := tuibase.Run(tuibase.Options{},
tuibase.WithAppName("My App"),
tuibase.WithPages(tuibase.RegisteredPage{Title: "Dashboard", Model: dash}),
tuibase.WithDebugOverlay(myInspector),
)
func WithAppName ¶
WithAppName sets the display name used in the terminal window title, the info modal, and the derived env-var prefix.
func WithAppVersion ¶
WithAppVersion overrides the version string shown in the info modal.
func WithConfigDir ¶
WithConfigDir overrides the settings configuration directory outright.
func WithConfigDirName ¶
WithConfigDirName sets the subdirectory name under os.UserConfigDir() used for persistent state.
func WithDebugOverlay ¶
WithDebugOverlay stores a model that replaces the built-in inspector as the Ctrl+D debug pop-up (Q-22): while the model is non-nil, tui-base owns the Ctrl+D toggle and presents this model in the inspector's overlay box — pairing with the standalone jarvisfriends/inspector, which delivers itself as a plain tea.Model. The model receives the overlay's inner size as a WindowSizeMsg, all keys while visible (Ctrl+D/Esc close), and mouse events when its View sets OnMouse.
func WithDefaultPage ¶
WithDefaultPage selects the page (by Title) shown on startup.
func WithGates ¶
func WithGates(g *gate.GateRegistry) Option
WithGates supplies the feature-gate registry (see docs/feature-gates.md).
func WithInitialLogLevel ¶
WithInitialLogLevel sets the log level applied at startup.
func WithKeyMap ¶
WithKeyMap replaces the default key map.
func WithPages ¶
func WithPages(pages ...RegisteredPage) Option
WithPages appends application pages (order preserved).
func WithSettingsSections ¶
WithSettingsSections appends app-defined sections to the settings page.
func WithWatchSettingsFile ¶
func WithWatchSettingsFile() Option
WithWatchSettingsFile enables live reload of tui_settings.json (FW-1).
func WithoutTerminalRelaunch ¶
func WithoutTerminalRelaunch() Option
WithoutTerminalRelaunch disables the automatic relaunch into Windows Terminal when started under the legacy console.
type Options ¶
Options re-exports router.Options: startup configuration for the app (name, version, config dir, pages, settings sections).
type RegisteredPage ¶
type RegisteredPage = router.RegisteredPage
RegisteredPage re-exports router.RegisteredPage: one application page (title + model) to add to the router.
type RouterModel ¶
type RouterModel = router.RouterModel
RouterModel re-exports router.RouterModel, the root tea.Model.
func New ¶
func New(options ...Option) *RouterModel
New returns a router built from the given functional options (SP-11); with none it has the built-in pages only (Home and Settings, with the inspector available as the Ctrl+D overlay):
m := tuibase.New(tuibase.WithAppName("My App"), tuibase.WithPages(pages...))
func NewWithOptions ¶
func NewWithOptions(opts Options, options ...Option) *RouterModel
NewWithOptions returns a router configured for the embedding application. Functional options, when given, apply on top of the struct.
type WindowsTerminalProfile ¶
type WindowsTerminalProfile = router.WindowsTerminalProfile
WindowsTerminalProfile re-exports router.WindowsTerminalProfile: the description of a Windows Terminal profile fragment (branded new-tab entry).
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
tui-base
command
Command tui-base runs the reference application showcasing the framework: multi-page routing, theming, notifications, and the Ctrl+D inspector.
|
Command tui-base runs the reference application showcasing the framework: multi-page routing, theming, notifications, and the Ctrl+D inspector. |
|
Package common holds small shared building blocks with no UI dependencies: the Component interface contract for pages, build/version metadata baked in via -ldflags (AppVersion, dependency info for the info modal), and WriteFileAtomic for crash-safe config persistence.
|
Package common holds small shared building blocks with no UI dependencies: the Component interface contract for pages, build/version metadata baked in via -ldflags (AppVersion, dependency info for the info modal), and WriteFileAtomic for crash-safe config persistence. |
|
Package config defines the types that allow any Model to contribute configurable fields to the application's Settings page.
|
Package config defines the types that allow any Model to contribute configurable fields to the application's Settings page. |
|
Package envpath shortens absolute paths for display by collapsing well-known environment-variable prefixes (e.g.
|
Package envpath shortens absolute paths for display by collapsing well-known environment-variable prefixes (e.g. |
|
examples
|
|
|
dashboard
command
Command dashboard shows a single custom page with themed widgets: a bubbles table styled via theme.TableStyles, live status bar segments, and a notification fired from a key press.
|
Command dashboard shows a single custom page with themed widgets: a bubbles table styled via theme.TableStyles, live status bar segments, and a notification fired from a key press. |
|
minimal
command
Command minimal is the smallest possible tui-base app: the built-in Home and Settings pages, theming, notifications, and the Ctrl+D inspector — one import, one call.
|
Command minimal is the smallest possible tui-base app: the built-in Home and Settings pages, theming, notifications, and the Ctrl+D inspector — one import, one call. |
|
multipage
command
Command multipage shows several app pages with custom settings sections and graceful SIGINT/SIGTERM shutdown via RunContext.
|
Command multipage shows several app pages with custom settings sections and graceful SIGINT/SIGTERM shutdown via RunContext. |
|
Package filewatch bridges fsnotify file-system events into Bubble Tea messages so views can live-reload when files change on disk (FW-1).
|
Package filewatch bridges fsnotify file-system events into Bubble Tea messages so views can live-reload when files change on disk (FW-1). |
|
Package logging is tui-base's runtime logger: leveled Debugf/Infof/Warnf/ Errorf functions writing to a rotating file (or the system temp directory), with a subscriber fan-out that feeds the in-app inspector's Log tab.
|
Package logging is tui-base's runtime logger: leveled Debugf/Infof/Warnf/ Errorf functions writing to a rotating file (or the system temp directory), with a subscriber fan-out that feeds the in-app inspector's Log tab. |
|
Package overlay provides shared overlay primitives used by the router's built-in overlays and by page models (settings, dashboard) that manage their own centered form dialogs.
|
Package overlay provides shared overlay primitives used by the router's built-in overlays and by page models (settings, dashboard) that manage their own centered form dialogs. |
|
pages
|
|
|
home
Package home is the default landing page shown when an application supplies no pages of its own — a minimal scrollable example of the page contract (page.Base embedding, theme-driven rendering, wheel/key scrolling).
|
Package home is the default landing page shown when an application supplies no pages of its own — a minimal scrollable example of the page contract (page.Base embedding, theme-driven rendering, wheel/key scrolling). |
|
settings
Package settings is the built-in three-pane settings page: a compact overview of every setting with an edit overlay per item (huh forms for selects/text/file pickers; custom overlays for directories, multi-file lists, durations, dates, and key recording).
|
Package settings is the built-in three-pane settings page: a compact overview of every setting with an edit overlay per item (huh forms for selects/text/file pickers; custom overlays for directories, multi-file lists, durations, dates, and key recording). |
|
Package router provides the root tea.Model for tui-base applications: it owns navigation, active-page selection, the status bar, the shared theme pointer, the notification manager, and the Z-ordered overlay stack (toast, notification history, Ctrl+D inspector, info modal).
|
Package router provides the root tea.Model for tui-base applications: it owns navigation, active-page selection, the status bar, the shared theme pointer, the notification manager, and the Z-ordered overlay stack (toast, notification history, Ctrl+D inspector, info modal). |
|
Package testutil holds tui-base's house-rule test helpers: architecture layering (CheckNoImports) and descriptive type naming (CheckDescriptiveStructNames).
|
Package testutil holds tui-base's house-rule test helpers: architecture layering (CheckNoImports) and descriptive type naming (CheckDescriptiveStructNames). |
|
Package theme is tui-base's compatibility surface over the shared style contract, which moved to github.com/jarvisfriends/snap/styles in the wholesale component wave (ROADMAP SP-2 follow-up, 2026-07-10).
|
Package theme is tui-base's compatibility surface over the shared style contract, which moved to github.com/jarvisfriends/snap/styles in the wholesale component wave (ROADMAP SP-2 follow-up, 2026-07-10). |


