Skip to content

Add support for function keys (F1–F12)#757

Open
kirby88 wants to merge 1 commit into
charmbracelet:mainfrom
kirby88:add-function-keys
Open

Add support for function keys (F1–F12)#757
kirby88 wants to merge 1 commit into
charmbracelet:mainfrom
kirby88:add-function-keys

Conversation

@kirby88

@kirby88 kirby88 commented Jun 9, 2026

Copy link
Copy Markdown

Summary

Adds support for the function keys F1–F12 as tape commands, so tapes can drive TUIs and apps that bind function keys (e.g. switching tabs/panes).

They follow the exact pattern of existing keypress commands like PageUp, including the optional @<time> and repeat-count grammar:

F1
F3 2
F5@500ms 3

Changes

  • token: new F1F12 token constants, Keywords mappings, and IsCommand entries.
  • parser: F1F12 added to CommandTypes and the parseCommand keypress switch, routing through parseKeypress (so @time/repeat work).
  • command: CommandFuncs entries mapping each F-key to ExecuteKey(input.Fn) — go-rod already defines input.F1input.F12.
  • record: F-key terminal escape sequences added to EscapeSequences so vhs record captures them.
  • docs: man page list + README "Function Keys" section.
  • tests: dedicated lexer/parser F-key tests; updated command_test.go command-count assertions (31 → 43).

No lexer change was required — readIdentifier already accepts digits, so F3 lexes as a single identifier token.

Testing

  • go build ./..., go vet ./..., go test ./... all pass; gofmt clean.
  • vhs validate accepts a tape using F3, F12@200ms 2, and F1 3.

Notes

  • Modifier chords (Ctrl+F3, Shift+F12) are intentionally not included in this PR to keep it focused; happy to add as a follow-up.

Adds F1 through F12 as repeatable keypress commands, following the
existing pattern used by keys like PageUp:

- token: new F1–F12 token constants, keyword mappings, and IsCommand
- parser: F1–F12 added to CommandTypes and the keypress switch, so they
  accept the standard `Key[@<time>] [count]` grammar
- command: CommandFuncs entries mapping each F-key to ExecuteKey with the
  corresponding go-rod input.Fn key
- record: F-key terminal escape sequences so `vhs record` captures them
- docs: man page and README "Function Keys" section
- tests: lexer/parser F-key tests; updated command count assertions

Co-authored-by: vix <290354907+vix-agent@users.noreply.github.com>
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.

1 participant