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

[FHL] Make VTApiRoutines, which does VT translation for output #11264

Merged
34 commits merged into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
eebed6a
Make a VTApiRoutines servicer that does minimal translations instead …
miniksa Jul 26, 2021
759a919
the rest of the stuff I did on Tuesday.
miniksa Jul 28, 2021
9325839
cooked read in cmd works omg.
miniksa Sep 17, 2021
3314e4a
remove one bit of badness
miniksa Jul 30, 2021
3372462
fix a thing where we would see the cursor on offs because it did not …
miniksa Aug 2, 2021
9277ff3
Define feature for this. Start piping through setting.
miniksa Sep 17, 2021
7549a04
change activation mechanism for passthrough
miniksa Sep 2, 2021
9bc88d3
argument/option for passthrough mode
miniksa Sep 15, 2021
f048c7d
some pre-review cleanup
miniksa Sep 17, 2021
8981585
have a few commas
miniksa Sep 17, 2021
338e62c
code format!
miniksa Sep 17, 2021
d23b9b0
fix some build errors
miniksa Jan 11, 2022
4749b68
more build fixes
miniksa Jan 11, 2022
1151239
code format
miniksa Jan 11, 2022
b43fa07
fix these tests by allocating the api handler.
miniksa Jan 12, 2022
08415e7
revert write change as it causes infinite loops with emoji
miniksa Jan 12, 2022
ea2a551
WELL THAT WAS EASY (to add the Settings UI toggle.)
miniksa Jan 12, 2022
dd83607
code format
miniksa Jan 12, 2022
5e740c8
take a different strategy for the default api routines since so many …
miniksa Jan 13, 2022
c85b2c9
unify includes beteween host and test project to the common one.
miniksa Jan 13, 2022
3383816
some PR comment odds and ends
miniksa Jan 13, 2022
7cb22a1
more PR feedback shuffling.
miniksa Jan 13, 2022
cd58080
code format!
miniksa Jan 13, 2022
379224a
rearrange public/private
miniksa Jan 14, 2022
85ae5bf
Messed up merge + a nit
miniksa Feb 12, 2022
daa154c
more bad merge
miniksa Feb 12, 2022
063ad97
ok pull this in
miniksa Feb 12, 2022
7b2e216
code format!
miniksa Feb 12, 2022
f070e89
actually check the setting before passing the flag down
miniksa Feb 23, 2022
72e8ecc
Apply correct style to toggleswitch
miniksa Feb 23, 2022
df4614e
address feedback
miniksa Feb 25, 2022
d6d8521
Merge remote-tracking branch 'origin/main' into dev/miniksa/vtapi
DHowett Mar 21, 2022
b348b29
Merge remote-tracking branch 'origin/main' into dev/miniksa/vtapi
DHowett Mar 30, 2022
61e8822
Only instantiate VtApiEtc if the feature is on
DHowett Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/actions/spelling/allow/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ lround
Lsa
lsass
LSHIFT
memchr
memicmp
MENUCOMMAND
MENUDATA
MENUINFO
MENUITEMINFOW
MENUINFO
MOUSELEAVE
mov
mptt
Expand Down
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ DECAUPSS
DECAWM
DECCKM
DECCOLM
DECCRA
DECDHL
decdld
DECDLD
Expand Down Expand Up @@ -2632,6 +2633,7 @@ VSTS
VSTT
vstudio
vswhere
vtapi
vtapp
VTE
VTID
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@
"xlocinfo": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp"
"xtr1common": "cpp",
"coroutine": "cpp",
"format": "cpp",
"forward_list": "cpp",
"latch": "cpp"
},
"files.exclude": {
"**/bin/**": true,
Expand Down
4 changes: 4 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,10 @@
"default": false,
"description": "When true, this profile should always open in an elevated context. If the window isn't running as an Administrator, then a new elevated window will be created."
},
"experimental.connection.passthroughMode": {
"description": "When set to true, directs the PTY for this connection to use pass-through mode instead of the original Conhost PTY simulation engine. This is an experimental feature, and its continued existence is not guaranteed.",
"type": "boolean"
},
"experimental.retroTerminalEffect": {
"description": "When set to true, enable retro terminal effects. This is an experimental feature, and its continued existence is not guaranteed.",
"type": "boolean"
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/PublicTerminalCore/HwndTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ HRESULT HwndTerminal::Initialize()
_terminal->Create(COORD{ 80, 25 }, 1000, *_renderer);
_terminal->SetColorTableEntry(TextColor::DEFAULT_BACKGROUND, RGB(12, 12, 12));
_terminal->SetColorTableEntry(TextColor::DEFAULT_FOREGROUND, RGB(204, 204, 204));
_terminal->SetWriteInputCallback([=](std::wstring& input) noexcept { _WriteTextToConnection(input); });
_terminal->SetWriteInputCallback([=](std::wstring_view input) noexcept { _WriteTextToConnection(input); });
localPointerToThread->EnablePainting();

_multiClickTime = std::chrono::milliseconds{ GetDoubleClickTime() };
Expand Down Expand Up @@ -282,7 +282,7 @@ void HwndTerminal::RegisterScrollCallback(std::function<void(int, int, int)> cal
_terminal->SetScrollPositionChangedCallback(callback);
}

void HwndTerminal::_WriteTextToConnection(const std::wstring& input) noexcept
void HwndTerminal::_WriteTextToConnection(const std::wstring_view input) noexcept
{
if (!_pfnWriteCallback)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/PublicTerminalCore/HwndTerminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct HwndTerminal : ::Microsoft::Console::Types::IControlAccessibilityInfo
friend void _stdcall TerminalKillFocus(void* terminal);

void _UpdateFont(int newDpi);
void _WriteTextToConnection(const std::wstring& text) noexcept;
void _WriteTextToConnection(const std::wstring_view text) noexcept;
HRESULT _CopyTextToSystemClipboard(const TextBuffer::TextAndColor& rows, bool const fAlsoCopyFormatting);
HRESULT _CopyToSystemClipboard(std::string stringToCopy, LPCWSTR lpszFormat);
void _PasteTextFromClipboard() noexcept;
Expand Down
39 changes: 25 additions & 14 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,13 +1070,20 @@ namespace winrt::TerminalApp::implementation
std::filesystem::path azBridgePath{ wil::GetModuleFileNameW<std::wstring>(nullptr) };
azBridgePath.replace_filename(L"TerminalAzBridge.exe");
connection = TerminalConnection::ConptyConnection();
connection.Initialize(TerminalConnection::ConptyConnection::CreateSettings(azBridgePath.wstring(),
L".",
L"Azure",
nullptr,
::base::saturated_cast<uint32_t>(settings.InitialRows()),
::base::saturated_cast<uint32_t>(settings.InitialCols()),
winrt::guid()));
auto valueSet = TerminalConnection::ConptyConnection::CreateSettings(azBridgePath.wstring(),
L".",
L"Azure",
nullptr,
::base::saturated_cast<uint32_t>(settings.InitialRows()),
::base::saturated_cast<uint32_t>(settings.InitialCols()),
winrt::guid());

if constexpr (Feature_VtPassthroughMode::IsEnabled())
{
valueSet.Insert(L"passthroughMode", Windows::Foundation::PropertyValue::CreateBoolean(settings.VtPassthrough()));
}

connection.Initialize(valueSet);
}

else
Expand Down Expand Up @@ -1114,13 +1121,17 @@ namespace winrt::TerminalApp::implementation
}

auto conhostConn = TerminalConnection::ConptyConnection();
conhostConn.Initialize(TerminalConnection::ConptyConnection::CreateSettings(settings.Commandline(),
newWorkingDirectory,
settings.StartingTitle(),
envMap.GetView(),
::base::saturated_cast<uint32_t>(settings.InitialRows()),
::base::saturated_cast<uint32_t>(settings.InitialCols()),
winrt::guid()));
auto valueSet = TerminalConnection::ConptyConnection::CreateSettings(settings.Commandline(),
newWorkingDirectory,
settings.StartingTitle(),
envMap.GetView(),
::base::saturated_cast<uint32_t>(settings.InitialRows()),
::base::saturated_cast<uint32_t>(settings.InitialCols()),
winrt::guid());

valueSet.Insert(L"passthroughMode", Windows::Foundation::PropertyValue::CreateBoolean(settings.VtPassthrough()));

conhostConn.Initialize(valueSet);

sessionGuid = conhostConn.Guid();
connection = conhostConn;
Expand Down
16 changes: 15 additions & 1 deletion src/cascadia/TerminalConnection/ConptyConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
_initialCols = winrt::unbox_value_or<uint32_t>(settings.TryLookup(L"initialCols").try_as<Windows::Foundation::IPropertyValue>(), _initialCols);
_guid = winrt::unbox_value_or<winrt::guid>(settings.TryLookup(L"guid").try_as<Windows::Foundation::IPropertyValue>(), _guid);
_environment = settings.TryLookup(L"environment").try_as<Windows::Foundation::Collections::ValueSet>();
if constexpr (Feature_VtPassthroughMode::IsEnabled())
{
_passthroughMode = winrt::unbox_value_or<bool>(settings.TryLookup(L"passthroughMode").try_as<Windows::Foundation::IPropertyValue>(), _passthroughMode);
}
}

if (_guid == guid{})
Expand Down Expand Up @@ -295,7 +299,17 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
// handoff from an already-started PTY process.
if (!_inPipe)
{
THROW_IF_FAILED(_CreatePseudoConsoleAndPipes(dimensions, PSEUDOCONSOLE_RESIZE_QUIRK | PSEUDOCONSOLE_WIN32_INPUT_MODE, &_inPipe, &_outPipe, &_hPC));
DWORD flags = PSEUDOCONSOLE_RESIZE_QUIRK | PSEUDOCONSOLE_WIN32_INPUT_MODE;

if constexpr (Feature_VtPassthroughMode::IsEnabled())
{
if (_passthroughMode)
{
WI_SetFlag(flags, PSEUDOCONSOLE_PASSTHROUGH_MODE);
Copy link
Member

Choose a reason for hiding this comment

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

This may not compile in Release. You are using a preprocessor define to control whether the constant is visible, but a constexpr if (which must compile successfully) wherein you are using the constant.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, you're gating the presence of the member using the preprocessor as well.

Try a build from the commandline with /p:WindowsTerminalBranding=Release

Copy link
Member

Choose a reason for hiding this comment

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

I'd say, keep the member and the constant defined and only gate whether the code actually touches them based on if constexpr

}
}

THROW_IF_FAILED(_CreatePseudoConsoleAndPipes(dimensions, flags, &_inPipe, &_outPipe, &_hPC));
THROW_IF_FAILED(_LaunchAttachedClient());
}
// But if it was an inbound handoff... attempt to synchronize the size of it with what our connection
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalConnection/ConptyConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
til::u8state _u8State{};
std::wstring _u16Str{};
std::array<char, 4096> _buffer{};
bool _passthroughMode{};

DWORD _OutputThread();
};
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// This event is explicitly revoked in the destructor: does not need weak_ref
_connectionOutputEventToken = _connection.TerminalOutput({ this, &ControlCore::_connectionOutputHandler });

_terminal->SetWriteInputCallback([this](std::wstring& wstr) {
_terminal->SetWriteInputCallback([this](std::wstring_view wstr) {
_sendInputToConnection(wstr);
});

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/ICoreSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.Terminal.Core
Boolean ForceVTInput;
Boolean TrimBlockSelection;
Boolean DetectURLs;
Boolean VtPassthrough;

Windows.Foundation.IReference<Microsoft.Terminal.Core.Color> TabColor;
Windows.Foundation.IReference<Microsoft.Terminal.Core.Color> StartingTabColor;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalCore/ITerminalApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace Microsoft::Terminal::Core

virtual void PrintString(std::wstring_view string) = 0;

virtual bool ReturnResponse(std::wstring_view responseString) = 0;

virtual TextAttribute GetTextAttributes() const = 0;
virtual void SetTextAttributes(const TextAttribute& attrs) = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ void Terminal::_NotifyTerminalCursorPositionChanged() noexcept
}
}

void Terminal::SetWriteInputCallback(std::function<void(std::wstring&)> pfn) noexcept
void Terminal::SetWriteInputCallback(std::function<void(std::wstring_view)> pfn) noexcept
{
_pfnWriteInput.swap(pfn);
}
Expand Down
9 changes: 5 additions & 4 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class Microsoft::Terminal::Core::Terminal final :
void UpdateAppearance(const winrt::Microsoft::Terminal::Core::ICoreAppearance& appearance);
void SetFontInfo(const FontInfo& fontInfo);

// Write goes through the parser
// Write comes from the PTY and goes to our parser to be stored in the output buffer
void Write(std::wstring_view stringView);

// WritePastedText goes directly to the connection
// WritePastedText comes from our input and goes back to the PTY's input channel
void WritePastedText(std::wstring_view stringView);

[[nodiscard]] std::unique_lock<til::ticket_lock> LockForReading();
Expand All @@ -97,6 +97,7 @@ class Microsoft::Terminal::Core::Terminal final :
#pragma region ITerminalApi
// These methods are defined in TerminalApi.cpp
void PrintString(std::wstring_view stringView) override;
bool ReturnResponse(std::wstring_view responseString) override;
TextAttribute GetTextAttributes() const override;
void SetTextAttributes(const TextAttribute& attrs) override;
Microsoft::Console::Types::Viewport GetBufferSize() override;
Expand Down Expand Up @@ -197,7 +198,7 @@ class Microsoft::Terminal::Core::Terminal final :
const bool IsUiaDataInitialized() const noexcept override;
#pragma endregion

void SetWriteInputCallback(std::function<void(std::wstring&)> pfn) noexcept;
void SetWriteInputCallback(std::function<void(std::wstring_view)> pfn) noexcept;
void SetWarningBellCallback(std::function<void()> pfn) noexcept;
void SetTitleChangedCallback(std::function<void(std::wstring_view)> pfn) noexcept;
void SetTabColorChangedCallback(std::function<void(const std::optional<til::color>)> pfn) noexcept;
Expand Down Expand Up @@ -252,7 +253,7 @@ class Microsoft::Terminal::Core::Terminal final :
#pragma endregion

private:
std::function<void(std::wstring&)> _pfnWriteInput;
std::function<void(std::wstring_view)> _pfnWriteInput;
std::function<void()> _pfnWarningBell;
std::function<void(std::wstring_view)> _pfnTitleChanged;
std::function<void(std::wstring_view)> _pfnCopyToClipboard;
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ TextAttribute Terminal::GetTextAttributes() const
return _buffer->GetCurrentAttributes();
}

bool Terminal::ReturnResponse(std::wstring_view responseString)
{
if (!_pfnWriteInput)
{
return false;
}
_pfnWriteInput(responseString);
return true;
}

void Terminal::SetTextAttributes(const TextAttribute& attrs)
{
_buffer->SetCurrentAttributes(attrs);
Expand Down
64 changes: 64 additions & 0 deletions src/cascadia/TerminalCore/TerminalDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,58 @@ bool TerminalDispatch::ResetMode(const DispatchTypes::ModeParams param)
return _ModeParamsHelper(param, false);
}

// Routine Description:
// - DSR - Reports status of a console property back to the STDIN based on the type of status requested.
// - This particular routine responds to ANSI status patterns only (CSI # n), not the DEC format (CSI ? # n)
// Arguments:
// - statusType - ANSI status type indicating what property we should report back
// Return Value:
// - True if handled successfully. False otherwise.
bool TerminalDispatch::DeviceStatusReport(const DispatchTypes::AnsiStatusType statusType)
{
bool success = false;

switch (statusType)
{
case DispatchTypes::AnsiStatusType::OS_OperatingStatus:
success = _OperatingStatus();
break;
case DispatchTypes::AnsiStatusType::CPR_CursorPositionReport:
success = _CursorPositionReport();
break;
}

return success;
}

// Routine Description:
// - DSR-OS - Reports the operating status back to the input channel
// Arguments:
// - <none>
// Return Value:
// - True if handled successfully. False otherwise.
bool TerminalDispatch::_OperatingStatus() const
{
// We always report a good operating condition.
return _WriteResponse(L"\x1b[0n");
}

// Routine Description:
// - DSR-CPR - Reports the current cursor position within the viewport back to the input channel
// Arguments:
// - <none>
// Return Value:
// - True if handled successfully. False otherwise.
bool TerminalDispatch::_CursorPositionReport() const
{
// Now send it back into the input channel of the console.
// First format the response string.
const auto pos = _terminalApi.GetCursorPosition();
// VT has origin at 1,1 where as we use 0,0 internally
const auto response = wil::str_printf<std::wstring>(L"\x1b[%d;%dR", pos.Y + 1, pos.X + 1);
return _WriteResponse(response);
}

// Method Description:
// - Start a hyperlink
// Arguments:
Expand Down Expand Up @@ -545,6 +597,18 @@ bool TerminalDispatch::DoConEmuAction(const std::wstring_view string)
return false;
}

// Routine Description:
// - Helper to send a string reply to the input stream of the console.
// - Used by various commands where the program attached would like a reply to one of the commands issued.
// Arguments:
// - reply - The reply string to transmit back to the input stream
// Return Value:
// - True if the string was sent to the connected application. False otherwise.
bool TerminalDispatch::_WriteResponse(const std::wstring_view reply) const
{
return _terminalApi.ReturnResponse(reply);
}

// Routine Description:
// - Support routine for routing private mode parameters to be set/reset as flags
// Arguments:
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalCore/TerminalDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class TerminalDispatch : public Microsoft::Console::VirtualTerminal::TermDispatc
bool SetMode(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::ModeParams /*param*/) override; // DECSET
bool ResetMode(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::ModeParams /*param*/) override; // DECRST

bool DeviceStatusReport(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::AnsiStatusType /*statusType*/) override; // DSR, DSR-OS, DSR-CPR

bool AddHyperlink(const std::wstring_view uri, const std::wstring_view params) override;
bool EndHyperlink() override;

Expand All @@ -90,8 +92,12 @@ class TerminalDispatch : public Microsoft::Console::VirtualTerminal::TermDispatc
TextAttribute& attr,
const bool isForeground);

bool _WriteResponse(const std::wstring_view reply) const;
bool _ModeParamsHelper(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::ModeParams param, const bool enable);

bool _OperatingStatus() const;
bool _CursorPositionReport() const;

void _ClearSingleTabStop();
void _ClearAllTabStops();
void _ResetTabStops();
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return Feature_AtlasEngine::IsEnabled();
}

bool ProfileViewModel::VtPassthroughAvailable() const noexcept
{
return Feature_VtPassthroughMode::IsEnabled();
}

bool ProfileViewModel::UseParentProcessDirectory()
{
return StartingDirectory().empty();
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsEditor/ProfileViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void CreateUnfocusedAppearance();
void DeleteUnfocusedAppearance();
bool AtlasEngineAvailable() const noexcept;
bool VtPassthroughAvailable() const noexcept;

VIEW_MODEL_OBSERVABLE_PROPERTY(ProfileSubPage, CurrentPage);

Expand Down Expand Up @@ -103,6 +104,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
OBSERVABLE_PROJECTED_SETTING(_profile, BellStyle);
OBSERVABLE_PROJECTED_SETTING(_profile, UseAtlasEngine);
OBSERVABLE_PROJECTED_SETTING(_profile, Elevate);
OBSERVABLE_PROJECTED_SETTING(_profile, VtPassthrough)

WINRT_PROPERTY(bool, IsBaseLayer, false);
WINRT_PROPERTY(IHostedInWindow, WindowRoot, nullptr);
Expand Down
Loading