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

[mainloop-] prevent input() errors while pasting keys #2378

Merged
merged 1 commit into from May 20, 2024

Conversation

midichef
Copy link
Contributor

When pasting a string into the terminal, a long sequence of keys such as aaaaaaaaaaaO (with a trailing space), will trigger an error:

File "/home/midichef/.local/lib/python3.10/site-packages/visidata/_input.py", line 358, in editText
v = vd.editline(vd.activeSheet._scr, y, x, w, display=display, **kwargs)
File "/home/midichef/.local/lib/python3.10/site-packages/visidata/_input.py", line 288, in editline
ch = vd.getkeystroke(scr)
File "/home/midichef/.local/lib/python3.10/site-packages/visidata/vdobj.py", line 141, in getkeystroke
self.drainPendingKeys(scr)
File "/home/midichef/.local/lib/python3.10/site-packages/visidata/vdobj.py", line 124, in drainPendingKeys
scr.timeout(0)
AttributeError: 'NoneType' object has no attribute 'timeout'

(This is for v3.0 and develop. For v2.11.1, pasting this string causes visidata to freeze and consume a lot of CPU.)

Why this happens:
After a new active sheet is created, there is a brief interval when the sheet does not yet have a _scr value. That interval lasts until the next time draw_all() is called in mainloop(). When handling pasted keys, input() can run in that brief interval, and it expects the active sheet's _scr value to have already been set.

What this PR changes:
After each command in the mainloop, if the active sheet has no screen in _scr, draw_all() will run, to give the sheet a screen.

Other considerations when pasting:
Even after this patch, pasting quick sequences of keys into visidata will not always work well. For example, consider the sequence O (options-global) and Enter. It can create an OptionsSheet and run edit-option before the new Sheet loads any rows, causing a traceback.

To run a series of commands, users should not paste keys into the terminal, unless they have a delay between keys. The reliable way to run a series of commands is to use macros, or replay commands from .vdj files.

When keys were input extremely quickly, commands were running on
new sheets before they could be drawn and assigned a screen.
Copy link
Owner

@saulpw saulpw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this makes sense to me. Thanks for digging into the cause of this!

@anjakefala anjakefala merged commit 05536fb into saulpw:develop May 20, 2024
13 checks passed
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

Successfully merging this pull request may close these issues.

None yet

3 participants