Don't generate names with visualized SPC and BS for the sxnui

You know, this doesn't really help right now, but it should fix #16577,
and maybe help with #16578 (but not the command palette part)
This commit is contained in:
Mike Griese
2024-02-21 09:17:44 -06:00
parent c94c00b760
commit 01ca03f433
2 changed files with 32 additions and 2 deletions

View File

@@ -945,17 +945,27 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
cmdImpl.copy_from(winrt::get_self<implementation::Command>(command));
const auto inArgs{ command.ActionAndArgs().Args().try_as<Model::SendInputArgs>() };
const auto inputString{ (std::wstring_view)(inArgs ? inArgs.Input() : L"") };
auto args = winrt::make_self<SendInputArgs>(
winrt::hstring{ fmt::format(FMT_COMPILE(L"{:\x7f^{}}{}"),
L"",
numBackspaces,
(std::wstring_view)(inArgs ? inArgs.Input() : L"")) });
inputString) });
Model::ActionAndArgs actionAndArgs{ ShortcutAction::SendInput, *args };
auto copy = cmdImpl->Copy();
copy->ActionAndArgs(actionAndArgs);
if (!copy->HasName())
{
// Here, we want to manually generate a send input name, but
// without visualizing space and backspace
//
// TODO! Do we want to include `Send Input: ` in the generated
// string? I think it looks better without it tbh
copy->Name(winrt::hstring{ til::visualize_nonspace_control_codes(std::wstring{ inputString }) });
}
return *copy;
};

View File

@@ -24,6 +24,26 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
}
return str;
}
_TIL_INLINEPREFIX std::wstring visualize_nonspace_control_codes(std::wstring str) noexcept
{
for (auto& ch : str)
{
// NOT backspace!
if (ch < 0x20 && ch != 0x08)
{
ch += 0x2400;
}
// else if (ch == 0x20)
// {
// ch = 0x2423; // replace space with ␣
// }
else if (ch == 0x7f)
{
ch = 0x2421; // replace del with ␡
}
}
return str;
}
_TIL_INLINEPREFIX std::wstring visualize_control_codes(std::wstring_view str)
{