Terminal console: bare rollcall in a terminal opens a full-screen UI (llmgw style)
CI / agent (push) Successful in 3s
CI / site (push) Successful in 2s
CI / go (push) Successful in 1m31s

- Bubble Tea + lipgloss with the same frame as llmgw: title bar, sidebar, bordered panel,
  key line, dialog overlay; keyboard only
- pages: overview, machines (filter, state filter, multi-select, bulk actions), machine
  detail, racks with elevation, jobs, events, tags, profiles, OS images
- actions: power, boot device, deploy OS, assign/unassign, tags, location, re-commission,
  release, cancel job, delete; confirmation for destructive ones; per-machine results
- connect screen when no server is configured; URL + token saved to
  ~/.config/rollcall/client.json (0600), also used by the CLI
- batched runes outside text fields are handled key by key
- rollcall tui -dump WxH renders one screen; first Go tests for rendering and keys
- web: unnamed machines show their id instead of the live image's hostname

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-27 20:00:51 +01:00
1 parent 5ee35037e5
commit e3d9373201
10 files changed
+2662 -9

No files matched your search

+5
View File
@@ -21,6 +21,11 @@ publish a tag that has no section here.
CSV import matched by id/serial/MAC/node name with dry run, rack definitions with height,
`list -rack/-room/-building`, location column and chips in the UI, Racks page with
elevation views, bulk "Set location…", `.Node.Rack` etc. in templates and tag rules.
- Terminal console: a bare `rollcall` in a terminal opens a full-screen UI in the llmgw style
(Bubble Tea): overview, machines with filter/selection/bulk actions, machine detail, racks
with elevation, jobs, events, tags, profiles, OS images; connect screen that saves
`~/.config/rollcall/client.json`, which the CLI also reads; `rollcall tui -dump` renders one
screen. First Go tests (console rendering and keys).
- `rollcall version`; CD-built binary carries `git describe`.
- Release notes from `CHANGELOG.md`.
+24
View File
@@ -72,6 +72,30 @@ cd deploy && sudo ./install.sh
command line baked into generated PXE files), `bmc_hints` (out-of-band BMC
mapping for machines without in-band IPMI, e.g. VMs).
### Console (same binary)
A bare `rollcall` in a terminal opens a full-screen console, built like the
llmgw one (Bubble Tea): the fleet down the left (Overview, Machines, Racks,
Jobs, Events) and provisioning (Tags, Profiles, OS images), the chosen page on
the right, keys along the bottom. It is keyboard only, so it works on serial
consoles and BMC KVMs.
* Machines: `/` filter (name, serial, MAC, IP, rack, tag), `s` cycles the state
filter, `Space` selects, `*` selects everything shown, `Enter` opens a
machine, `a` opens the actions for the selection or the current row: power,
boot device, deploy OS, assign/unassign profile, tags, location,
re-commission, release, cancel job, delete. Destructive ones ask first.
* Racks: `Enter` shows the elevation; `Enter` on a unit opens that machine.
* Jobs and events open the machine they belong to; tags, profiles and OS
images show their definition. `r` refreshes (it also refreshes on its own,
every 3 s while a job runs), `?` lists the keys, `q` quits.
On the server as root it reads `/etc/rollcall/config.json`. Anywhere else it
asks for the server URL and admin token once and keeps them in
`~/.config/rollcall/client.json` (mode 0600), which the CLI then uses as well.
In a pipe or a script a bare `rollcall` prints its help as before.
`rollcall tui -dump 140x40 -page machines -plain` renders one screen to stdout.
### CLI (same binary)
```sh
+11 -1
View File
@@ -32,7 +32,17 @@ func newClient() (*client, error) {
}
}
if base == "" || token == "" {
return nil, fmt.Errorf("set ROLLCALL_URL and ROLLCALL_TOKEN (or make the config file readable)")
if cc, ok := loadClientConf(); ok {
if base == "" {
base = cc.URL
}
if token == "" {
token = cc.Token
}
}
}
if base == "" || token == "" {
return nil, fmt.Errorf("set ROLLCALL_URL and ROLLCALL_TOKEN, make the server config readable, or run rollcall in a terminal to connect")
}
return &client{base: strings.TrimRight(base, "/"), token: token, http: &http.Client{Timeout: 90 * time.Second}}, nil
}
+23 -3
View File
@@ -1,18 +1,38 @@
module rollcall
go 1.24
go 1.24.2
require (
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/lipgloss v1.1.0
github.com/charmbracelet/x/ansi v0.11.6
github.com/jackc/pgx/v5 v5.7.5
github.com/klauspost/compress v1.18.0
github.com/mattn/go-isatty v0.0.24
golang.org/x/crypto v0.37.0
)
require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/colorprofile v0.4.1 // indirect
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.9.0 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.24.0 // indirect
)
+45 -2
View File
@@ -1,6 +1,28 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
github.com/clipperhouse/displaywidth v0.9.0/go.mod h1:aCAAqTlh4GIVkhQnJpbL0T/WfcrJXHcj8C0yjYcjOZA=
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
@@ -11,19 +33,40 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
+18 -2
View File
@@ -24,6 +24,8 @@ var version = "dev"
func usage() {
_, _ = os.Stderr.WriteString(`usage:
rollcall in a terminal: the full-screen console
rollcall tui [-dump WxH -page P -machine ID -plain]
rollcall serve [-config PATH]
rollcall version
rollcall keygen
@@ -51,7 +53,8 @@ func usage() {
rollcall location racks | rack NAME -building B -room R [-height 42]
rollcall list [-tag T] [-building B] [-room R] [-rack K]
(deploy, power and location take tag:NAME instead of ID to act on every machine with that tag)
env: ROLLCALL_URL (default from config listen), ROLLCALL_TOKEN, ROLLCALL_CONFIG
env: ROLLCALL_URL (default from config listen), ROLLCALL_TOKEN, ROLLCALL_CONFIG;
away from the server the console saves URL and token in ~/.config/rollcall/client.json
`)
os.Exit(2)
}
@@ -61,10 +64,23 @@ func newFlags(name string) *flag.FlagSet { return flag.NewFlagSet(name, flag.Exi
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
if len(os.Args) < 2 {
usage()
// A bare `rollcall` in a terminal opens the console; in a pipe or a
// script it prints its help, as it always did.
if !interactive() {
usage()
}
if err := runTUI(); err != nil {
log.Fatal(err)
}
return
}
cmd, args := os.Args[1], os.Args[2:]
switch cmd {
case "tui", "console":
if err := tuiDump(args); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
case "serve":
fs := flag.NewFlagSet("serve", flag.ExitOnError)
cfg := fs.String("config", envOr("ROLLCALL_CONFIG", "/etc/rollcall/config.json"), "config file")
+2015
View File
File diff suppressed because it is too large. Load diff
+362
View File
@@ -0,0 +1,362 @@
package main
// The frame every full-screen rollcall screen is drawn in, the same design as
// llmgw's: a title bar, a sidebar on the left, the content in a bordered panel
// on the right, the keys along the bottom, and a dialog over it all when one is
// open. Keyboard only: these screens run on serial consoles and BMC KVMs as
// often as in a desktop terminal.
//
// The two widgets are written here rather than taken from bubbles: its
// packages ask the terminal for its colours as they load, which would make
// every CLI subcommand wait on a terminal that never answers.
import (
"strings"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
)
var (
tuiAccent = lipgloss.AdaptiveColor{Light: "#0B7F7D", Dark: "#3FC2BC"}
tuiOK = lipgloss.AdaptiveColor{Light: "#1F8A4C", Dark: "#6FD3A6"}
tuiWarn = lipgloss.AdaptiveColor{Light: "#A15C00", Dark: "#E9B35A"}
tuiBad = lipgloss.AdaptiveColor{Light: "#B42318", Dark: "#F07C6C"}
tuiDim = lipgloss.AdaptiveColor{Light: "#56696C", Dark: "#8FA5A4"}
sTitle = lipgloss.NewStyle().Bold(true).Foreground(tuiAccent)
sBold = lipgloss.NewStyle().Bold(true)
sDim = lipgloss.NewStyle().Foreground(tuiDim)
sOK = lipgloss.NewStyle().Foreground(tuiOK)
sWarn = lipgloss.NewStyle().Foreground(tuiWarn)
sBad = lipgloss.NewStyle().Foreground(tuiBad)
fBar = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.AdaptiveColor{Light: "#FFFFFF", Dark: "#0B1B1B"}).Background(tuiAccent)
fBorder = lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).BorderForeground(tuiDim)
fFocus = lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).BorderForeground(tuiAccent)
fKeys = lipgloss.NewStyle().Foreground(tuiDim)
fSelected = lipgloss.NewStyle().Bold(true).Foreground(tuiAccent)
fDialog = lipgloss.NewStyle().Border(lipgloss.DoubleBorder()).BorderForeground(tuiAccent).Padding(1, 2)
)
const navWidth = 22
// navItem is one line of the sidebar.
type navItem struct {
Label string
State string // "done", "current", "todo" for steps; "" for menu entries
Current bool
Dim bool
Heading bool // a title between groups, not an entry
}
type frame struct {
Width, Height int
Title string // left of the title bar
Where string // right of the title bar
Nav []navItem
PanelTitle string
Body string
Scroll int // body lines scrolled off the top
Keys string
Dialog string
DialogTitle string
}
// render draws the whole screen, exactly Width by Height.
func (f frame) render() string {
w, h := max(f.Width, 60), max(f.Height, 16)
title := " " + f.Title
right := version + " "
if f.Where != "" {
right = f.Where + " · " + right
}
gap := max(1, w-ansi.StringWidth(title)-ansi.StringWidth(right))
bar := fBar.Render(truncateWidth(title+strings.Repeat(" ", gap)+right, w))
ph := h - 2
inner := ph - 2
var navLines []string
cur := 0
for _, it := range f.Nav {
mark := " "
label := it.Label
if it.Heading {
navLines = append(navLines, sDim.Render(label))
continue
}
if it.Current || it.State == "current" {
cur = len(navLines)
}
switch {
case it.State == "done":
mark = sOK.Render("✓ ")
case it.State == "current", it.Current:
mark = fSelected.Render("› ")
label = fSelected.Render(label)
case it.Dim || it.State == "todo":
label = sDim.Render(label)
}
navLines = append(navLines, truncateWidth(mark+label, navWidth-2))
}
if len(navLines) > inner {
total := len(navLines)
top := min(max(0, cur-inner/2), total-inner)
navLines = append([]string{}, navLines[top:top+inner]...)
if top > 0 {
navLines[0] = sDim.Render(" ↑ more")
}
if top+inner < total {
navLines[inner-1] = sDim.Render(" ↓ more")
}
}
left := box(fBorder, "", strings.Join(navLines, "\n"), navWidth, inner)
pw := w - navWidth - 2 - 2
lines := strings.Split(strings.TrimRight(f.Body, "\n"), "\n")
scroll := min(max(f.Scroll, 0), max(0, len(lines)-inner))
visible := lines[scroll:]
if len(visible) > inner {
visible = visible[:inner]
visible[inner-1] = sDim.Render(" ↓ more — PgDn")
}
for i := range visible {
visible[i] = truncateWidth(visible[i], pw)
}
panelTitle := f.PanelTitle
if scroll > 0 {
panelTitle += " ↑"
}
main := box(fFocus, panelTitle, strings.Join(visible, "\n"), pw, inner)
keys := fKeys.Render(" " + truncateWidth(f.Keys, w-2))
screen := bar + "\n" + lipgloss.JoinHorizontal(lipgloss.Top, left, main) + "\n" + keys
if f.Dialog != "" {
dw := min(w-8, max(50, maxLineWidth(f.Dialog)+6))
d := fDialog.Width(dw).Render(f.Dialog)
if f.DialogTitle != "" {
d = titled(d, f.DialogTitle)
}
screen = overlay(screen, d, w, h)
}
return screen
}
func box(style lipgloss.Style, title, content string, width, height int) string {
b := style.Width(width).Height(height).Render(content)
if title == "" {
return b
}
return titled(b, title)
}
// titled sets " title " into a box's top border, after its corner.
func titled(b, title string) string {
lines := strings.Split(b, "\n")
if len(lines) == 0 {
return b
}
top := lines[0]
t := " " + title + " "
tw := ansi.StringWidth(t)
if ansi.StringWidth(top) < tw+4 {
return b
}
lines[0] = ansi.Truncate(top, 2, "") + sTitle.Render(t) + ansi.TruncateLeft(top, 2+tw, "")
return strings.Join(lines, "\n")
}
// overlay draws top over the middle of base, both w by h.
func overlay(base, top string, w, h int) string {
bl := strings.Split(base, "\n")
tl := strings.Split(top, "\n")
tw := maxLineWidth(top)
x := max(0, (w-tw)/2)
y := max(0, (h-len(tl))/2)
for i, l := range tl {
row := y + i
if row >= len(bl) {
break
}
under := bl[row]
left := ansi.Truncate(under, x, "")
if pad := x - ansi.StringWidth(left); pad > 0 {
left += strings.Repeat(" ", pad)
}
right := ansi.TruncateLeft(under, x+ansi.StringWidth(l), "")
bl[row] = left + l + right
}
return strings.Join(bl, "\n")
}
func maxLineWidth(s string) int {
n := 0
for _, l := range strings.Split(s, "\n") {
n = max(n, ansi.StringWidth(l))
}
return n
}
// truncateWidth cuts a line, colours and all, to w cells.
func truncateWidth(s string, w int) string {
if ansi.StringWidth(s) <= w {
return s
}
return ansi.Truncate(s, max(w-1, 0), "…")
}
// table draws rows under a header in columns as wide as they need, cut to
// width; the selected row is shown reversed when the panel has the focus.
func table(headers []string, rows [][]string, selected int, width int, focused bool) string {
widths := make([]int, len(headers))
for i, h := range headers {
widths[i] = ansi.StringWidth(h)
}
for _, r := range rows {
for i := range headers {
if i < len(r) {
widths[i] = min(max(widths[i], ansi.StringWidth(r[i])), 40)
}
}
}
line := func(cells []string) string {
var b strings.Builder
for i := range headers {
c := ""
if i < len(cells) {
c = truncateWidth(cells[i], widths[i])
}
b.WriteString(c)
if i < len(headers)-1 {
b.WriteString(strings.Repeat(" ", widths[i]-ansi.StringWidth(c)+2))
}
}
return truncateWidth(b.String(), width)
}
var b strings.Builder
b.WriteString(" " + lipgloss.NewStyle().Bold(true).Foreground(tuiDim).Render(line(headers)) + "\n")
for i, r := range rows {
l := line(r)
switch {
case i == selected && focused:
plain := ansi.Strip(l)
pad := max(0, width-ansi.StringWidth(plain))
l = fBar.Render(plain + strings.Repeat(" ", pad))
case i == selected:
l = sBold.Render(ansi.Strip(l))
}
b.WriteString(" " + l + "\n")
}
if len(rows) == 0 {
b.WriteString(" " + sDim.Render("nothing yet") + "\n")
}
return b.String()
}
// wrap breaks text at spaces to width; continuation lines start with indent.
func wrap(s string, width int, indent string) string {
if width < 10 {
return s
}
var out []string
for _, para := range strings.Split(s, "\n") {
line := ""
for _, word := range strings.Fields(para) {
if line != "" && ansi.StringWidth(line)+1+ansi.StringWidth(word) > width {
out = append(out, line)
line = indent + word
continue
}
if line == "" {
line = word
} else {
line += " " + word
}
}
out = append(out, line)
}
return strings.Join(out, "\n")
}
// ---------------------------------------------------------------- widgets
type spinTickMsg struct{}
var spinFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
type spinnerModel struct{ frame int }
func (s spinnerModel) Tick() tea.Msg { return spinTickMsg{} }
func (s spinnerModel) Update(msg tea.Msg) (spinnerModel, tea.Cmd) {
if _, ok := msg.(spinTickMsg); !ok {
return s, nil
}
s.frame = (s.frame + 1) % len(spinFrames)
return s, tea.Tick(100*time.Millisecond, func(time.Time) tea.Msg { return spinTickMsg{} })
}
func (s spinnerModel) View() string { return sTitle.Render(spinFrames[s.frame]) }
// textField is one line of text typed at its end: all a form here needs.
type textField struct {
value []rune
focused bool
Prompt string
Placeholder string
CharLimit int
Mask bool // a password
}
func newTextField() textField { return textField{} }
func (f *textField) SetValue(s string) { f.value = []rune(s) }
func (f textField) Value() string { return string(f.value) }
func (f *textField) Focus() { f.focused = true }
func (f *textField) Blur() { f.focused = false }
func (f textField) Update(msg tea.Msg) (textField, tea.Cmd) {
k, ok := msg.(tea.KeyMsg)
if !ok || !f.focused {
return f, nil
}
switch k.Type {
case tea.KeyRunes, tea.KeySpace:
r := k.Runes
if k.Type == tea.KeySpace {
r = []rune{' '}
}
for _, c := range r {
if f.CharLimit == 0 || len(f.value) < f.CharLimit {
f.value = append(f.value, c)
}
}
case tea.KeyBackspace:
if len(f.value) > 0 {
f.value = f.value[:len(f.value)-1]
}
case tea.KeyCtrlU:
f.value = nil
}
return f, nil
}
func (f textField) View() string {
text := string(f.value)
if f.Mask {
text = strings.Repeat("•", len(f.value))
}
shown := text
if text == "" && f.Placeholder != "" {
shown = sDim.Render(f.Placeholder)
}
if f.focused {
shown += "█"
}
return f.Prompt + shown
}
+158
View File
@@ -0,0 +1,158 @@
package main
import (
"encoding/json"
"strings"
"testing"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
)
// fakeModel is a console with a small fleet loaded, no server needed.
func fakeModel(t *testing.T, w, h int) tuiModel {
t.Helper()
now := time.Now()
sp, _ := json.Marshal(DeploySpec{OS: "rocky-9", Version: "20261027-92c206", Disk: "/dev/sda"})
prog := json.RawMessage(`{"phase":"writing","pct":42,"msg":"42% of 552 MiB"}`)
job := &Job{ID: "j-1", MachineID: "m-a", Kind: "deploy", State: "running", Spec: sp, Progress: prog, Created: now}
name, os, ip := "node001", "rocky-9", "10.0.0.50"
bmc := obj{"address": "10.0.0.11", "configured": true}
m := newTUIModel(&client{base: "http://test"})
m.w, m.h = w, h
m.loaded = true
m.d = tuiData{at: now,
machines: []Summary{
{ID: "m-a", State: "deploying", NodeName: &name, OS: &os, MgmtIP: &ip, CPUs: "64", MemoryBytes: 512 << 30, Disks: 2, StorageBytes: 8 << 40, GPUs: 4, IBHCAs: 2,
BMC: &bmc, Tags: []string{"gpu", "rack-3"}, ManualTags: []string{"rack-3"}, AutoTags: []string{"gpu"}, Job: job, LastSeen: &now,
Location: Location{Building: "DC1", Room: "Hall A", Rack: "R12", Unit: 24}},
{ID: "m-b", State: "ready", CPUs: "32", MemoryBytes: 256 << 30, LastSeen: &now},
},
racks: []Rack{{Building: "DC1", Room: "Hall A", Name: "R12", Height: 42}},
jobs: []*Job{job},
events: []MachineEvent{{Event: Event{TS: now, Event: "deploy started", Detail: "job=j-1"}, MachineID: "m-a"}},
tags: []TagDef{{Name: "gpu", Match: "{{ gt .Node.GPUs 0 }}", CloudConfig: "#cloud-config\npackages: [x]", Machines: 1}},
os: []OSImage{{Name: "rocky-9", Current: &OSMeta{Version: "20261027-92c206", Size: 553 << 20, RawSize: 10 << 30, Imported: now}}},
}
return m
}
func TestTUIPagesRender(t *testing.T) {
for _, size := range [][2]int{{140, 40}, {80, 24}, {60, 16}} {
for page := 0; page < pCount; page++ {
m := fakeModel(t, size[0], size[1])
m.menu, m.inPanel = page, true
out := ansi.Strip(m.View())
lines := strings.Split(out, "\n")
if len(lines) != max(size[1], 16) {
t.Errorf("%dx%d %s: %d lines", size[0], size[1], pageNames[page], len(lines))
}
for i, l := range lines {
if w := ansi.StringWidth(l); w > max(size[0], 60) {
t.Errorf("%dx%d %s: line %d is %d wide", size[0], size[1], pageNames[page], i, w)
}
}
if !strings.Contains(out, pageLabels[page]) {
t.Errorf("%s: label missing", pageNames[page])
}
}
}
}
func TestTUIMachinesListAndFilter(t *testing.T) {
m := fakeModel(t, 160, 30)
m.menu, m.inPanel = pMachines, true
out := ansi.Strip(m.View())
for _, want := range []string{"node001", "deploying 42%", "Hall A/R12 U24", "64c 512.0G 2×8.0T 4GPU 2IB", "m-b"} {
if !strings.Contains(out, want) {
t.Errorf("machines page lacks %q", want)
}
}
m.filter.SetValue("r12")
if got := len(m.filtered()); got != 1 {
t.Errorf("filter r12: %d machines, want 1", got)
}
m.filter.SetValue("")
m.stateF = "ready"
if got := m.filtered(); len(got) != 1 || got[0].ID != "m-b" {
t.Errorf("state filter: %+v", got)
}
}
func TestTUIKeysSelectionAndActions(t *testing.T) {
m := fakeModel(t, 140, 40)
press := func(s string) {
var k tea.KeyMsg
switch s {
case "enter":
k = tea.KeyMsg{Type: tea.KeyEnter}
case "esc":
k = tea.KeyMsg{Type: tea.KeyEsc}
case " ":
k = tea.KeyMsg{Type: tea.KeySpace}
default:
k = tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(s)}
}
mm, _ := m.Update(k)
m = mm.(tuiModel)
}
press("j") // Machines
press("enter")
if !m.inPanel || m.menu != pMachines {
t.Fatalf("not in the machines panel: menu=%d inPanel=%v", m.menu, m.inPanel)
}
press(" ")
press(" ")
if len(m.sel) != 2 {
t.Fatalf("selected %d, want 2", len(m.sel))
}
press("a")
if m.dlg == nil || !strings.Contains(m.dlg.title, "2 machines") {
t.Fatalf("actions dialog for the selection not open: %+v", m.dlg)
}
out := ansi.Strip(m.View())
for _, want := range []string{"Power cycle", "Deploy OS…", "Location…", "Delete record"} {
if !strings.Contains(out, want) {
t.Errorf("actions menu lacks %q", want)
}
}
// Deploy OS… opens a form with the OS image choice
for i, it := range m.dlg.menu {
if it.label == "Deploy OS…" {
m.dlg.focus = i
}
}
press("enter")
if m.dlg == nil || len(m.dlg.fields) == 0 || m.dlg.fields[0].value() != "rocky-9" {
t.Fatalf("deploy form not open with rocky-9: %+v", m.dlg)
}
press("esc")
press("esc") // clears the selection
if len(m.sel) != 0 {
t.Errorf("Esc did not clear the selection")
}
}
func TestTUIBatchedRunes(t *testing.T) {
m := fakeModel(t, 140, 40)
mm, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("jj")})
if got := mm.(tuiModel).menu; got != pRacks {
t.Errorf("\"jj\" in one message moved to page %d, want %d (Racks)", got, pRacks)
}
m.filtering = true
m.filter.Focus()
mm, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("r12")})
if got := mm.(tuiModel).filter.Value(); got != "r12" {
t.Errorf("typed into the filter: %q, want r12", got)
}
}
func TestTUIRackElevation(t *testing.T) {
m := fakeModel(t, 120, 60)
m.menu, m.inPanel, m.rackOpen = pRacks, true, 0
out := ansi.Strip(m.View())
if !strings.Contains(out, "24 │ node001") {
t.Errorf("elevation lacks node001 at U24:\n%s", out)
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ const human = n => { n = Number(n || 0); const u = ['B', 'K', 'M', 'G', 'T', 'P'
const ago = ts => { if (!ts) return '-'; const s = (Date.now() - new Date(ts)) / 1000; if (s < 90) return `${s | 0}s`; if (s < 5400) return `${(s / 60) | 0}m`; if (s < 172800) return `${(s / 3600) | 0}h`; return `${(s / 86400) | 0}d`; };
const when = ts => ts ? new Date(ts).toLocaleString() : '';
const pill = (s, extra = '') => `<span class="pill ${esc(s)}">${esc(s)}${extra}</span>`;
const nameOf = m => m.node_name || m.hostname || m.id;
const nameOf = m => m.node_name || m.id;
// ---------------------------------------------------------------- state
let token = '';