David-Kunz / gen.nvim

Neovim plugin to generate text using LLMs with customizable prompts
The Unlicense
1.15k stars 92 forks source link

Handle user cancellation (<Esc>/<C-c>) when asking for prompt #105

Closed hanschen closed 2 months ago

hanschen commented 2 months ago

Currently it's not possible to cancel the operation when "Prompt: " is shown - <Esc> seems to act as <Cr>, and <C-c> throws an error message.

It would be nice if <Esc> and <C-c> were respected.

(Sorry for opening so many issues recently, I'm just fascinated by this plugin. :smile:)

David-Kunz commented 2 months ago

Hi @hanschen ,

First of all, your issues are much appreciated and thank you for your nice comments 😄 .

I use the standard vim.ui.select function, you can press q to quit the prompt selection. Does that help?

Tip: If you're using Telescope, you can install nvim-telescope/telescope-ui-select.nvim to delegate such user input to Telescope.

Best regards, David

hanschen commented 2 months ago

Thanks for the answer! I'm afraid I can still trigger this issue. Here's some more detailed information on how to reproduce it:

To reproduce:

  1. Run :Gen and choose e.g. the default Chat option.
  2. After hitting Enter, you'll see it asking for Prompt:. Now press <Esc> or <C-c>.

Expected results:

The cursor is returned to the original buffer and no generation window is shown.

Actual results:

If you hit <Esc>, you'll get a generation window with an empty $input.

If you hit <C-c>, you'll get an Error executing Lua callback: Keyboard interrupt error.

More information:

Related? https://github.com/neovim/neovim/issues/18144

Hope that clarifies the issue.