Application event loop and navigation
The application event loop keeps the terminal UI responsive while it combines user input with Kubernetes updates and background work. It sends keys, mouse actions, timer ticks, and asynchronous messages through one state model so that navigation, overlays, notifications, and workspace changes remain consistent. See the interactive terminal application page for the wider application model and terminal rendering and input for terminal setup and drawing.
Event loop
Event sources
The event loop waits on terminal events, application messages, redraw timers, and periodic maintenance at the same time. Key actions redraw at once for low input delay. Background updates mark the frame as dirty and are batched before rendering so a busy cluster does not cause one redraw per update. Input and message handling also clean up transient views and helper resources when navigation leaves them. This keeps a mode change from stranding a stream, plugin, or browser helper.
The main cycle follows this order:
- Read a terminal event or an application message.
- Apply it to the shared application state.
- Run any queued interactive command or notification delivery.
- Redraw immediately for direct input or on the next short frame tick for background changes.
- Run one-second maintenance such as expiring flashes and removing exited port forwards.
This diagram shows how direct input and asynchronous work meet in one state transition path.
flowchart TD
A[Terminal event] --> B[Input handling]
C[Background message] --> D[Message handling]
E[Timer tick] --> F[Maintenance]
B --> G[Application state]
D --> G
F --> G
G --> H[Queued command or notification]
G --> I[Dirty frame]
I --> J[Terminal render]
References: src/main.rs• L1047-1165 src/…/input.rs• L19-141 src/…/lifecycle.rs• L1125-1167
Generation boundaries
Each active resource view has a generation. Starting a new watch or changing context advances that generation and stops work tied to the old view. Background messages carry the generation that created them, so late results cannot replace data in a newer view. Auxiliary polls and streams use the same boundary.
A fully synced snapshot can seed a revisited view while its fresh watch catches up. This keeps navigation responsive without reusing partial data. The same boundary makes reconnects and context changes safe when network work completes in an unexpected order. Node capacity data follows the same rule and uses an incremental watch when allowed, with a paced list fallback when the cluster permits listing but not watching pods.
References: src/…/lifecycle.rs• L486-591 src/…/lifecycle.rs• L884-1051 src/…/lifecycle.rs• L1104-1123
Input actions
Keyboard routing
Keyboard input is first translated by the configured key map into an action and then routed by the current mode. The table handles movement, filtering, drilling, actions, and view changes. Document views handle scroll and search. Dialogs and pickers consume input locally until they accept or cancel it.
The command palette matches commands and resource kinds in its first word. It completes a namespace or context argument in the same position that the resource query parser will use. Saved bookmarks, workspaces, and named layouts are direct destinations. A custom resource name takes priority over a command with the same text when the cluster owns that name.
The mode is the active interaction contract. It prevents a key such as Enter, Esc, or a character from changing the underlying table while the user types in a prompt or chooses an item. Built-in actions take priority. Configured bookmarks, workspaces, and plugins receive keys that remain unhandled. When input changes mode, the application clears transient scroll state and stops resources owned by the old mode. Leaving a PVC browser or skin preview also releases its helper state, even when a palette, prompt, or background message caused the transition.
References: src/…/input.rs• L19-141 src/…/input.rs• L145-328 src/…/input.rs• L387-591 src/…/input.rs• L594-851 src/…/input.rs• L1073-1413 src/…/overlays.rs• L226-520
Mouse actions
Mouse input uses the same movement actions as the keyboard. The wheel becomes repeated up or down actions, so tables, documents, logs, and pickers share one scroll behavior. A table click selects a row. A header click selects a sort column, and clicking the active header reverses its direction.
Mouse capture follows the active view. Interactive views keep capture for clicks and wheel events. Document views release capture so the terminal can provide native text selection. Alternate-scroll sequences still reach the application as navigation keys.
References: src/…/mouse.rs• L44-71 src/…/mouse.rs• L68-117 src/…/mouse.rs• L120-159 src/main.rs• L1063-1117
Action workflows
Selected rows and marked rows can start guarded cluster actions, interactive terminal commands, clipboard work, or independent background work. The action flow keeps the target set fixed when a confirmation opens, then returns progress and the final result through the shared status path. Read-only mode and configured guardrails can stop an action before it changes the cluster.
The same flow covers common workload changes such as restart, image update, scale, and node operations. It also supports controller reconciliation, suspend or resume actions, scheduled-job triggers, certificate requests, pod and node debug sessions, document editing, file transfer, and clipboard or save actions. Confirmation text warns when a controller-managed object will be recreated or when approval grants cluster access. Foreground shell, attach, edit, and debug sessions suspend the UI, while background port forwards let browsing continue until the forward exits or the user stops it.
Actions are limited by the resource kind and its API group. This keeps similarly named custom resources from receiving an action intended for Flux or Argo CD. A document edit also re-reads the source object before opening the editor, so a stale document cannot silently target a replacement object.
References: src/…/actions.rs• L21-203 src/…/actions.rs• L265-373 src/…/actions.rs• L883-988 src/…/actions.rs• L1045-1321 src/…/actions.rs• L1373-1598 src/…/actions.rs• L1970-2170 src/…/helpers.rs• L37-345 src/…/overlays.rs• L95-223 src/…/flux.rs• L598-738
Plugin activity
Plugins extend the input model without taking control of the application state. A plugin can collect typed values, run for one or more targets, show live activity in a popup, return a report, or finish in the background. The application limits each run and ties its result to the current run and view, so cancellation or navigation cannot replace a newer plugin result.
References: src/…/plugins.rs• L29-113 src/…/plugins.rs• L115-226 src/…/plugins.rs• L464-731
Navigation model
Root views
A root view is a fresh resource and namespace choice. It clears the drill breadcrumb and transient row state, applies the chosen filter, records the view in browser-style history, and starts a new resource watch. The command palette can choose a resource, namespace, context, bookmark, workspace, or layout. A query or bookmark can also carry a filter, sort, or alternate view before the watch starts.
Namespace choices can use * and ? patterns. The application resolves the matching namespaces before it applies the destination. A namespaced resource then follows all matched namespaces. An unresolved pattern leaves no stale resource data in view.
Context-dependent bookmarks and workspaces are held until the requested connection is ready. This keeps the destination attached to the user action instead of applying it to whichever view was active when the connection began.
Root navigation is separate from drill navigation. This keeps Esc focused on returning from a drill while [ and ] move through recent root views.
References: src/…/lifecycle.rs• L20-175 src/…/lifecycle.rs• L237-328 src/…/input.rs• L691-851 src/…/bookmarks.rs• L33-106 src/…/workspaces.rs• L44-79 src/…/navigation.rs• L426-457 src/…/namespace_patterns.rs• L50-163
Drill-down views
Drill-down navigation pushes the current view onto a breadcrumb stack and opens a related view. The relationship may come from a built-in resource link, a selector on the selected object, a node or owner reference, or configured view rules. The new view keeps enough scope information to explain the path and to restore the prior kind, namespace, filters, selectors, and selection when the user goes back.
The common result is a focused list rather than a dead-end detail screen. For example, a workload can open its pods, a pod can open its containers, and a namespace can move into pods scoped to that namespace. RBAC objects can open their related subject or rule view. Helm and custom-resource views can also lead to their history, values, or discovered custom resources. When no list relationship exists, the application opens the resource detail view instead.
Selectors from the selected object define the target scope where possible. If the target kind is unavailable or the source has no required selector, the application keeps the current view and shows a warning instead of opening an unscoped list.
References: src/…/navigation.rs• L18-120 src/…/navigation.rs• L153-235 src/…/navigation.rs• L255-372 src/…/navigation.rs• L409-424 src/…/actions.rs• L398-471 src/…/lifecycle.rs• L397-441
View history
View history stores root resource, namespace, filter, and layout choices. Moving backward or forward restores that entry and starts its watch without adding a new history entry. A new root choice truncates the forward history, which gives the controls browser-like behavior.
References: src/…/lifecycle.rs• L277-395 src/…/layouts.rs• L50-86
View layouts
A view layout is a named column arrangement for a resource kind. The command palette can select it directly or as part of a resource query, and history restores it with the rest of the root view. Changing a layout rebuilds the visible column model while keeping the resource watch and the user's explicit sort choice aligned with the new columns.
References: src/…/layouts.rs• L12-86 src/…/layouts.rs• L88-151 src/…/rows.rs• L908-963
Row state
Row state turns the current resource store into the ordered set that navigation and selection use. Local filters, server-side selectors, sort choices, and live metrics all affect that set, so updates invalidate the visible order when the selected view can change.
The application rebuilds this derived set when membership, order, or the active column layout can change. When an update changes only row content and the current order remains valid, it refreshes that row without discarding the whole order. Time-based values and live metrics still cause refreshes as they change. This keeps the cursor, visible cells, and navigation order aligned during live updates.
Root changes reset the cursor and marked rows. Ordinary watch updates refresh only the affected row data when its position and membership stay valid, which keeps selection stable during live updates without showing stale cells.
References: src/…/rows.rs• L4-41 src/…/rows.rs• L546-717 src/…/rows.rs• L740-821 src/…/lifecycle.rs• L443-472
Pickers and overlays
Selection pickers
Pickers turn a multi-step choice into a focused local mode. Namespace and context pickers load their lists in the background and support fuzzy filtering. The namespace picker keeps the current choice visible, then places configured favorites and recent choices before the remaining namespaces. Recents are tracked per context and are bounded so a context change does not mix choices from another cluster. Namespace completion in the command palette uses the same fetched list, so a choice made in the picker and a choice made in the palette share one view of the cluster.
The context picker can also rename a kubeconfig context without replacing the live connection. After the rename, its cached choices and context-scoped namespace recents follow the new name.
Sort and copy pickers use the same local selection pattern for table columns and selected-row fields. Container and port-forward pickers pass the chosen item into logs, shell, debug, transfer, or a prompt. A namespace filter can also be accepted as a literal namespace when the cluster does not expose a complete list.
The picker owns its cursor and filter while it is open. Esc first clears an active filter where useful, then closes the picker. Enter applies the selected item and returns to the view that opened it.
References: src/…/pickers.rs• L11-57 src/…/pickers.rs• L59-187 src/…/pickers.rs• L211-497 src/…/pickers.rs• L516-620 src/…/pickers.rs• L641-875 src/…/overlays.rs• L5-93 src/…/overlays.rs• L529-591
Prompts and confirmations
Prompts collect values such as replica counts, image names, paths, ports, lookback periods, and context names. Confirmations protect actions that can change cluster state or cross a shell boundary. Both remember the view to return to, validate input before starting the action, and can hand off to background work or an interactive command.
The return target is not always the table. A prompt opened over logs, contexts, the PVC browser, a directory browser, a document, or a port picker returns to that parent mode. Chained prompts handle custom port forwards and file transfers. Cancellation releases any pending action or helper resource.
References: src/…/overlays.rs• L95-223 src/…/overlays.rs• L226-520 src/…/overlays.rs• L522-604 src/…/input.rs• L40-141
Document and log overlays
Detail, diff, events, help, and logs are temporary views over the current resource context. They support scrolling, search, copying, saving, and view-specific controls without losing the selected table row. Closing them stops only the stream or refresh owned by that view, then restores the prior mode.
The log view can follow pod, workload, service, marked-pod, or external-provider sources. It keeps its own stream lifecycle, so changing a log filter, container scope, or provider lookback restarts the log work without restarting the underlying resource watch. Structured log records can be shown as raw text, compact records, or pretty JSON.
The command palette can also open over these views. Its return mode records the source, so leaving through a command performs the same stream and document cleanup as pressing Esc. Editing a document checks the live object first, while copying and saving report their result through the shared status path.
References: src/…/actions.rs• L474-631 src/…/actions.rs• L883-988 src/…/logs.rs• L149-186 src/…/logs.rs• L709-891 src/…/logs.rs• L933-1050 src/…/input.rs• L657-717 src/…/input.rs• L803-862 src/…/input.rs• L1231-1433
Notifications and status
The status area gives immediate feedback for navigation, progress, success, and failure. Background actions claim the status area while they run and replace the progress text with a result. A one-second tick expires short-lived flashes, while longer-lived welcome or recurring messages remain until another interaction replaces them.
Generation and claim checks keep an old task from overwriting a newer task's message. Internal task panics and watch errors become visible in the application instead of silently breaking the interactive session.
References: src/…/lifecycle.rs• L1063-1093 src/…/lifecycle.rs• L1292-1338 src/store.rs• L400-416
Resource notifications
The notify feature watches one selected object independently of the current view. After the initial state is known, later changes are compared and grouped into a readable message. The event enters the shared message path, appears as a status flash, and may also ring the terminal or invoke a desktop notifier.
Notifications stop when the context changes or the session ends. Their epoch prevents messages queued by an old context from being delivered after the switch.
References: src/…/notify.rs• L3-19 src/…/notify.rs• L53-161 src/…/lifecycle.rs• L948-956 src/store.rs• L417-422 src/main.rs• L1127-1137
Workspace transitions
Workspace views
A workspace is a named cycle of saved views. Opening one applies its first view. Tab and Shift-Tab move through the workspace's views. Without an active workspace they cycle through common resources instead. Each workspace view reuses the same navigation path as a saved bookmark, then labels the status area with the workspace position.
References: src/…/workspaces.rs• L15-42 src/…/workspaces.rs• L44-149
Fleet dashboard
The fleet dashboard is an opt-in transition from one cluster view to a cross-context health summary. It gathers the selected contexts in bounded parallel work and gives each context its own timeout, so one slow connection does not block the others. Selecting a degraded Argo CD count returns through the normal context-and-query path with the matching filter already applied.
References: src/…/fleet.rs• L5-16 src/…/fleet.rs• L18-213
Context transitions
A context transition replaces the cluster connection and repeats discovery for the target context. Before the switch, the application stops old watches, clears data that belongs to the old cluster, and preserves one deferred destination such as a resource query, bookmark, or workspace. When the new connection arrives, it applies that destination first. Otherwise it restores a matching resource or falls back to the configured default.
The transition also reloads context-specific behavior such as aliases, views, plugins, guardrails, notifications, and the active skin. Running port forwards are left alive because each process is already tied to the context used when it started. New autostart forwards are then added for the destination context.
This diagram shows why a context switch is a lifecycle boundary rather than a simple namespace change.
sequenceDiagram
participant U as User
participant A as Application
participant C as Target context
participant W as Background watches
U->>A: Choose context, query, bookmark, or workspace
A->>W: Stop old work and invalidate old generation
A->>C: Connect and discover APIs
C-->>A: New cluster connection
A->>A: Apply deferred destination or default view
A->>W: Start watches for the new view
A-->>U: Show new data and status
References: src/…/pickers.rs• L877-943 src/…/pickers.rs• L945-1122 src/…/bookmarks.rs• L33-103 src/…/workspaces.rs• L44-79 src/…/navigation.rs• L378-399 src/…/lifecycle.rs• L1104-1123
Change checklist
When these files or sections are changed, remember to consider these:
- Keep every new input mode aligned across key dispatch, key scope, mouse-capture policy, overlay return handling, and cleanup after a mode change.
- Keep command-palette completion aligned with resource-query parsing so
-n,--namespace, context options, layout options, and typed arguments resolve to the same destination. - Keep every asynchronous message tied to the correct view generation or request identity. Add an explicit stale-result cleanup path when the operation can create a cluster-side resource.
- When adding a root navigation target, update the command-palette destination rules, bookmark/workspace application path, and view-history behavior together.
- When adding a drill relationship, preserve the breadcrumb frame and restore the prior scope, filter, sort, and selection on return.
- When changing filtering, sorting, metrics, or column layouts, keep row invalidation and cursor behavior aligned so the visible order does not lag behind the data.
- When changing namespace selection, keep pattern discovery, matched-namespace watches, deferred root actions, and unresolved-pattern cleanup aligned.
- When changing context switching, review deferred query, bookmark, workspace, and fleet destinations as well as context-scoped configuration and running port forwards.
- When changing notifications or status claims, keep delivery, expiry, generation checks, and terminal or desktop output in agreement.
- When changing plugin output, log streams, suspended commands, or helper browsers, keep cancellation, return modes, cleanup, and status ownership aligned.
- When changing kind-specific actions, keep the resource-kind and API-group checks aligned with the action menu, guardrails, confirmation text, and result messages.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A background result arrives after the user changes view or context | Old data can replace the current view or show an unrelated result | Generation and request checks drop stale messages |
| A context switch leaves old watches or cached resources active | The new context can show old cluster data or receive old updates | Context changes bump the generation, stop work, and clear context-owned caches |
| A namespace pattern has no match or discovery fails | The application can show stale data or fail to reach the requested root view | Pattern resolution reports the problem and clears unresolved pattern state |
| A picker or prompt returns to the table instead of its source overlay | The user loses the active log, context, PVC, or port-forward workflow | Overlay return modes are captured and cleaned after each transition |
| Mouse capture stays enabled in a document view | Terminal text selection does not work and wheel input can use the wrong path | Capture follows wants_mouse_capture; document views release it |
| A notify watch survives a context change | A message from the old cluster appears in the new session | Notification tasks are aborted and the notification epoch advances |
| A workspace, fleet drill-in, or query is requested during an unfinished context switch | The wrong destination opens when the connection completes | One deferred destination owns the switch and competing pending destinations are cleared |
| A running port forward is treated as a foreground command | Browsing pauses or the tunnel stops when the user leaves the action | Port forwards run independently and are reaped when their child exits |
| A filter, sort, metric, or column change skips row invalidation | The cursor or visible list can use an old order or old cell values | Row state invalidation covers view changes and the data sources that affect membership or order |
| A namespace fetch from an older request replaces a newer list | Picker choices and palette completion show stale namespaces | The request and generation identify the accepted namespace list |
| A namespace listing is restricted and the typed name is rejected as unknown | The user cannot switch to a namespace that the list API could not reveal | The picker accepts unmatched typed text as a verbatim namespace |
| A node pod watch is forbidden but the application keeps retrying it | The API receives repeated failed watch requests and node totals stop updating | Forbidden watch errors switch to a slower list fallback; transient errors use paced backoff |
| A plugin, log stream, suspended command, or helper browser outlives its source mode | Old output can overwrite a new document or keep a hidden task alive | Stream, plugin, suspend, and helper identities are cancelled or cleaned on exit |
| A document is edited from a stale object snapshot | The shell can modify a resource that no longer matches the open document | The application re-reads the document source before it starts the edit |
| A kind-specific action is offered for a resource from another API group | The action can patch the wrong resource contract or appear to work without the intended effect | Action availability checks both the resource kind and its API group |
| A controller-managed object is deleted without showing its owner | The object returns and the user may think deletion failed | Confirmation text identifies the manager and warns that reconciliation can recreate it |
Key files
| File | Why to read it |
|---|---|
| src/main.rs | See the central event loop, redraw policy, terminal capture changes, background message batching, notification delivery, and suspend/resume path. |
| src/…/mod.rs | See the application modes, deferred destinations, overlays, workspaces, log sources, and status ownership that define the interaction model. |
| src/…/actions.rs | See how user actions become guarded background work, interactive commands, clipboard work, document operations, and independent port forwards. |
| src/…/helpers.rs | See the shared action contracts for controller-specific patches, managed-resource warnings, clipboard output, and related-resource scope. |
| src/…/input.rs | See how key actions map to modes, overlays, document views, filters, table navigation, and transition cleanup. |
| src/…/mouse.rs | See wheel translation, table hit testing, sorting by header click, and mouse-capture rules. |
| src/…/lifecycle.rs | See watch generations, background message application, view snapshots, stale-result handling, and watch recovery. |
| src/…/bookmarks.rs | See saved destinations, deferred context changes, and bookmark filter, sort, and view application. |
| src/…/navigation.rs | See root navigation, breadcrumb drilling, related-resource jumps, namespace transitions, and restoration of prior views. |
| src/…/namespace_patterns.rs | See wildcard namespace resolution and the way matched namespaces feed resource watches and deferred navigation. |
| src/…/layouts.rs | See named layout selection and the link between palette navigation, history, and visible columns. |
| src/…/pickers.rs | See namespace and context switching, fuzzy selection, recent namespaces, sort/copy pickers, and deferred context transitions. |
| src/…/rows.rs | See how the live store becomes the filtered and sorted row set used by selection and rendering. |
| src/…/logs.rs | See log source transitions, independent stream refresh, search, structured record views, and follow behavior. |
| src/…/plugins.rs | See plugin forms, activity views, output modes, cancellation, and result delivery. |
| src/…/fleet.rs | See the bounded cross-context dashboard and its return path into normal context navigation. |
| src/…/workspaces.rs | See named workspace opening and view cycling. |
| src/…/overlays.rs | See confirmation, prompt, container, port-forward, and suspended-action transitions. |
| src/…/notify.rs | See independent object watches and terminal or desktop notification delivery. |
| src/store.rs | See the message contracts that connect background tasks to the application state. |