[mainloop-] prevent input() errors while pasting keys #2378
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When pasting a string into the terminal, a long sequence of keys such as
aaaaaaaaaaaO
(with a trailing space), will trigger an error:(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 timedraw_all()
is called inmainloop()
. 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
) andEnter
. It can create an OptionsSheet and runedit-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.