tui

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 0 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.

README

tui

github.com/stokaro/kc/tui is a set of building blocks for terminal programs in the style of Midnight Commander, for Bubble Tea v2: a table for long lists, mc's dialog widgets, the F9 menu bar, the F3 viewer and the parts they build on. They come from kc, a two-panel Kubernetes TUI, which now imports them from this module like any other program. Nothing here depends on kc or on Kubernetes.

Status

tui is at v0, and its API may still change. Before v1, a change that breaks callers raises the minor version (v0.4.x to v0.5.0), and additions and fixes raise the patch version. CHANGELOG.md lists every version, with the breaking changes first and what a caller has to change. v1 comes once the API has held still for a while (see Next).

Install

go get github.com/stokaro/kc/tui@latest

tui needs Go 1.27 or later, and at least these versions of the Charm libraries:

Module Version
charm.land/bubbletea/v2 v2.1.2
charm.land/lipgloss/v2 v2.1.1
charm.land/bubbles/v2 v2.2.2
charm.land/glamour/v2 v2.0.1

The repository's CI tests tui on Linux and macOS. shell, shell/hook, app (which holds the shell), examples/files and cmd/bubbleheadless need a Unix system; the other packages also compile for Windows, but nothing tests them there.

Packages

Package What it does
table A table over a long list that reads only the rows on screen, with the cursor and marks kept by row ID.
dialog The widgets and keys of mc's dialogs: input lines, check boxes, rules and buttons in a form; the question, text input and confirmation dialogs.
modal The dialog window with its frame, shadow and key bar, the stack of open dialogs, mc's Esc handling, and the fit of a window over its panel.
menubar The F9 pull-down menu bar, with menus described as data.
keys The function key bar, the Esc and C-x prefixes, Meta digits as function keys, key names in mc notation and a key map.
toast The toast that replaces a bottom line for a few seconds, a rate limit for error toasts, the busy marker over slow work, and the message log behind the toasts.
viewer The F3 text viewer with syntax highlighting and search, for text in memory and for files too large for it.
help The F1 help: a book of linked Markdown pages, its search, and a viewer with mc's keys and colors.
pagedfile Block-wise reading of large text files, with a bounded cache and a streaming search.
overlay One block of styled terminal text drawn over another, as a dialog over the panels.
styles The colors and lipgloss styles of the mc look, with a replaceable panel palette.
skin Panel palettes from YAML skin files, built in or the user's own, and rules that give labels such as a cluster name a color.
kittygfx Images through the Unicode placeholders of the Kitty graphics protocol.
panel One panel: the row source it browses (folders of rows, rows that open folders, the ".." row), the contract of the widgets it shows, and the panel with its frame, modes and quick search.
panel/list The list widget that draws a folder through the table, with the cursor and marks by row ID, group marks and notices.
panel/reload Loading and refreshing panel content in the background, one load at a time.
nav The stack of folders a panel has entered, a walk back to a place along row IDs, and a history of places generic over the program's location type.
shell The embedded subshell behind C-o: the user's shell on a pty, full screen or as the shell line under the panels, the commands it runs and how they ended, restarts after an exit, and handing the terminal to another program.
shell/hook Startup scripts that make bash, zsh, sh and fish report the exit status of each command.
app The two-panel screen: the menu bar row, two panels, the shell line and the function key bar, the focus, mc's order of key handling, the menu bar and the dialogs over the panels, and messages that reach their owner behind a dialog (Background).
cmd/bubbleheadless A headless terminal that runs a program and takes keys and screenshots, for tests.

Each library package has runnable examples on pkg.go.dev.

Examples

Example What it shows
examples/files A two-panel file browser over the local file system, built only from this module: app.Screen with two panels of the list widget, F3 in the viewer, F7 and F8 in dialogs, the F9 menu bar and the C-o shell. A test runs it in cmd/bubbleheadless.

To try it from a checkout of the repository: cd tui && go run ./examples/files [directory].

Quick start

This program builds a table over five rows, moves the cursor down and marks a row, as the keys of a focused panel would, and prints the table without its colors. In a Bubble Tea program, the table lives in the model, Update passes it the key messages, and View draws t.View().

package main

import (
	"context"
	"fmt"
	"strings"

	tea "charm.land/bubbletea/v2"
	"github.com/charmbracelet/x/ansi"

	"github.com/stokaro/kc/tui/table"
)

func main() {
	ctx := context.Background()
	rows := []table.Row{
		table.SimpleRow{ID: "bin", Cells: []string{"bin", "<DIR>", "Nov 28"}},
		table.SimpleRow{ID: "docs", Cells: []string{"docs", "<DIR>", "Nov 29"}},
		table.SimpleRow{ID: "go.mod", Cells: []string{"go.mod", "1.2K", "Nov 27"}},
		table.SimpleRow{ID: "main.go", Cells: []string{"main.go", "8.4K", "Nov 29"}},
		table.SimpleRow{ID: "README.md", Cells: []string{"README.md", "3.1K", "Nov 20"}},
	}
	cols := []table.Column{{Title: "Name"}, {Title: "Size"}, {Title: "Modified"}}

	t := table.NewBigTable(cols, table.NewSliceList(rows), 30, 6)
	t.BorderVertical(ctx, true)
	t.Focus(ctx)

	t.UpdateWithContext(ctx, tea.KeyPressMsg{Code: tea.KeyDown})
	t.UpdateWithContext(ctx, tea.KeyPressMsg{Code: tea.KeyInsert})

	for line := range strings.SplitSeq(ansi.Strip(t.View().Content), "\n") {
		fmt.Printf("|%s|\n", line)
	}
	id, _ := t.CurrentID(ctx)
	fmt.Println("cursor:", id)
	fmt.Println("marked:", t.SelectedIDs())
}

It prints:

|Name           │Size │Modified|
|bin            │<DIR>│Nov 28  |
|docs           │<DIR>│Nov 29  |
|go.mod         │1.2K │Nov 27  |
|main.go        │8.4K │Nov 29  |
|README.md      │3.1K │Nov 20  |
cursor: go.mod
marked: [docs]

The program is the ExampleBigTable example of the table package, and a test keeps the two the same.

Versions

tui versions are tags of the form tui/vX.Y.Z in the kc repository, cut when tui is ready and independent of kc's own releases (vX.Y.Z). Each has a GitHub Release named "tui vX.Y.Z" with the changelog section as its notes. To use a version:

go get github.com/stokaro/kc/tui@v0.4.2

Next

With the two-panel screen and the example, the plan of ADR 0431 is done: kc's mc interface lives in this module. v1 follows once the API has held still for a while. kc remains the larger program that shows how the packages fit together.

License

tui is licensed under the Apache License 2.0, like the rest of the repository. LICENSE and NOTICE in this directory are copies of the repository's.

The overlay package is adapted from bubbletea-overlay, which is under the MIT License. Its license text is kept next to the code, in overlay/LICENSE-MIT, and NOTICE names it.

Documentation

Overview

Package tui is the root of the module github.com/stokaro/kc/tui: the parts of a two-panel terminal program in the style of Midnight Commander, built on Bubble Tea v2.

kc's panels, function key bar, menu bar, dialogs, viewer, embedded shell and the screen that holds them moved into this module one package at a time: the table, the panel and its list widget, the dialog widgets and the dialog stack, the menu bar, the function key bar, the toast line, the viewer, the embedded shell, the two-panel screen and the parts they build on. The module imports nothing from kc, Kubernetes or controller-runtime, and a test in this package fails when it does.

The packages:

  • table: a table over a long list that reads only the rows on screen.
  • dialog: the widgets and the key handling of mc's dialogs, and the question, text input and confirmation dialogs.
  • modal: the dialog window, the stack of open dialogs and mc's Esc handling.
  • menubar: the F9 pull-down menu bar.
  • keys: the function key bar, the Esc and C-x prefixes, key names in mc notation and a key map.
  • toast: the bottom line toast, the busy marker and the message log.
  • viewer: the F3 text viewer, for text in memory and for paged files.
  • help: the F1 help, a book of linked Markdown pages with search.
  • pagedfile: block-wise reading of files too large for memory.
  • overlay: one block of terminal text drawn over another.
  • styles: the colors and styles of the mc look.
  • skin: panel palettes from YAML skin files, and label color rules.
  • kittygfx: images through the Unicode placeholders of the Kitty graphics protocol.
  • panel: one panel: the row source a program implements, the widget contract, and the panel's frame, modes and quick search.
  • panel/list: the list widget that draws a folder through the table.
  • panel/reload: loading and refreshing panel content in the background.
  • nav: the stack of folders a panel has entered, a walk along row IDs, and a history of places.
  • shell: the embedded subshell behind C-o, with the shell line, the status of its commands and its restarts, and handing the terminal to another program.
  • shell/hook: the startup scripts that make a shell report the exit status of each command.
  • app: the two-panel screen, with the focus, mc's order of key handling, the menu bar and the dialogs over the panels, and the messages that reach their owner behind a dialog.
  • cmd/bubbleheadless: a headless terminal driver for tests and screenshots.
  • examples/files: a two-panel file browser built only from these packages.

Versions are tags of the form tui/vX.Y.Z, and the changelog is CHANGELOG.md next to this file. Before v1, a minor version may change the API incompatibly.

Directories

Path Synopsis
Package app is the two-panel screen of an mc-style program: the menu bar row, two panels side by side, the shell line and the function key bar, with the F9 menu bar, the stack of dialogs and the full-screen shell over them.
Package app is the two-panel screen of an mc-style program: the menu bar row, two panels side by side, the shell line and the function key bar, with the F9 menu bar, the stack of dialogs and the full-screen shell over them.
cmd
bubbleheadless command
Command bubbleheadless runs a terminal program without a real terminal and drives it with commands read from standard input.
Command bubbleheadless runs a terminal program without a real terminal and drives it with commands read from standard input.
Package dialog draws the widgets of Midnight Commander's dialogs and runs their keys: lines of text, input lines, check boxes, separator rules and a row of push buttons, with the default button drawn "[< OK >]".
Package dialog draws the widgets of Midnight Commander's dialogs and runs their keys: lines of text, input lines, check boxes, separator rules and a row of push buttons, with the default button drawn "[< OK >]".
examples
files command
Command files is a two-panel file browser in the style of Midnight Commander, built only from the packages of this module.
Command files is a two-panel file browser in the style of Midnight Commander, built only from the packages of this module.
Package help shows a book of Markdown pages in a window, as the F1 help of Midnight Commander does.
Package help shows a book of Markdown pages in a window, as the F1 help of Midnight Commander does.
Package keys holds the key handling of mc's screens that a program shares between its panels, viewers and dialogs: the function key bar, the Esc and C-x prefixes, Meta digits as function keys, key names in mc notation, and a key map that binds those names.
Package keys holds the key handling of mc's screens that a program shares between its panels, viewers and dialogs: the function key bar, the Esc and C-x prefixes, Meta digits as function keys, key names in mc notation, and a key map that binds those names.
Package kittygfx shows images with the Unicode placeholders of the Kitty graphics protocol: an image is sent once, as a virtual placement, and the screen shows it through ordinary text cells, the character U+10EEEE with diacritics for its row and column and the foreground color for its image ID.
Package kittygfx shows images with the Unicode placeholders of the Kitty graphics protocol: an image is sent once, as a virtual placement, and the screen shows it through ordinary text cells, the character U+10EEEE with diacritics for its row and column and the foreground color for its image ID.
Package menubar implements a pull-down menu bar like the one Midnight Commander opens with F9: a one-line bar of menu titles on the top screen row and a framed drop-down under the selected title.
Package menubar implements a pull-down menu bar like the one Midnight Commander opens with F9: a one-line bar of menu titles on the top screen row and a framed drop-down under the selected title.
Package modal is the dialog layer of an mc-style screen: the dialog window with its frame, shadow and key bar, the stack of open dialogs, mc's Esc handling, and the fit of a window over the panel it belongs to.
Package modal is the dialog layer of an mc-style screen: the dialog window with its frame, shadow and key bar, the stack of open dialogs, mc's Esc handling, and the fit of a window over the panel it belongs to.
Package nav moves a panel through folders: the stack of folders it has entered, a walk along row IDs, and the history of places it has been.
Package nav moves a panel through folders: the stack of folders it has entered, a walk along row IDs, and the history of places it has been.
Package overlay draws one block of terminal text over another, the way a dialog covers the panels behind it.
Package overlay draws one block of terminal text over another, the way a dialog covers the panels behind it.
Package pagedfile reads a text file that is too large to hold in memory, one block at a time, so that a viewer can show any part of it without reading the rest.
Package pagedfile reads a text file that is too large to hold in memory, one block at a time, so that a viewer can show any part of it without reading the rest.
Package panel holds one panel of a two-panel program: the row source a program implements for its data, the contract of what a panel shows, and the Panel with its frame, modes and quick search.
Package panel holds one panel of a two-panel program: the row source a program implements for its data, the contract of what a panel shows, and the Panel with its frame, modes and quick search.
list
Package list is the list widget of a panel: it draws a panel.Folder through a table.BigTable that reads only the rows on screen.
Package list is the list widget of a panel: it draws a panel.Folder through a table.BigTable that reads only the rows on screen.
reload
Package reload loads panel content in the background and refreshes it.
Package reload loads panel content in the background and refreshes it.
Package shell is the embedded subshell of a two-panel program, as behind C-o in Midnight Commander: the user's $SHELL on a pseudo-terminal, drawn by a terminal emulator either full screen or as the one shell line under the panels.
Package shell is the embedded subshell of a two-panel program, as behind C-o in Midnight Commander: the user's $SHELL on a pseudo-terminal, drawn by a terminal emulator either full screen or as the one shell line under the panels.
hook
Package hook makes a shell that a terminal program starts report the exit status of each command.
Package hook makes a shell that a terminal program starts report the exit status of each command.
Package skin reads panel skins and label color rules.
Package skin reads panel skins and label color rules.
Package styles holds the colors and lipgloss styles of the Midnight Commander look: white on blue panels with a cyan cursor row, black on light gray dialogs, and a function key bar of black key numbers and cyan labels.
Package styles holds the colors and lipgloss styles of the Midnight Commander look: white on blue panels with a cyan cursor row, black on light gray dialogs, and a function key bar of black key numbers and cyan labels.
Package table shows a long list as a table that reads only the rows on screen, for the panels of a two-panel program.
Package table shows a long list as a table that reads only the rows on screen, for the panels of a two-panel program.
demo command
Command demo shows two tables over the same 1,000 rows of made-up data, side by side, with a status column that changes every second.
Command demo shows two tables over the same 1,000 rows of made-up data, side by side, with a status column that changes every second.
Package toast holds the messages of an mc-style screen's bottom lines: the toast, the busy marker and the message log behind them.
Package toast holds the messages of an mc-style screen's bottom lines: the toast, the busy marker and the message log behind them.
Package viewer shows text in a panel or a window, like Midnight Commander's F3 viewer: scrolling, syntax highlighting, line wrap, a search dialog and selection with the mouse.
Package viewer shows text in a panel or a window, like Midnight Commander's F3 viewer: scrolling, syntax highlighting, line wrap, a search dialog and selection with the mouse.

Jump to

Keyboard shortcuts

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