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

Add support for the DECSWT (Set Window Title) escape sequence #16804

Merged
merged 8 commits into from
Mar 4, 2024

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Mar 3, 2024

This PR adds support for the OSC 21 sequence used on DEC terminals to
set the window title. It's just an alias of the OSC 2 title sequence
used by XTerm.

This PR also corrects the handling of blank title sequences, which are
supposed to reset the title to its default value, but were previously
ignored.

Detailed Description of the Pull Request / Additional comments

To handle the blank title parsing correctly, I had to make some changes
to the state machine. Previously it would not have dispatched an OSC
sequence unless it received a semicolon following the OSC number, but
when there's a blank string, that semicolon should not be required.

I also took this opportunity to simplify the OSC parsing in the state
machine, and eliminate the _GetOscTitle method which no longer served
any purpose.

Validation Steps Performed

I've manually confirmed that the title sequences are now working as
expected, and added some state machine unit tests covering the blank
value handling for these sequences.

I also had to update one of the existing state machine tests to account
for the changes I made to allow the semicolon to be omitted.

Closes #16783
Closes #16784

@j4james j4james marked this pull request as ready for review March 3, 2024 01:18
Comment on lines -162 to +168
// - title - The null-terminated string to set as the window title
// - title - The string to set as the window title
// Return Value:
// - <none>
void ConhostInternalGetSet::SetWindowTitle(std::wstring_view title)
{
ServiceLocator::LocateGlobals().getConsoleInformation().SetTitle(title);
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
gci.SetTitle(title.empty() ? gci.GetOriginalTitle() : title);
Copy link
Collaborator Author

@j4james j4james Mar 3, 2024

Choose a reason for hiding this comment

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

I'm not sure why the title parameter originally expected to be null-terminated, but that's no longer the case. The CONSOLE_INFORMATION::SetTitle method immediately constructs a std::wstring with that parameter, and in the Terminal::SetWindowTitle implementation, it's assigned to a std::optional<std::wstring> using emplace. Neither of those should need a null-terminated string_view as far as I understand.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, probably vestiges of the pre-wstring times :)

virtual bool ActionOscDispatch(const wchar_t wch,
const size_t parameter,
const std::wstring_view string) = 0;
virtual bool ActionOscDispatch(const size_t parameter, const std::wstring_view string) = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dropped the wch parameter from this method because it's never actually used for anything. It just indicated whether the sequence was terminated with a BEL or an ST backslash, but that's of no relevance to anyone.

Comment on lines -786 to +784
std::wstring title;
success = _GetOscTitle(string, title);
success = success && _dispatch->SetWindowTitle(title);
success = _dispatch->SetWindowTitle(string);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All that _GetOscTitle was doing was assigning the wstring_view to a wstring, and checking that it wasn't blank. But we don't actually want that blank check, and there's no reason why we can't just pass the wstring_view through to SetWindowTitle as is.

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Comprehensive as always. Thank you!

Comment on lines -162 to +168
// - title - The null-terminated string to set as the window title
// - title - The string to set as the window title
// Return Value:
// - <none>
void ConhostInternalGetSet::SetWindowTitle(std::wstring_view title)
{
ServiceLocator::LocateGlobals().getConsoleInformation().SetTitle(title);
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
gci.SetTitle(title.empty() ? gci.GetOriginalTitle() : title);
Copy link
Member

Choose a reason for hiding this comment

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

Ah, probably vestiges of the pre-wstring times :)

@DHowett DHowett merged commit 33589cd into microsoft:main Mar 4, 2024
15 checks passed
@j4james j4james deleted the feature-decswt branch March 7, 2024 17:13
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.

OSC 2 doesn't handle a blank title correctly Add support for DECSWT (Set Window Title)
3 participants