diff --git a/0.22.0-release-notes.md b/0.22.0-release-notes.md index af998638e..b7c99bb2a 100644 --- a/0.22.0-release-notes.md +++ b/0.22.0-release-notes.md @@ -1,5 +1,8 @@ # Notable new features +- Pressing `Ctrl-Alt-V` in the REPL now enters a mode where the name of the + next key pressed will be inserted into the buffer. + # Notable bugfixes - The `lower` glob modifier (as in `echo *[lower]`) now correctly matches diff --git a/pkg/edit/builtins.go b/pkg/edit/builtins.go index 4ebf33638..c1eac4f76 100644 --- a/pkg/edit/builtins.go +++ b/pkg/edit/builtins.go @@ -66,6 +66,29 @@ func insertRaw(app cli.App, tty cli.TTY) { app.PushAddon(w) } +func insertKeyName(app cli.App) { + codeArea, ok := focusedCodeArea(app) + if !ok { + return + } + w := modes.NewStub(modes.StubSpec{ + Bindings: tk.FuncBindings(func(w tk.Widget, event term.Event) bool { + switch event := event.(type) { + case term.KeyEvent: + codeArea.MutateState(func(s *tk.CodeAreaState) { + s.Buffer.InsertAtDot(ui.Key(event).String()) + }) + app.PopAddon() + return true + default: + return false + } + }), + Name: " KEY NAME ", + }) + app.PushAddon(w) +} + var errMustBeKeyOrString = errors.New("must be key or string") func toKey(v any) (ui.Key, error) { @@ -143,8 +166,9 @@ func wordify(fm *eval.Frame, code string) error { func initTTYBuiltins(app cli.App, tty cli.TTY, nb eval.NsBuilder) { nb.AddGoFns(map[string]any{ - "insert-raw": func() { insertRaw(app, tty) }, - "clear": func() { clear(app, tty) }, + "insert-raw": func() { insertRaw(app, tty) }, + "-insert-key-name": func() { insertKeyName(app) }, + "clear": func() { clear(app, tty) }, }) } diff --git a/pkg/edit/init.elv b/pkg/edit/init.elv index 25fab19f9..ab6479e02 100644 --- a/pkg/edit/init.elv +++ b/pkg/edit/init.elv @@ -42,6 +42,7 @@ set insert:binding = (binding-table [ &Ctrl-K= $kill-line-right~ &Ctrl-V= $insert-raw~ + &Ctrl-Alt-V= $-insert-key-name~ &Alt-,= $lastcmd:start~ &Alt-.= $insert-last-word~