Merge remote-tracking branch 'origin/main' into dev/migrie/oop/ragnarok

This commit is contained in:
Mike Griese 2021-11-11 11:08:54 -06:00
commit a338ca168c
7 changed files with 71 additions and 24 deletions

View file

@ -41,6 +41,7 @@ Lmid
Lorigin Lorigin
maxed maxed
mkmk mkmk
mnt
mru mru
noreply noreply
nje nje

View file

@ -28,6 +28,7 @@ namespace Microsoft.Terminal.Control
Microsoft.Terminal.Control.IControlAppearance Microsoft.Terminal.Control.IControlAppearance
{ {
String ProfileName; String ProfileName;
String ProfileSource;
Boolean UseAcrylic { get; }; Boolean UseAcrylic { get; };
ScrollbarState ScrollState { get; }; ScrollbarState ScrollState { get; };

View file

@ -2296,6 +2296,42 @@ namespace winrt::Microsoft::Terminal::Control::implementation
} }
std::wstring fullPath{ item.Path() }; std::wstring fullPath{ item.Path() };
// Fix path for WSL
if (_settings.ProfileSource() == L"Windows.Terminal.Wsl")
{
std::replace(fullPath.begin(), fullPath.end(), L'\\', L'/');
if (fullPath.size() >= 2 && fullPath.at(1) == L':')
{
// C:/foo/bar -> Cc/foo/bar
fullPath.at(1) = til::tolower_ascii(fullPath.at(0));
// Cc/foo/bar -> /mnt/c/foo/bar
fullPath.replace(0, 1, L"/mnt/");
}
else
{
static constexpr std::wstring_view wslPathPrefixes[] = { L"//wsl.localhost/", L"//wsl$/" };
for (auto prefix : wslPathPrefixes)
{
if (til::starts_with(fullPath, prefix))
{
if (const auto idx = fullPath.find(L'/', prefix.size()); idx != std::wstring::npos)
{
// //wsl.localhost/Ubuntu-18.04/foo/bar -> /foo/bar
fullPath.erase(0, idx);
}
else
{
// //wsl.localhost/Ubuntu-18.04 -> /
fullPath = L"/";
}
break;
}
}
}
}
const auto containsSpaces = std::find(fullPath.begin(), const auto containsSpaces = std::find(fullPath.begin(),
fullPath.end(), fullPath.end(),
L' ') != fullPath.end(); L' ') != fullPath.end();
@ -2308,6 +2344,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
allPaths += fullPath; allPaths += fullPath;
} }
_core.PasteText(winrt::hstring{ allPaths }); _core.PasteText(winrt::hstring{ allPaths });
} }
} }

View file

@ -222,6 +222,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Fill in the remaining properties from the profile // Fill in the remaining properties from the profile
_ProfileName = profile.Name(); _ProfileName = profile.Name();
_ProfileSource = profile.Source();
_UseAcrylic = profile.UseAcrylic(); _UseAcrylic = profile.UseAcrylic();
_FontFace = profile.FontInfo().FontFace(); _FontFace = profile.FontInfo().FontFace();

View file

@ -112,6 +112,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// ------------------------ End of Core Settings ----------------------- // ------------------------ End of Core Settings -----------------------
INHERITABLE_SETTING(Model::TerminalSettings, hstring, ProfileName); INHERITABLE_SETTING(Model::TerminalSettings, hstring, ProfileName);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, ProfileSource);
INHERITABLE_SETTING(Model::TerminalSettings, bool, UseAcrylic, false); INHERITABLE_SETTING(Model::TerminalSettings, bool, UseAcrylic, false);
INHERITABLE_SETTING(Model::TerminalSettings, double, Opacity, UseAcrylic() ? 0.5 : 1.0); INHERITABLE_SETTING(Model::TerminalSettings, double, Opacity, UseAcrylic() ? 0.5 : 1.0);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, Padding, DEFAULT_PADDING); INHERITABLE_SETTING(Model::TerminalSettings, hstring, Padding, DEFAULT_PADDING);

View file

@ -50,6 +50,7 @@ namespace ControlUnitTests
// ------------------------ End of Core Settings ----------------------- // ------------------------ End of Core Settings -----------------------
WINRT_PROPERTY(winrt::hstring, ProfileName); WINRT_PROPERTY(winrt::hstring, ProfileName);
WINRT_PROPERTY(winrt::hstring, ProfileSource);
WINRT_PROPERTY(bool, UseAcrylic, false); WINRT_PROPERTY(bool, UseAcrylic, false);
WINRT_PROPERTY(double, Opacity, .5); WINRT_PROPERTY(double, Opacity, .5);
WINRT_PROPERTY(winrt::hstring, Padding, DEFAULT_PADDING); WINRT_PROPERTY(winrt::hstring, Padding, DEFAULT_PADDING);

View file

@ -2509,53 +2509,55 @@ ITermDispatch::StringHandler AdaptDispatch::RequestSetting()
// - None // - None
void AdaptDispatch::_ReportSGRSetting() const void AdaptDispatch::_ReportSGRSetting() const
{ {
using namespace std::string_view_literals;
// A valid response always starts with DCS 1 $ r. // A valid response always starts with DCS 1 $ r.
// Then the '0' parameter is to reset the SGR attributes to the defaults. // Then the '0' parameter is to reset the SGR attributes to the defaults.
std::wstring response = L"\033P1$r0"; fmt::basic_memory_buffer<wchar_t, 64> response;
response.append(L"\033P1$r0"sv);
TextAttribute attr; TextAttribute attr;
if (_pConApi->PrivateGetTextAttributes(attr)) if (_pConApi->PrivateGetTextAttributes(attr))
{ {
// For each boolean attribute that is set, we add the appropriate // For each boolean attribute that is set, we add the appropriate
// parameter value to the response string. // parameter value to the response string.
const auto addAttribute = [&](const auto parameter, const auto enabled) { const auto addAttribute = [&](const auto& parameter, const auto enabled) {
if (enabled) if (enabled)
{ {
response += parameter; response.append(parameter);
} }
}; };
addAttribute(L";1", attr.IsBold()); addAttribute(L";1"sv, attr.IsBold());
addAttribute(L";2", attr.IsFaint()); addAttribute(L";2"sv, attr.IsFaint());
addAttribute(L";3", attr.IsItalic()); addAttribute(L";3"sv, attr.IsItalic());
addAttribute(L";4", attr.IsUnderlined()); addAttribute(L";4"sv, attr.IsUnderlined());
addAttribute(L";5", attr.IsBlinking()); addAttribute(L";5"sv, attr.IsBlinking());
addAttribute(L";7", attr.IsReverseVideo()); addAttribute(L";7"sv, attr.IsReverseVideo());
addAttribute(L";8", attr.IsInvisible()); addAttribute(L";8"sv, attr.IsInvisible());
addAttribute(L";9", attr.IsCrossedOut()); addAttribute(L";9"sv, attr.IsCrossedOut());
addAttribute(L";21", attr.IsDoublyUnderlined()); addAttribute(L";21"sv, attr.IsDoublyUnderlined());
addAttribute(L";53", attr.IsOverlined()); addAttribute(L";53"sv, attr.IsOverlined());
// We also need to add the appropriate color encoding parameters for // We also need to add the appropriate color encoding parameters for
// both the foreground and background colors. // both the foreground and background colors.
const auto addColor = [&](const auto base, const auto color) { const auto addColor = [&](const auto base, const auto color) {
const auto iterator = std::back_insert_iterator(response);
if (color.IsIndex16()) if (color.IsIndex16())
{ {
const auto index = color.GetIndex(); const auto index = color.GetIndex();
const auto colorParameter = base + (index >= 8 ? 60 : 0) + (index % 8); const auto colorParameter = base + (index >= 8 ? 60 : 0) + (index % 8);
fmt::format_to(iterator, FMT_STRING(L";{}"), colorParameter); fmt::format_to(std::back_inserter(response), FMT_COMPILE(L";{}"), colorParameter);
} }
else if (color.IsIndex256()) else if (color.IsIndex256())
{ {
const auto index = color.GetIndex(); const auto index = color.GetIndex();
fmt::format_to(iterator, FMT_STRING(L";{};5;{}"), base + 8, index); fmt::format_to(std::back_inserter(response), FMT_COMPILE(L";{};5;{}"), base + 8, index);
} }
else if (color.IsRgb()) else if (color.IsRgb())
{ {
const auto r = GetRValue(color.GetRGB()); const auto r = GetRValue(color.GetRGB());
const auto g = GetGValue(color.GetRGB()); const auto g = GetGValue(color.GetRGB());
const auto b = GetBValue(color.GetRGB()); const auto b = GetBValue(color.GetRGB());
fmt::format_to(iterator, FMT_STRING(L";{};2;{};{};{}"), base + 8, r, g, b); fmt::format_to(std::back_inserter(response), FMT_COMPILE(L";{};2;{};{};{}"), base + 8, r, g, b);
} }
}; };
addColor(30, attr.GetForeground()); addColor(30, attr.GetForeground());
@ -2563,8 +2565,8 @@ void AdaptDispatch::_ReportSGRSetting() const
} }
// The 'm' indicates this is an SGR response, and ST ends the sequence. // The 'm' indicates this is an SGR response, and ST ends the sequence.
response += L"m\033\\"; response.append(L"m\033\\"sv);
_WriteResponse(response); _WriteResponse({ response.data(), response.size() });
} }
// Method Description: // Method Description:
@ -2575,8 +2577,11 @@ void AdaptDispatch::_ReportSGRSetting() const
// - None // - None
void AdaptDispatch::_ReportDECSTBMSetting() const void AdaptDispatch::_ReportDECSTBMSetting() const
{ {
using namespace std::string_view_literals;
// A valid response always starts with DCS 1 $ r. // A valid response always starts with DCS 1 $ r.
std::wstring response = L"\033P1$r"; fmt::basic_memory_buffer<wchar_t, 64> response;
response.append(L"\033P1$r"sv);
CONSOLE_SCREEN_BUFFER_INFOEX csbiex = { 0 }; CONSOLE_SCREEN_BUFFER_INFOEX csbiex = { 0 };
csbiex.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX); csbiex.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
@ -2592,11 +2597,10 @@ void AdaptDispatch::_ReportDECSTBMSetting() const
marginTop = 1; marginTop = 1;
marginBottom = csbiex.srWindow.Bottom - csbiex.srWindow.Top; marginBottom = csbiex.srWindow.Bottom - csbiex.srWindow.Top;
} }
const auto iterator = std::back_insert_iterator(response); fmt::format_to(std::back_inserter(response), FMT_COMPILE(L"{};{}"), marginTop, marginBottom);
fmt::format_to(iterator, FMT_STRING(L"{};{}"), marginTop, marginBottom);
} }
// The 'r' indicates this is an DECSTBM response, and ST ends the sequence. // The 'r' indicates this is an DECSTBM response, and ST ends the sequence.
response += L"r\033\\"; response.append(L"r\033\\"sv);
_WriteResponse(response); _WriteResponse({ response.data(), response.size() });
} }