Repository navigation
Description
Summary
Two gaps in the pod shell (s), both about "I need to see / do more than the pane gives me":
- The in-panel shell cannot scroll. Output that leaves the screen is gone, the wheel over the pane silently moves the hidden table's selection, and full-screen programs in the pod (
less,vim,htop) never see wheel events. - There is no way to get the real terminal. When the emulator is not enough (long output, native select/copy, true colours, a long session), you have to quit k10s and type
kubectl exec -it … -- shby hand.Sshould do that: quit k10s and exec into the selected pod in the terminal k10s was started from.
Everything below was checked against main (v0.1.7, bubbletea v1.3.10, vt10x 2022-03-01).
Part 1 — scrolling in the in-panel shell
Current behaviour
- Wheel over the shell pane corrupts the table selection.
handleMouse→scrollPaneAt→scrollMain(model.go:1748).scrollMainhandlesmodeLogsandmodeText, then falls through to the table branch and mutatesm.rowIdx/m.rowMem[kind]even though the pane is showing a shell. Detach after scrolling and the row you had selected has moved. - No scrollback. vt10x keeps only the visible screen:
scrollUpclears the evicted rows and swaps the rest (vt10x state.go:477); there is no history buffer (the repo has aTODO: selection scrolland no commits since 2022-03).cat /etc/nginx/nginx.confin a 20-row pane shows the last 20 lines, full stop. pgup/pgdndo nothing useful.keyBytesforwards them to the pod as\x1b[5~/\x1b[6~; a plainsh/bashprompt ignores them.- Mouse-aware programs never get the wheel. vt10x parses DECSET 9/1000/1002/1003/1006 and exposes the state via
Terminal.Mode()(ModeMouseButton,ModeMouseMotion,ModeMouseSgr, …), but k10s never forwards a mouse report, soless --mouse,vim :set mouse=a,htopbehave as if the terminal had no mouse.
Proposal
- Stop the fall-through. In
scrollMain(orscrollPaneAt),modeShellgets its own branch; the table is never touched while a shell is in the pane. - Add a scrollback buffer to the emulator. vt10x upstream has none and is unmaintained, so fork it into
internal/vt(it is ~1.5k LOC, MIT) and add history the way st's scrollback patch does: inscrollUp, whenorig == 0, the scroll region is the whole screen andModeAltScreenis off, push the evicted[]Glyphrows onto a ring of 2000 lines (const for now; a config knob can come later). ExposeHistoryLen()andHistoryCell(i, x). Alt-screen output (vim/less) is never recorded, same as every real terminal.
Alternative to evaluate before forking: swap to an emulator that already has scrollback (e.g.charmbracelet/x/vt). Only worth it if the render loop inshellBody(Cell,Cursor,CursorVisible,Size,Resize,Mode) maps over cheaply; otherwise fork. - A view offset in the model.
shellScroll int, 0 = live.- Wheel over the pane: ±2 lines (same step as the other panes).
- Keys while in the shell:
shift+up/shift+downone line,shift+home/shift+endtop / live. (shift+pgup/shift+pgdnare not decodable in bubbletea v1 and most terminals eat them for their own scrollback anyway.) These are the only keys the shell does not forward, besidesctrl+]. - Any key forwarded to the pod snaps back to live (xterm/kitty convention). New output while scrolled keeps the position.
shellBodyrendershistory tail + screenshifted by the offset; the cursor is drawn only when live.shellStatusLineshows↑ 120 lines back · any key returnswhile scrolled, so a stale screen is never mistaken for a hung pod.
- Forward the wheel when the pod program wants it. When
ModeAltScreenis on there is nothing to scroll locally, so instead:Mode()&ModeMouseMask != 0→ write a mouse report to the session with pane-relative coordinates: SGR\x1b[<64;x;yM/\x1b[<65;x;yMwhenModeMouseSgr, X10\x1b[M+ bytes otherwise.- no mouse mode → write 3×
\x1b[A/\x1b[B(xterm "alternate scroll" behaviour;\x1bOA/\x1bOBwhenModeAppCursor). This makes the wheel work inless,man,kubectl logs | lessinside the pod with zero config. - Not on alt screen and mouse mode on (rare, e.g. a TUI that does not switch screens): forward the report; otherwise scroll locally.
- Resize: history lines keep the width they were written at; no reflow (out of scope).
Acceptance
- Wheel over the shell pane never changes
rowIdx/rowMem(regression test next toTestShellSizedToThePanel). - Write
rows+50lines into the fake session, wheel up → the first line is visible; one forwarded keystroke → back to live and the status line is the normal one. - History is capped (write 3000 lines →
HistoryLen() == 2000) and alt-screen output is not recorded. - Alt screen +
?1000h/?1006h→ one wheel tick yields the SGR sequence on the session's stdin; alt screen without mouse mode → three\x1b[A. -
ctrl+],[ detach ]and a session that ends on its own still work from a scrolled position. - Docs:
docs/ui.md"Shell" section,docs/keybindings.md, the in-app help ininternal/ui/commands.go, and thes shellrow inREADME.md.
Part 2 — S: quit k10s and open the shell in the parent terminal
Why
The in-panel shell is a small emulator with a theme-mapped 16-colour palette, no native selection (the mouse is captured; ctrl+s copy-mode only half helps), and whatever scrollback Part 1 gives it. Sometimes you want the real thing: the pod shell in the terminal you launched k10s from, with that terminal's scrollback, selection, fonts and colours, and k10s out of the way. Today that is "quit, remember the pod name, type kubectl exec -it … -n … -- sh". S should be that, with k10s resolving pod and container exactly as s does (workload → pod, bash if present else sh).
What already exists
domain.Source.Shell(kind, ns, name) (tea.ExecCommand, error)is still in the interface and implemented in k8s, mock andpendingSource. The k8s one (execCommandin internal/k8s/exec.go) does a raw-TTY in-processremotecommandstream withkterm.TTY{Raw: true}andMonitorSize— akubectl exec -itequivalent with no kubectl binary. Nothing in the UI calls it since the in-panel shell replaced the oldstartShell(4c30892).- Precedent for "do a thing in the clean terminal after the TUI exits":
/updatesetsm.relaunch, returnstea.Quit, andmain.gorunsupdate.Relaunchafterp.Run()returns — alt screen torn down, mouse tracking off, nothing of k10s left on screen.
Proposal
-
New action
domain.AShellOut(id"shellout", name open to bikeshedding): keyS, label "Shell (terminal)", listed inActionsdirectly unders Shell. Offered whereverAShellis (Kind.Can), not allowed in read-only (ReadOnlyAllows+ its test list), notRisky.Sis free: nothing inhandleKeyor the action table uses it (DandTare the only shifted letters in use). -
Flow:
fireAction→cmd, err := m.src.Shell(kind, ns, name).cmd == nilor error (demo, pending connection, not pod-backed) → toastno interactive shell here (offline demo, or not a pod), stay in k10s.- otherwise
m.exitShell = cmd,m.backToTable(), returntea.Quit.
-
main.go, after
p.Run()and before the relaunch branch:if c := m.ExitShell(); c != nil { c.SetStdin(os.Stdin); c.SetStdout(os.Stdout); c.SetStderr(os.Stderr) fmt.Fprintf(os.Stderr, "k10s: shell into %s (%s) — exit the shell to get your prompt back\n", name, ns) if err := c.Run(); err != nil { /* print, exit 1 */ } return }
The process ends when the pod shell ends. The exit code should follow the remote shell's (
remotecommandsurfaces it asexec.CodeExitError). -
Keep the store alive until then. The source lease only closes on context replace, and nothing on the
tea.Quitpath callsClose(); add a test so that stays true, becauseexecCommand.Runbuilds its request lazily fromstore.c. -
Align
Shell()withShellSession().Store.Shellstill rejectskind != "pods"and usespodContainer; switch it tologTargetsoSworks on Deployments/StatefulSets/Jobs the waysandldo. -
Not
tea.ExecProcess. That hands the terminal over and comes back into k10s afterwards; the point ofSis to leave. (Coming back can be a follow-up — it is one line with the sameexecCommand— but it is a different feature.) -
Inside the in-panel shell
Sis just a key and goes to the pod. Reaching the external shell from there is detach →S. A/shellslash command is optional sugar, not required. -
Cross-platform: nothing here needs
syscall.Exec;ktermraw mode is what kubectl uses on Windows too.
Acceptance
- Table, pod selected,
S→ k10s exits the alt screen and the pod shell is running in the parent terminal; exiting it returns to the user's prompt with the shell's exit code. -
Son a Deployment resolves to one of its pods (same podl/swould pick). -
Son a kind without a shell (Secret) is not offered; on the demo context it toasts and does not quit; in--readonlyit is not offered. - Unit test:
fireAction(AShellOut)with a source whoseShell()returns a command →ExitShell() != niland the returned cmd istea.Quit; withnil, nil→ toast, no quit. - Actions pane shows
S Shell (terminal); help text (commands.go),docs/keybindings.md,docs/ui.mdShell section and the README action table mention it, and say plainly that it quits k10s.
Out of scope
- Reflowing scrollback on resize, searching the scrollback, select/copy inside the pane.
- Returning to k10s after the external shell exits (would be
tea.ExecProcess; separate issue if wanted). - Making
Sreachable from inside the running in-panel shell.
Pointers
internal/ui/shell.go—handleShellKey,keyBytes,shellBody,shellStatusLineinternal/ui/model.go—handleMouse(~2668),scrollPaneAt/scrollMain(~1727),handleKeyshell guard (~1288), action dispatch (~1623),shellStartMsg/shellOutMsg(~1047)internal/ui/actions.go— action table;internal/domain/domain.go,internal/domain/readonly.gointernal/k8s/exec.go—execCommand(tea.ExecCommand),Store.Shell;internal/k8s/shell.go—ShellSession,logTargetinternal/ui/update.goRelaunch()+main.goafterp.Run()— the quit-then-act pattern to copyinternal/ui/shell_test.go— fake session harness for the new tests
Suggest two PRs (Part 1, Part 2); they do not touch the same lines.
Activity
feat(ui): S quits k10s into the pod shell in the real terminal
fix(ui): keep the wheel over the shell from moving the table