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

Pause/disable user input when displaying stats for countdown game #11

Closed
gerazov opened this issue Dec 25, 2023 · 7 comments
Closed

Pause/disable user input when displaying stats for countdown game #11

gerazov opened this issue Dec 25, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@gerazov
Copy link
Contributor

gerazov commented Dec 25, 2023

It would be nice if the user input is paused for a bit, or even better completely disabled, after the game finishes and the stats are displayed.

Otherwise depending on what word your typing you can edit over the displayed text.

I tried the following:

  1. Pause Neovim using vim.wait(500). This doesn't really work, if it does pause Vim the keypresses are still accumulated sent after the wait.

  2. Turn off modifiable via api.nvim_buf_set_option(0, "modifiable", false), this I think is a good choice but can lead to a bunch of E21: Cannot make changes, 'modifiable' is off. I couldn't find if this can be suppressed at a buffer level..

  3. Prompt user for input, e.g. "Press Enter to continue ..." but vim.fn.input() would open a new prompt. Maybe a custom function could be implemented 🤔

I'm pushing the 2. PR - seems the cleanest.

Ignore if it doesn't make sense 😅 :

@NStefan002
Copy link
Owner

Thanks again for the help 😁. The solution you proposed in PR makes sense, but I would like to suppress the error, I'll look into it and try to come up with a different solution. If I don't make any progress, I will merge the PR (it's much better than the current state 😀).

@gerazov
Copy link
Contributor Author

gerazov commented Dec 26, 2023

Yeah - it would be better for sure 👍

I did go over the API, forums, LLMs, for all 3 of these, and couldn't find an elegant way to resolve this 😅

Maybe you have better luck 😉

@NStefan002
Copy link
Owner

I did go over the API, forums, LLMs, for all 3 of these, and couldn't find an elegant way to resolve this 😅

I was just about to type this.

The only other way I thought of was to do something like this:

local keys_to_disable =
    { "a", "A", "i", "I", "o", "O", "s", "S", "x", "d", "D", "c", "C", "p", "P", "u", "U", "J", "r", "R", ".", }
for _, key in pairs(keys_to_disable) do
    vim.keymap.set("n", key, "<nop>", { buffer = 0 })
end

But it's very hacky, there are a lot of edge cases that aren't covered.

Also, when I tried using the solution you proposed in PR, I noticed that the error it was throwing was not the same as the ones that block your Neovim instance (I don't know what are they called), as I thought at first. So I think this solution is good enough until the better one emerges.

PS: I will not merge your PR, because it uses the API function that is deprecated in nightly versions, and the "use instead" function already exists in versions 0.9.x

@gerazov
Copy link
Contributor Author

gerazov commented Dec 26, 2023

Yeah that is a hell of a hack but it could do the trick - as long as the user can't enter insert mode 👍

Great that it got solved - thanks 🙏

NStefan002 added a commit that referenced this issue Dec 26, 2023
@gerazov
Copy link
Contributor Author

gerazov commented Dec 30, 2023

I keep getting the E21 errors all the time 😅

Can you still merge the hack that disables all inserting commands? 🙏

@NStefan002 NStefan002 reopened this Dec 31, 2023
@NStefan002 NStefan002 added the enhancement New feature or request label Dec 31, 2023
NStefan002 added a commit that referenced this issue Dec 31, 2023
NStefan002 added a commit that referenced this issue Dec 31, 2023
fix: hacky solution that solves #11
@NStefan002
Copy link
Owner

Do you mind testing it now, @gerazov? I will leave this issue open for now.

@gerazov
Copy link
Contributor Author

gerazov commented Dec 31, 2023

Works great - thanks 🤟

@gerazov gerazov closed this as completed Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants