Skip to content

Commit c0b1fe0

Browse files
Combine the parsing & dispatch blocks for OSC actions (#8202)
In `ActionOscDispatch()` in `OutputStateMachineEngine.cpp`, we had a section for parsing and another section for dispatching. This PR combines those two blocks since they do not need to be distinct. ## Validation Steps Performed TerminalApiTests still pass
1 parent 4998779 commit c0b1fe0

File tree

1 file changed

+69
-76
lines changed

1 file changed

+69
-76
lines changed

src/terminal/parser/OutputStateMachineEngine.cpp

Lines changed: 69 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -640,111 +640,104 @@ bool OutputStateMachineEngine::ActionOscDispatch(const wchar_t /*wch*/,
640640
const std::wstring_view string)
641641
{
642642
bool success = false;
643-
std::wstring title;
644-
std::wstring setClipboardContent;
645-
std::wstring params;
646-
std::wstring uri;
647-
bool queryClipboard = false;
648-
std::vector<size_t> tableIndexes;
649-
std::vector<DWORD> colors;
650643

651644
switch (parameter)
652645
{
653646
case OscActionCodes::SetIconAndWindowTitle:
654647
case OscActionCodes::SetWindowIcon:
655648
case OscActionCodes::SetWindowTitle:
649+
{
650+
std::wstring title;
656651
success = _GetOscTitle(string, title);
652+
success = success && _dispatch->SetWindowTitle(title);
653+
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCWT);
657654
break;
655+
}
658656
case OscActionCodes::SetColor:
657+
{
658+
std::vector<size_t> tableIndexes;
659+
std::vector<DWORD> colors;
659660
success = _GetOscSetColorTable(string, tableIndexes, colors);
661+
for (size_t i = 0; i < tableIndexes.size(); i++)
662+
{
663+
const auto tableIndex = til::at(tableIndexes, i);
664+
const auto rgb = til::at(colors, i);
665+
success = success && _dispatch->SetColorTableEntry(tableIndex, rgb);
666+
}
667+
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCCT);
660668
break;
669+
}
661670
case OscActionCodes::SetForegroundColor:
671+
{
672+
std::vector<DWORD> colors;
673+
success = _GetOscSetColor(string, colors);
674+
if (success && colors.size() > 0)
675+
{
676+
success = _dispatch->SetDefaultForeground(til::at(colors, 0));
677+
}
678+
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCFG);
679+
break;
680+
}
662681
case OscActionCodes::SetBackgroundColor:
682+
{
683+
std::vector<DWORD> colors;
684+
success = _GetOscSetColor(string, colors);
685+
if (success && colors.size() > 0)
686+
{
687+
success = _dispatch->SetDefaultBackground(til::at(colors, 0));
688+
}
689+
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCBG);
690+
break;
691+
}
663692
case OscActionCodes::SetCursorColor:
693+
{
694+
std::vector<DWORD> colors;
664695
success = _GetOscSetColor(string, colors);
696+
if (success && colors.size() > 0)
697+
{
698+
success = _dispatch->SetCursorColor(til::at(colors, 0));
699+
}
700+
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCSCC);
665701
break;
702+
}
666703
case OscActionCodes::SetClipboard:
704+
{
705+
std::wstring setClipboardContent;
706+
bool queryClipboard = false;
667707
success = _GetOscSetClipboard(string, setClipboardContent, queryClipboard);
708+
if (success && !queryClipboard)
709+
{
710+
success = _dispatch->SetClipboard(setClipboardContent);
711+
}
712+
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCSCB);
668713
break;
714+
}
669715
case OscActionCodes::ResetCursorColor:
670-
success = true;
716+
{
717+
success = _dispatch->SetCursorColor(0xffffffff);
718+
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCRCC);
671719
break;
720+
}
672721
case OscActionCodes::Hyperlink:
722+
{
723+
std::wstring params;
724+
std::wstring uri;
673725
success = _ParseHyperlink(string, params, uri);
726+
if (uri.empty())
727+
{
728+
success = success && _dispatch->EndHyperlink();
729+
}
730+
else
731+
{
732+
success = success && _dispatch->AddHyperlink(uri, params);
733+
}
674734
break;
735+
}
675736
default:
676737
// If no functions to call, overall dispatch was a failure.
677738
success = false;
678739
break;
679740
}
680-
if (success)
681-
{
682-
switch (parameter)
683-
{
684-
case OscActionCodes::SetIconAndWindowTitle:
685-
case OscActionCodes::SetWindowIcon:
686-
case OscActionCodes::SetWindowTitle:
687-
success = _dispatch->SetWindowTitle(title);
688-
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCWT);
689-
break;
690-
case OscActionCodes::SetColor:
691-
for (size_t i = 0; i < tableIndexes.size(); i++)
692-
{
693-
const auto tableIndex = til::at(tableIndexes, i);
694-
const auto rgb = til::at(colors, i);
695-
success = _dispatch->SetColorTableEntry(tableIndex, rgb);
696-
}
697-
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCCT);
698-
break;
699-
case OscActionCodes::SetForegroundColor:
700-
if (colors.size() > 0)
701-
{
702-
success = _dispatch->SetDefaultForeground(til::at(colors, 0));
703-
}
704-
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCFG);
705-
break;
706-
case OscActionCodes::SetBackgroundColor:
707-
if (colors.size() > 0)
708-
{
709-
success = _dispatch->SetDefaultBackground(til::at(colors, 0));
710-
}
711-
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCBG);
712-
break;
713-
case OscActionCodes::SetCursorColor:
714-
if (colors.size() > 0)
715-
{
716-
success = _dispatch->SetCursorColor(til::at(colors, 0));
717-
}
718-
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCSCC);
719-
break;
720-
case OscActionCodes::SetClipboard:
721-
if (!queryClipboard)
722-
{
723-
success = _dispatch->SetClipboard(setClipboardContent);
724-
}
725-
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCSCB);
726-
break;
727-
case OscActionCodes::ResetCursorColor:
728-
// the console uses 0xffffffff as an "invalid color" value
729-
success = _dispatch->SetCursorColor(0xffffffff);
730-
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCRCC);
731-
break;
732-
case OscActionCodes::Hyperlink:
733-
if (uri.empty())
734-
{
735-
success = _dispatch->EndHyperlink();
736-
}
737-
else
738-
{
739-
success = _dispatch->AddHyperlink(uri, params);
740-
}
741-
break;
742-
default:
743-
// If no functions to call, overall dispatch was a failure.
744-
success = false;
745-
break;
746-
}
747-
}
748741

749742
// If we were unable to process the string, and there's a TTY attached to us,
750743
// trigger the state machine to flush the string to the terminal.

0 commit comments

Comments
 (0)