Alt + Backspace to delete complete words
cmprmsd opened this issue · 3 comments
Hey Brian,
Can't believe I'm the first person creating an issue here. This project is such a great idea! I missed this automation in other projects like ishell or promptui.
Bug / Feature Request
I just noticed that alt + backspace
behaves strangely. It will insert question marks instead of deleting complete words as I would expect it in an interactive shell.
As it messes with the cli-ui it might be a bug to address but also a nice feature implementation that I'd love to see!
Edit: Also ctrl+right
and ctrl+left
would be a great idea in order to skip through longer commands as I just noticed :D
Thanks in advance!
@cmprmsd Thanks for testing it out and submitting all these great issues!
It looks like go-prompt uses Emacs keybindings by default. So ctrl+w
should accomplish the same thing as alt+backspace
. It looks like a few shortcuts are missing from the go-prompt library, so it looks like we'll need to wait for c-bata/go-prompt#249 before we can implement alt+backspace
and others.
ctrl+left
and ctrl+right
might be doable to implement, though. It looks like you're using Windows (and I'm on Mac), so could you give this a try and let me know if it works for you?
opt := prompt.OptionAddKeyBind(
prompt.KeyBind{Key: prompt.ControlLeft, Fn: prompt.GoLeftWord},
prompt.KeyBind{Key: prompt.ControlRight, Fn: prompt.GoRightWord},
)
cmd.AddCommand(shell.New(cmd), opt)
Cool, this works! Just had to move opt into shell.New like this:
cmd.AddCommand(shell.New(cmd, opt))
Sadly there is no prompt.AltBackspace. 👎
I think the correct PR was c-bata/go-prompt#112
but there was also some talk about Mac keyboard issues.
Strange. I'll ask what happend and why it got closed 🤷♂️
However this is an issue up to go-prompt so you got a great solution to my problem 👍 1000 thanks!
Just a quick heads up. It's possible to create ASCIICodeBinds. So I modified your suggestion to include also Alt+Backspace:
func init() {
keyBinds := prompt.OptionAddKeyBind(
prompt.KeyBind{Key: prompt.ControlLeft, Fn: prompt.GoLeftWord},
prompt.KeyBind{Key: prompt.ControlRight, Fn: prompt.GoRightWord},
)
codeBinds := prompt.OptionAddASCIICodeBind(
prompt.ASCIICodeBind{ASCIICode: []byte{0x1b, 0x7f}, Fn: prompt.DeleteWord}, // Alt + Backspace
)
rootCmd.AddCommand(shell.New(rootCmd, keyBinds, codeBinds))
}