Skip to content

Commit

Permalink
Don't generate names with visualized SPC and BS for the sxnui
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
zadjii-msft committed May 13, 2024
1 parent fae7cff commit c58fbae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,17 +964,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;
};

Expand Down
20 changes: 20 additions & 0 deletions src/inc/til/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit c58fbae

Please sign in to comment.