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

Move cursor to left margin for IL and DL controls #2731

Merged
merged 2 commits into from
Sep 12, 2019

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Sep 12, 2019

Summary of the Pull Request

According to the DEC STD 070 manual, the cursor position should be moved to the left margin after the execution of the IL and DL escape sequences. This PR updates the code to implement that behaviour.

PR Checklist

Detailed Description of the Pull Request / Additional comments

I've modified the DoSrvPrivateModifyLinesImpl function (which is where the IL and DL controls are ultimately handled), to update the cursor position - setting the column to 0 - after the screen has been scrolled. Note that this has to happen inside the IsCursorInMargins check, since the cursor is not supposed to be moved if it was outside the margin boundaries.

Also note that this should really be set to the left margin specified by DECSLRM, but we don't yet support that control, so for now it's hardcoded to 0.

When it came to actually setting the cursor position, I found there were a number of options to choose from, with quite different behaviours. Some operations use a variation of SetConsoleCursorPosition, some use AdjustCursorPosition, and some call the SCREEN_INFORMATION::SetCursorPosition method directly, or even just Cursor::SetPosition. It wasn't always clear to why a particular method was chosen.

I ultimately decided on SCREEN_INFORMATION::SetCursorPosition with the TurnOn parameter set to false, since that seemed the simplest option that also matched the behaviour of a carriage return. I'm not certain that's the best choice, though, so I'm open to other suggestions.

Validation Steps Performed

There were a number of existing IL and DL tests that assumed the cursor position was not meant to move, and validated that behaviour. I've updated all of those tests to confirm that cursor position is now moved to column 0 when those escape sequences are executed.

@zadjii-msft zadjii-msft added Area-VT Virtual Terminal sequence support Product-Conhost For issues in the Console codebase labels Sep 12, 2019
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

This seems like the way I'd do it. Great work as always :)

@zadjii-msft zadjii-msft added the Needs-Second It's a PR that needs another sign-off label Sep 12, 2019
@miniksa
Copy link
Member

miniksa commented Sep 12, 2019

Also note that this should really be set to the left margin specified by DECSLRM, but we don't yet support that control, so for now it's hardcoded to 0.

Should this be filed as a backlog future work item?

@miniksa
Copy link
Member

miniksa commented Sep 12, 2019

When it came to actually setting the cursor position, I found there were a number of options to choose from, with quite different behaviours. Some operations use a variation of SetConsoleCursorPosition, some use AdjustCursorPosition, and some call the SCREEN_INFORMATION::SetCursorPosition method directly, or even just Cursor::SetPosition. It wasn't always clear to why a particular method was chosen.

This certainly needs a follow up work item. I'm reviewing some of the code in each of these to try to come up with reasoning why you should use one over the other... and I'm realizing that this is probably the source of our "the cursor is blinking weirdly or is on when it shouldn't be while text is outputting" problems.

As far as I can tell, you've chosen the correct one with SCREEN_INFORMATION::SetCursorPosition because that one is responsible for updating the delay status on the cursor so it stays off or on instead of blinking wildly as it is moving rapidly around the screen when things are happening. The cursor is supposed to temporarily suspend blinking when there is activity (by the delay).

I am certain the inconsistency in application of which cursor-setting-function is being used is responsible for graphical glitches.

@miniksa
Copy link
Member

miniksa commented Sep 12, 2019

When it came to actually setting the cursor position, I found there were a number of options to choose from, with quite different behaviours. Some operations use a variation of SetConsoleCursorPosition, some use AdjustCursorPosition, and some call the SCREEN_INFORMATION::SetCursorPosition method directly, or even just Cursor::SetPosition. It wasn't always clear to why a particular method was chosen.

This certainly needs a follow up work item. I'm reviewing some of the code in each of these to try to come up with reasoning why you should use one over the other... and I'm realizing that this is probably the source of our "the cursor is blinking weirdly or is on when it shouldn't be while text is outputting" problems.

As far as I can tell, you've chosen the correct one with SCREEN_INFORMATION::SetCursorPosition because that one is responsible for updating the delay status on the cursor so it stays off or on instead of blinking wildly as it is moving rapidly around the screen when things are happening. The cursor is supposed to temporarily suspend blinking when there is activity (by the delay).

I am certain the inconsistency in application of which cursor-setting-function is being used is responsible for graphical glitches.

I created #2739 for this one.

I left it up to @j4james and @zadjii-msft to determine if they want to track a future work item for DECSLRM.

@miniksa miniksa removed the Needs-Second It's a PR that needs another sign-off label Sep 12, 2019
@miniksa miniksa merged commit 1fccbc5 into microsoft:master Sep 12, 2019
@j4james j4james deleted the fix-ildl-xpos branch September 22, 2019 09:28
DHowett-MSFT pushed a commit that referenced this pull request Sep 23, 2019
* Move cursor position to the left margin after execution of the IL and DL escape sequences.
* Update IL and DL screen buffer tests to account for the cursor moving to the left margin.

(cherry picked from commit 1fccbc5)
@ghost
Copy link

ghost commented Sep 24, 2019

🎉Windows Terminal Preview v0.5.2661.0 has been released which incorporates this pull request.:tada:

Handy links:

@DHowett-MSFT
Copy link
Contributor

This went out for conhost in insider build 19002! Thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IL and DL commands should move cursor to left margin
4 participants