Detect if an editor or pager is open in #prepareWith and, if so, close it
See exercises.api.mjs
, line 195.
The #prepareWith
method is crucial for us, because it allows to prepare each exercise by executing arbitrary, teacher-defined commands, and it also allows clearing the screen, which we make use of at the beginning of an exercise (to hide preparation commands) and right after verification (to hide verification commands) 1.
Because the VM needs to load several seconds after loading the page for the first time, #prepareWith
waits until it detects a prompt to start preparing.
However, there is one case when that causes it to wait indefinitely, namely, when the user has opened an editor or a pager. In this case, no prompt is shown, so #prepareWith
waits as long as the user closes the editor. This can cause issue in at least two cases:
- When the user opens an editor and decides to switch to another exercise
- When the user solves an exercise by opening an editor and manually confirming they are done
In both cases, nothing happens, because #prepareWith
silently waits. This is confusing.
What should be done
If #prepareWith
does not detect a prompt, it should see if it can detect an editor or a pager. If so, it should try to close that editor or pager; and then check again if it sees a prompt (which it definitely should, then).
-
In the happy path, verification is immediately followed by the beginning of the next exercise, so one could argue the clearing is redundant. However, in case of a failed verification, the user is dropped into the shell again with now re-preparation applied. To avoid them seeing the verification commands in case of a failed exercise, we need to clear twice.
↩