Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alt + Backspace to delete complete words #1

Closed
cmprmsd opened this issue Apr 23, 2022 · 3 comments
Closed

Alt + Backspace to delete complete words #1

cmprmsd opened this issue Apr 23, 2022 · 3 comments

Comments

@cmprmsd
Copy link

cmprmsd commented Apr 23, 2022

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!

@brianstrauch
Copy link
Owner

brianstrauch commented Apr 24, 2022

@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)

@cmprmsd
Copy link
Author

cmprmsd commented Apr 27, 2022

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!

@cmprmsd cmprmsd closed this as completed Apr 27, 2022
@cmprmsd
Copy link
Author

cmprmsd commented May 2, 2022

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))
}

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

No branches or pull requests

2 participants