Skip to content
Kite

Inline CLIs with Trail

Use extras/trail when finished work should stay in terminal scrollback while a smaller live region updates beneath it. Start an application with trail.Run(ctx, app, trail.WithInterceptLog(true)). The option redirects the standard Go logger above the live frame during the run and restores its writer on return; it does not intercept arbitrary writes to stdout.

Treat the items passed to <Static> as an append-only history. trail.Static remembers how many items it already emitted. New items are rendered and permanently inserted above the frame. Changing a previously emitted item cannot rewrite scrollback. Put current progress outside Static so it can change in place:

func progress(completed []string, current string) kitex.Node {
history := trail.Static(completed, func(name string, _ int) kitex.Node {
return kitex.Textf("Done: %s", name)
})
return kitex.Box(kitex.BoxProps{},
history,
kitex.Textf("Working on %s…", current),
)
}

A canvas has no terminal scrollback. This simulation keeps completed lines above a divider; Reset starts a fresh session.

var TrailProgress = kitex.FC("TrailProgress", func(kitex.NoProps) kitex.Node {
steps := []string{"lint", "build", "test"}
completed, setCompleted := kitex.UseState(0)
n := completed()
current := "All steps complete"
if n < len(steps) {
current = "Working on " + steps[n] + "…"
}
history := kitex.Map(steps[:n], func(name string, _ int) kitex.Node {
return kitex.Box(kitex.BoxProps{
Key: name,
Style: demo.Default.MutedText,
}, kitex.Text("Done: "+name))
})
complete := kitex.Button(kitex.ButtonProps{
Style: demo.Default.PrimaryButton,
Disabled: n == len(steps),
OnPress: func() { setCompleted(n + 1) },
}, kitex.Text("Complete step"))
reset := kitex.Button(kitex.ButtonProps{
Style: demo.Default.Button,
OnPress: func() { setCompleted(0) },
}, kitex.Text("Reset"))
return kitex.Box.Style(
demo.Default.Container,
history,
kitex.Box.Style(style.S().BorderTop(true), kitex.Text(current)),
kitex.Box.Style(demo.Default.ButtonRow, complete, reset),
)
})
  • UseApp() returns the running app handle: call Println for a permanent line or Exit(err) to end the command.
  • UseInput receives printable input and the underlying event.KeyEvent. Use the event for control keys, whose input string may be empty.
  • UseStdout() exposes Write and Size; UseStderr() exposes Write. Prefer these handles over printing through the live frame.
  • MeasureElement(ref) returns the mounted element’s size. Read it after layout, not while constructing the node. UseFocus(ref) tracks whether a referenced control has focus.