This PR adds a terminal.EraseScreen function to support the "Erase in Display" ANSI control sequence. This function replaces calls to terminal.ClearLine in resetPrompt in order to clear previous prompt output entirely and atomically, instead of clearing each line in an iterative manner.
Updating resetPrompt to clear to the end of the screen seems to significantly reduce the "flickering" effect noted in #436 since fewer updates to the terminal screen are made between each render.
Additionally, the MultiLine prompt was updated as a result of changes to the resetPrompt logic. This prompt now preserves leading and trailing spaces in answers and replaces the input template with an answered template after submission. The template was also updated to begin inputs on a newline, which happens to be a request of #336.
The following steps can be used to inspect these changes:
Checkout this branch
In a project using survey and survey.Select, survey.MultiSelect, or survey.MultiLine, append the following to your go.mod, pointing to your local survey source:
Run your project and rapidly page through select options in an attempt to reproduce the flickering effect.
Notes
Flickering is not entirely removed since there is brief moment between clearing the past prompt and outputting the updated one where the erased screen might be shown. This seems to be a fairly rare occurrence though, only happening a handful of times in my testing. The "synchronized update" suggestion from @dnkl would likely prevent this, but I had some difficulties in implementing this.
This has not been tested with a Windows terminal, however I presume this escape code is properly handled as "virtual terminal sequences are recommended" when developing for Windows.
These changes are also likely to impact the updates in #474, as both PRs are modifying the logic of resetPrompt.
These changes do not seem to impact the current behavior shown in #452.
Summary
This PR adds a
terminal.EraseScreen
function to support the "Erase in Display" ANSI control sequence. This function replaces calls toterminal.ClearLine
inresetPrompt
in order to clear previous prompt output entirely and atomically, instead of clearing each line in an iterative manner.Updating
resetPrompt
to clear to the end of the screen seems to significantly reduce the "flickering" effect noted in #436 since fewer updates to the terminal screen are made between each render.Additionally, the
MultiLine
prompt was updated as a result of changes to theresetPrompt
logic. This prompt now preserves leading and trailing spaces in answers and replaces the input template with an answered template after submission. The template was also updated to begin inputs on a newline, which happens to be a request of #336.Preview
Before
https://user-images.githubusercontent.com/18134219/205465447-cda292c1-bb7b-4ef3-af26-aa450b00791b.mp4
After
https://user-images.githubusercontent.com/18134219/205465499-ed0040e4-80ec-49e8-b0df-9223258a1b10.mp4
Reviewers
The following steps can be used to inspect these changes:
Checkout this branch
In a project using
survey
andsurvey.Select
,survey.MultiSelect
, orsurvey.MultiLine
, append the following to yourgo.mod
, pointing to your localsurvey
source:Run your project and rapidly page through select options in an attempt to reproduce the flickering effect.
Notes
Flickering is not entirely removed since there is brief moment between clearing the past prompt and outputting the updated one where the erased screen might be shown. This seems to be a fairly rare occurrence though, only happening a handful of times in my testing. The "synchronized update" suggestion from @dnkl would likely prevent this, but I had some difficulties in implementing this.
This has not been tested with a Windows terminal, however I presume this escape code is properly handled as "virtual terminal sequences are recommended" when developing for Windows.
resetPrompt
.These changes do not seem to impact the current behavior shown in #452.