Skip to content

cmdio: decode keys through teainput - #7740

Draft
pietern wants to merge 1 commit into
pietern/charm-v2/03a-render-splitfrom
pietern/charm-v2/03b-teainput
Draft

pietern wants to merge 1 commit into
pietern/charm-v2/03a-render-splitfrom
pietern/charm-v2/03b-teainput

Conversation

@pietern

@pietern pietern commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Prompt, select and the pager switch on keystroke names from a new libs/cmdio/teainput package instead of v1 key types:

  • teainput.Decode turns a bubbletea message into an Event with Key (keystroke name), Text (printable text) and Paste. Key names follow bubbletea v2 (enter, ctrl+c, space, alt+backspace).
  • Several runes in one read are text and get no key name. A single rune is a key press.
  • Alt is kept in the name only where v1 checked it: Alt+rune, Alt+space, Alt+backspace and Alt+tab. Other Alt combinations act as the plain key, as in v1. Alt+Space still advances the pager, as in v1.
  • A paste is handled as v1 handled it: the prompt inserts it, select treats it as typed text, the pager ignores it.

Why

This is v1 behaviour on the new decoder, so the v2 move only changes the decoder. Fixed on the way: a burst of text that spells a key name (enter, down) used to act as that key. v1 typed it as text; the decoder had given it the key's name, so a fast enter submitted a prompt. Now a burst is text.

Tests

  • go build ./..., golangci-lint (0 issues), gofmt clean.
  • TERM=xterm-256color go test -race -count=3 ./libs/cmdio/... passes.
  • New teainput tests cover the decoder, including bursts (enter, down, ctrl+c) and paste.
  • The existing burst pins (TestKeysPin_PromptBurstKeyName, TestKeysPin_SelectFilterBurstKeyName) pass with the same text as v1.
  • The pins pass without -update. No golden changes.

Stack: based on pietern/charm-v2/03a-render-split.

Manual checks for real terminals:

  • databricks selftest tui prompt, then type enter quickly (or paste it) and press Enter: Entered: enter (v1 and this branch).

This pull request and its description were written by Isaac.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: bc4d7d7

Run: 44344043267

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 272 19 19:12
💚​ aws-windows-latest-4core-16gb 1 274 17 11:09
💚​ azure linux-2core-8gb 1 271 19 17:49
💚​ azure-windows-latest-4core-16gb 1 273 17 11:33
💚​ gcp linux-2core-8gb 1 272 19 16:18
💚​ gcp-windows-latest-4core-16gb 1 274 17 9:54
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 40 slowest tests (at least 2 minutes):
duration env testname
6:49 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsReadDir
5:48 aws linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
5:15 azure linux-2core-8gb TestFilerRecursiveDelete/workspace_files_extensions
4:48 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsDelete
4:13 aws linux-2core-8gb TestLock
4:03 azure-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsDelete
3:52 azure-windows-latest-4core-16gb TestImportDirDoesNotOverwrite
3:46 aws linux-2core-8gb TestImportDirDoesNotOverwrite
3:41 gcp-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsStat
3:28 gcp linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
3:09 gcp linux-2core-8gb TestExportDir
3:03 azure-windows-latest-4core-16gb TestAccept
3:02 azure-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsReadDir
3:01 gcp linux-2core-8gb TestFilerWorkspaceFilesExtensionsDelete
3:00 aws-windows-latest-4core-16gb TestAccept
2:59 azure-windows-latest-4core-16gb TestExportDir
2:59 gcp-windows-latest-4core-16gb TestExportDir
2:57 aws linux-2core-8gb TestFilerWorkspaceFilesExtensionsRead
2:56 aws linux-2core-8gb TestImportDir
2:54 aws linux-2core-8gb TestFilerRecursiveDelete/workspace_files_extensions
2:50 gcp-windows-latest-4core-16gb TestAccept
2:46 aws-windows-latest-4core-16gb TestImportDirDoesNotOverwrite
2:38 azure linux-2core-8gb TestImportDirDoesNotOverwrite
2:35 gcp-windows-latest-4core-16gb TestImportDirDoesNotOverwrite
2:34 azure linux-2core-8gb TestImportDirWithOverwriteFlag
2:33 aws-windows-latest-4core-16gb TestFilerRecursiveDelete/workspace_files_extensions
2:31 azure-windows-latest-4core-16gb TestFilerRecursiveDelete/workspace_files_extensions
2:31 gcp linux-2core-8gb TestSyncIncrementalFileSync
2:26 azure linux-2core-8gb TestFilerReadWrite/workspace_files_extensions
2:26 azure-windows-latest-4core-16gb TestSyncFullFileSync
2:25 azure-windows-latest-4core-16gb TestLock
2:23 aws linux-2core-8gb TestSyncFullFileSync
2:22 azure-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsStat
2:19 gcp linux-2core-8gb TestFilerWorkspaceFilesExtensionsStat
2:19 aws linux-2core-8gb TestFilerWorkspaceNotebook/rJupyterNb.ipynb
2:15 aws-windows-latest-4core-16gb TestImportDirWithOverwriteFlag
2:12 gcp linux-2core-8gb TestFilerReadDir/workspace_files_extensions
2:10 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsStat
2:10 gcp linux-2core-8gb TestFilerReadWrite/workspace_files_extensions
2:04 azure linux-2core-8gb TestSyncFullFileSync

@pietern
pietern added this pull request to stack #7754 November 18, 2026 08:35
@pietern

pietern commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/review

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me — no issues found.

@pietern
pietern force-pushed the pietern/charm-v2/03b-teainput branch from 786e293 to abd2eff Compare November 18, 2026 13:07
@pietern
pietern force-pushed the pietern/charm-v2/03b-teainput branch from abd2eff to 6faf163 Compare November 18, 2026 15:55
@pietern
pietern force-pushed the pietern/charm-v2/03b-teainput branch from 6faf163 to bc4d7d7 Compare November 18, 2026 16:07
@pietern

pietern commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

/review

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at bc4d7d7. Each finding was verified against the code.

Not ready yet: part of the automated review did not complete.

This PR replaces direct v1 key-type switches in the prompt, select and pager models with a new teainput.Decode decoder that returns keystroke names, preparing for a Bubble Tea v2 migration. The change is well-structured and well-tested. One edge case in the decoder's Alt+rune branch doesn't normalize a space rune to "space", which could silently break the pager's "alt+space" match on terminals that deliver Alt+Space as KeyRunes.

case tea.KeyRunes:
if k.Alt {
if len(k.Runes) == 1 {
return Event{Key: "alt+" + string(k.Runes)}, true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] When Alt+Space arrives as tea.KeyRunes with Runes: []rune(" ") and Alt: true, this returns Event{Key: "alt+ "} (literal space character). The non-Alt branch normalizes space via printable() (line 59), and the KeySpace branch returns "alt+space" explicitly (line 64), but this Alt+rune branch doesn't. The pager matches "alt+space" to advance (pager.go:201), so if a terminal delivers Alt+Space through this path the keypress silently does nothing. Normalizing the space rune here would close the gap:

if len(k.Runes) == 1 {
    name := printable(string(k.Runes)).Key
    return Event{Key: "alt+" + name}, true
}

An "alt space as rune" test case alongside the existing "space as rune" (teainput_test.go:20) would pin it.

Comment thread libs/cmdio/teainput/teainput_test.go Outdated
@@ -0,0 +1,75 @@
package teainput

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The testing rules ask for package teainput_test (external-test package). This file only accesses exported identifiers (Decode, Press, Type, Paste, Event), so it can use the _test suffix. Separately, the same rules expect a press_test.go alongside press.go; moving TestPressRoundTrips there would satisfy both.

Models switch on keystroke names from teainput.Decode instead of v1
key types. Behaviour is v1's, with one fix: several runes arriving in
one read are text and carry no key name, so typing "enter" fast no
longer submits a prompt. A single rune is still a key press.

Alt is kept in the name only where v1 checked it: Alt+rune, Alt+space,
Alt+backspace and Alt+tab stay inert, and Alt+space still advances the
pager. Other Alt combinations act as the plain key, as in v1. A paste is
handled as v1 handled it: prompt inserts it, select treats it as typed
text, and the pager ignores it.

The existing burst pins (prompt "enter", select "down") and the new
teainput tests pin the text. No golden moves.

Co-authored-by: Isaac <no-reply@databricks.com>
@pietern
pietern force-pushed the pietern/charm-v2/03b-teainput branch from bc4d7d7 to 7b5134c Compare November 20, 2026 13:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants