Compare commits

...

3 commits

Author SHA1 Message Date
Mike Griese 491ec14291 Passthrough input too 2019-07-19 15:13:46 -05:00
Mike Griese 90271426e9 accidentally the whole thing 2019-07-19 11:07:20 -05:00
Mike Griese f5939ebd61 Implement a basic passthrough mode
* [ ] Doesn't immediately stop a frame when passthrough mode is entered.
  * [ ] Exiting passthrough will leave us in a torn state
  * [ ] Pretty sure that's the wrong place to put that flag

  Otherwise this was scary easy
2019-07-19 10:24:29 -05:00
23 changed files with 750 additions and 5 deletions

97
conpty.txt Normal file
View file

@ -0,0 +1,97 @@
Microsoft Windows [Version 10.0.18936.1001]]0;C:\WINDOWS\system32\cmd.exe[?25h
(c) 2019 Microsoft Corporation. All rights reserved.

[11:54:25.95]>c:\Users\migrie\dev\private\OpenConsole> 
[1] [dev/migrie/f/passthrough-2019] migrie@MIGRIE-SURFBOOK>wsl.exe
]0;C:\WINDOWS\system32\cmd.exe - wsl.exezadjii@migrie-surfbook:/mnt/c/Users/migrie/dev/private/OpenConsole$ ]0;zadjii@migrie-surfbook: /mnt/c/Users/migrie/dev/private/OpenConsolevi README.md
[?2004h[?2004h




























[?25h"README.md" 177L, 11259C[?25h[?2004l[?2004h[?25h[?2004l[?2004h▽[?25h[>c]10;?]11;?
[?25h README.md  ◀◀ buffers 
1 # Welcome\! 
2 #### This repository contains the source code for:
3 
4  * Windows Terminal
5  * The Windows console host (conhost.exe)
6  * Components shared between the two projects
7  * ColorTool
8  * 
8  * Sample projects that show how to consume the Window
s Console APIs
9  
10 #### Other related repositories include:
11  * Console API Documentation
12 
13 ### Build Status
14 
15 Project|Build Status
16 ---|---
17 Terminal|Build Status
17 Terminal|Build Status

18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004h
NORMAL ▶ ⎇ dev/migrie/f/passthrough-2019 ▶ < markdown ◀ [unix] ◀ 1,397 words « 3% ␊ 6/177 ㏑ : 46 ◀ Ξ [9]trailing ◀]0;/mnt/c/Users/migrie/dev/private/OpenConsole/README.md+0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ <[?25h^[[?25h [?25h[?2004h:[?25hq
[?2004l]0;[?2004lMicrosoft Windows [Version 10.0.18936.1001]
(c) 2019 Microsoft Corporation. All rights reserved.

[11:54:25.95]>c:\Users\migrie\dev\private\OpenConsole>
[1] [dev/migrie/f/passthrough-2019] migrie@MIGRIE-SURFBOOK>wsl.exe
zadjii@migrie-surfbook:/mnt/c/Users/migrie/dev/private/OpenConsole$ vi README.md 
zadjii@migrie-surfbook:/mnt/c/Users/migrie/dev/private/OpenConsole$ 






















]0;zadjii@migrie-surfbook: /mnt/c/Users/migrie/dev/private/OpenConsole[?25h

273
conpty001.txt Normal file
View file

@ -0,0 +1,273 @@
Microsoft Windows [Version 10.0.18936.1001]]0;C:\WINDOWS\system32\cmd.exe[?25h
(c) 2019 Microsoft Corporation. All rights reserved.

[12:00:25.93]>c:\Users\migrie\dev\private\OpenConsole> 
[1] [dev/migrie/f/passthrough-2019] migrie@MIGRIE-SURFBOOK>wsl.exe
]0;C:\WINDOWS\system32\cmd.exe - wsl.exezadjii@migrie-surfbook:/mnt/c/Users/migrie/dev/private/OpenConsole$ ]0;zadjii@migrie-surfbook: /mnt/c/Users/migrie/dev/private/OpenConsolevi README.md
[?2004h[?2004h




























[?25h"README.md" 177L, 11259C[?25h[?2004l[?2004h[?25h[?2004l[?2004h▽[?25h [?25h[>c]10;?]11;? README.md  ◀◀ buffers 
1 # Welcome\! 
2 #### This repository contains the source code for:
3 
4  * Windows Terminal
5  * The Windows console host (conhost.exe)
6  * Components shared between the two projects
7  * ColorTool
8  *  8  * Sample projects that show how to consume the Window
s Console APIs
9  
10 #### Other related repositories include:
11  * Console API Documentation
12 
13 ### Build Status
14 
15 Project|Build Status
16 ---|---
17 Terminal|Build Status 17 Terminal|Build Status

18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004l[?2004h[?2004h
NORMAL ▶ ⎇ dev/migrie/f/passthrough-2019 ▶ < markdown ◀ [unix] ◀ 1,397 words « 3% ␊ 6/177 ㏑ : 46 ◀ Ξ [9]trailing ◀]0;/mnt/c/Users/migrie/dev/private/OpenConsole/README.md+0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ <[?25h~@k[?25h[ColorTool](https://github.com/Microsoft/Terminal/tree/master/src/tools/ColorTool)Sample projects that show how to consume the Windownsole APIs
Other related repositories include:Console API Documentation
Build Status
ect|Build Status---inal|Build Status
rTool|

rminal & Console Overview
se take a few minutes to review the overview below before diving into the code:
indows Terminal▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 3% ␊ 7/177 ㏑ : 46 ◀ Ξ [9]trmd" 177L, 11259C[?25h~@k[?25h 7  * ColorTool
8  * [Sample projects](https://github.com/Microsoft/Terminal/tree/master/samples) that show how to consume the Window
s Console APIs
9  
10 #### Other related repositories include:
11  * Console API Documentation
12 
13 ### Build Status
14 
15 Project|Build Status
16 ---|---
17 Terminal|Build Status

18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal
NORMAL ▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 4% ␊ 8/177 ㏑ : 46 ◀ Ξ [9]trailing ◀
"README.md" 177L, 11259C[?25h~@k[?25h 8  * Sample projects that show how to consume the Window
s Console APIs
9  
10 #### Other related repositories include:
11  * Console API Documentation
12 
13 ### Build Status
14 
15 Project|Build Status
16 ---|---
17 Terminal|Build Status

18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal
NORMAL ▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 5% ␊ 9/177 ㏑ : 2 ◀ Ξ [9]trailing ◀
"README.md" 177L, 11259C[?25h~@k[?25h10/177 ㏑ : 40 ◀ Ξ [9]tr[?25h~@k[?25h[Console API Documentation](https://github.com/MicrosoftDocs/Console-Docs)
Build Status
ect|Build Status---inal|Build Status
rTool|

rminal & Console Overview
se take a few minutes to review the overview below before diving into the code:
indows Terminal▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 6% ␊ 11/177 ㏑ : 46 ◀ Ξ [9]trmd" 177L, 11259C[?25h~@k[?25hConsole API Documentation
Build Status
ect|Build Status---inal|Build Status
rTool|

rminal & Console Overview
se take a few minutes to review the overview below before diving into the code:
indows Terminal▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 6% ␊ 12/177 ㏑ : 1 ◀ Ξ [9]trmd" 177L, 11259C[?25h~@k[?25h7% ␊ 13/177 ㏑ : 16 ◀ Ξ [9]tr[?25h~@k[?25h4/177 ㏑ : 1 ◀ Ξ [9]tr[?25h~@k[?25h8% ␊ 15/177 ㏑ : 20 ◀ Ξ [9]tr[?25h~@k[?25h9% ␊ 16/177 ㏑ : 7 ◀ Ξ [9]tr[?25h~@k[?25h 17 Terminal|[![Build Status](https://dev.azure.com/ms/Terminal/_apis/build/status/Terminal%20CI?branchName=master)](htt
ps://dev.azure.com/ms/Terminal/_build?definitionId=136)
18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal
NORMAL ▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 9% ␊ 17/177 ㏑ : 46 ◀ Ξ [9]trailing ◀
"README.md" 177L, 11259C[?25h~@k[?25h 17 Terminal|Build Status

18 ColorTool|![](https://microsoft.visualstudio.com/_apis/public/build/definitions/c93e867a-8815-43c1-92c4-e7dd5404f1e1
/17023/badge)
19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal
NORMAL ▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 10% ␊ 18/177 ㏑ : 46 ◀ Ξ [9]trailing ◀
"README.md" 177L, 11259C[?25h~@k[?25h 18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal
NORMAL ▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 10% ␊ 19/177 ㏑ : 1 ◀ Ξ [9]trailing ◀
"README.md" 177L, 11259C[?25h~@k[?25h1% ␊ 20/177 ㏑ : 29 ◀ Ξ [9]tr[?25h~@k[?25h1/177 ㏑ : 1 ◀ Ξ [9]tr[?25h~@k[?25h 2 #### This repository contains the source code for:
3 
4  * Windows Terminal
5  * The Windows console host (conhost.exe)
6  * Components shared between the two projects
7  * ColorTool
8  * Sample projects that show how to consume the Window
s Console APIs
9  
10 #### Other related repositories include:
11  * Console API Documentation
12 
13 ### Build Status
14 
15 Project|Build Status
16 ---|---
17 Terminal|Build Status

18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal
25 
NORMAL ▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 12% ␊ 22/177 ㏑ : 46 ◀ Ξ [9]trailing ◀
[?25h~@k[?25h 5  * The Windows console host (conhost.exe)
6  * Components shared between the two projects
7  * ColorTool
8  * Sample projects that show how to consume the Window
s Console APIs
9  
10 #### Other related repositories include:
11  * Console API Documentation
12 
13 ### Build Status
14 
15 Project|Build Status
16 ---|---
17 Terminal|Build Status

18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal
25 
26 Windows Terminal is a new, modern, feature-rich, productive terminal application for command-line users. It includes
 many of the features most frequently requested by the Windows command-line community including support for tabs, ri
ch text, globalization, configurability, theming & styling, and more.
NORMAL ▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ < ◀ [unix] ◀ 1,397 words « 12% ␊ 23/177 ㏑ : 1 ◀ Ξ [9]trailing ◀
[?25h~@k[?25h3% ␊ 24/177 ㏑ : 19 ◀ Ξ [9]tr[?25h◀ [unix] ◀ 1,397 words « 13% ␊ 24/177 ㏑ : 19 ◀ Ξ [64[?25h~@k[?25h 1 # Welcome\! 
2 #### This repository contains the source code for:
3 
4  * Windows Terminal
5  * The Windows console host (conhost.exe)
6  * Components shared between the two projects
7  * ColorTool
8  * Sample projects that show how to consume the Window
s Console APIs
9  
10 #### Other related repositories include:
11  * Console API Documentation
12 
13 ### Build Status
14 
15 Project|Build Status
16 ---|---
17 Terminal|Build Status

18 ColorTool|

19 
20 # Terminal & Console Overview
21 
22 Please take a few minutes to review the overview below before diving into the code:
23 
24 ## Windows Terminal
NORMAL ▶ +0 ~0 -0 ⎇ dev/migrie/f/passthrough-2019 ▶ <◀ [unix] ◀ 1,397 words « 3% ␊ 6/177 ㏑ : 3 ◀ Ξ [64]trailing ◀
[?25h^[[?25h [?25h[?2004h:[?25hq [?2004l]0;[?2004lMicrosoft Windows [Version 10.0.18936.1001]
(c) 2019 Microsoft Corporation. All rights reserved.

[12:00:25.93]>c:\Users\migrie\dev\private\OpenConsole>
[1] [dev/migrie/f/passthrough-2019] migrie@MIGRIE-SURFBOOK>wsl.exe
zadjii@migrie-surfbook:/mnt/c/Users/migrie/dev/private/OpenConsole$ vi README.md 
zadjii@migrie-surfbook:/mnt/c/Users/migrie/dev/private/OpenConsole$ 






















]0;zadjii@migrie-surfbook: /mnt/c/Users/migrie/dev/private/OpenConsole[?25h

9
passthough.txt Normal file

File diff suppressed because one or more lines are too long

38
passthrough001.txt Normal file

File diff suppressed because one or more lines are too long

View file

@ -77,7 +77,28 @@ VtInputThread::VtInputThread(_In_ wil::unique_hfile hPipe,
{
return S_FALSE;
}
_pInputStateMachine->ProcessString(pwsSequence.get(), cchSequence);
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
if (gci.GetVtIo()->IsInPassthroughMode())
{
try
{
std::deque<std::unique_ptr<IInputEvent>> inputEvents;
for (size_t i = 0; i < cchSequence; i++)
{
inputEvents.push_back(std::make_unique<KeyEvent>(true, 1ui16, 0ui16, 0ui16, pwsSequence[i], 0));
}
gci.GetActiveInputBuffer()->Write(inputEvents);
}
catch (...)
{
LOG_HR(wil::ResultFromCaughtException());
}
}
else
{
_pInputStateMachine->ProcessString(pwsSequence.get(), cchSequence);
}
}
CATCH_RETURN();

View file

@ -397,3 +397,18 @@ void VtIo::_ShutdownIfNeeded()
ServiceLocator::RundownAndExit(ERROR_BROKEN_PIPE);
}
}
void VtIo::SetPassthroughMode(const bool enable)
{
_pVtRenderEngine->SetPassthroughMode(enable);
}
bool VtIo::IsInPassthroughMode()
{
return _pVtRenderEngine->IsInPassthroughMode();
}
void VtIo::PassthroughString(std::wstring_view view)
{
std::wstring wstr{ view };
// LOG_IF_FAILED(_pVtRenderEngine->WriteTerminalW(wstr));
_pVtRenderEngine->PassthroughString(wstr);
}

View file

@ -36,6 +36,10 @@ namespace Microsoft::Console::VirtualTerminal
void CloseInput() override;
void CloseOutput() override;
void SetPassthroughMode(const bool enable);
void PassthroughString(std::wstring_view view);
bool IsInPassthroughMode();
private:
// After CreateIoHandlers is called, these will be invalid.
wil::unique_hfile _hInput;

View file

@ -941,6 +941,17 @@ using Microsoft::Console::VirtualTerminal::StateMachine;
const DWORD dwFlags,
_Inout_opt_ PSHORT const psScrollY)
{
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
if (gci.IsInVtIoMode() && gci.GetVtIo()->IsInPassthroughMode())
// if (WI_IsFlagSet(screenInfo.OutputMode, ENABLE_PASSTHROUGH_MODE))
{
const size_t BufferSize = *pcb;
const size_t cch = BufferSize / sizeof(WCHAR);
gci.GetVtIo()->PassthroughString({ pwchRealUnicode, cch });
// *pcb += BufferSize;
// return STATUS_SUCCESS;
}
if (!WI_IsFlagSet(screenInfo.OutputMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING) ||
!WI_IsFlagSet(screenInfo.OutputMode, ENABLE_PROCESSED_OUTPUT))
{

View file

@ -26,7 +26,7 @@
#define VALID_TEXT_ATTRIBUTES (FG_ATTRS | BG_ATTRS | META_ATTRS)
#define INPUT_MODES (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT | ENABLE_VIRTUAL_TERMINAL_INPUT)
#define OUTPUT_MODES (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN | ENABLE_LVB_GRID_WORLDWIDE)
#define OUTPUT_MODES (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN | ENABLE_LVB_GRID_WORLDWIDE | ENABLE_PASSTHROUGH_MODE)
#define PRIVATE_MODES (ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE | ENABLE_AUTO_POSITION | ENABLE_EXTENDED_FLAGS)
using namespace Microsoft::Console::Types;
@ -394,7 +394,14 @@ void ApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept
SCREEN_INFORMATION& screenInfo = context.GetActiveBuffer();
const DWORD dwOldMode = screenInfo.OutputMode;
const DWORD dwNewMode = mode;
DWORD preprocessNewMode = mode;
if (!gci.IsInVtIoMode() &&
(WI_IsFlagSet(preprocessNewMode, ENABLE_PASSTHROUGH_MODE)))
{
WI_ClearFlag(preprocessNewMode, ENABLE_PASSTHROUGH_MODE);
}
const DWORD dwNewMode = preprocessNewMode;
screenInfo.OutputMode = dwNewMode;
@ -413,6 +420,31 @@ void ApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept
screenInfo.SetDefaultVtTabStops();
}
if (gci.IsInVtIoMode())
{
// if we're moving from passthrough on->off
if (WI_IsFlagClear(dwNewMode, ENABLE_PASSTHROUGH_MODE) &&
WI_IsFlagSet(dwOldMode, ENABLE_PASSTHROUGH_MODE))
{
gci.GetVtIo()->SetPassthroughMode(false);
// Trigger a redaw all, to sync us back up.
ServiceLocator::LocateGlobals().pRender->TriggerRedrawAll();
}
// if we're moving from passthrough off->on
else if (WI_IsFlagSet(dwNewMode, ENABLE_PASSTHROUGH_MODE) &&
WI_IsFlagClear(dwOldMode, ENABLE_PASSTHROUGH_MODE))
{
// DebugBreak();
// Trigger a frame NOW, to flush any state since the last frame
RECT dummy{ 0 };
// ServiceLocator::LocateGlobals().pRender->TriggerSystemRedraw(&dummy);
// ServiceLocator::LocateGlobals().pRender->WaitForPaintCompletion(1000);
LOG_IF_FAILED(ServiceLocator::LocateGlobals().pRender->PaintFrame());
gci.GetVtIo()->SetPassthroughMode(true);
ServiceLocator::LocateGlobals().pRender->WaitForPaintCompletion(1000);
}
}
gci.SetVirtTermLevel(WI_IsFlagSet(dwNewMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING) ? 1 : 0);
gci.SetAutomaticReturnOnNewline(WI_IsFlagSet(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN) ? false : true);
gci.SetGridRenderingAllowedWorldwide(WI_IsFlagSet(screenInfo.OutputMode, ENABLE_LVB_GRID_WORLDWIDE));

View file

@ -71,6 +71,9 @@ Revision History:
#define CONSOLE_SUSPENDED (CONSOLE_OUTPUT_SUSPENDED)
// clang-format on
// ENABLE_LVB_GRID_WORLDWIDE is 0x0010
#define ENABLE_PASSTHROUGH_MODE 0x0020
class COOKED_READ_DATA;
class CommandHistory;

View file

@ -507,6 +507,11 @@ void Renderer::WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs)
_pThread->WaitForPaintCompletionAndDisable(dwTimeoutMs);
}
void Renderer::WaitForPaintCompletion(const DWORD dwTimeoutMs)
{
_pThread->WaitForPaintCompletion(dwTimeoutMs);
}
// Routine Description:
// - Paint helper to fill in the background color of the invalid area within the frame.
// Arguments:

View file

@ -73,6 +73,7 @@ namespace Microsoft::Console::Render
void EnablePainting() override;
void WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs) override;
void WaitForPaintCompletion(const DWORD dwTimeoutMs) override;
void AddRenderEngine(_In_ IRenderEngine* const pEngine) override;

View file

@ -242,3 +242,8 @@ void RenderThread::WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs)
ResetEvent(_hPaintEnabledEvent);
WaitForSingleObject(_hPaintCompletedEvent, dwTimeoutMs);
}
void RenderThread::WaitForPaintCompletion(const DWORD dwTimeoutMs)
{
WaitForSingleObject(_hPaintCompletedEvent, dwTimeoutMs);
}

View file

@ -31,6 +31,7 @@ namespace Microsoft::Console::Render
void EnablePainting() override;
void WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs) override;
void WaitForPaintCompletion(const DWORD dwTimeoutMs) override;
private:
static DWORD WINAPI s_ThreadProc(_In_ LPVOID lpParameter);

View file

@ -22,6 +22,7 @@ namespace Microsoft::Console::Render
virtual void NotifyPaint() = 0;
virtual void EnablePainting() = 0;
virtual void WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs) = 0;
virtual void WaitForPaintCompletion(const DWORD dwTimeoutMs) = 0;
};
inline Microsoft::Console::Render::IRenderThread::~IRenderThread(){};

View file

@ -54,6 +54,7 @@ namespace Microsoft::Console::Render
virtual void EnablePainting() = 0;
virtual void WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs) = 0;
virtual void WaitForPaintCompletion(const DWORD dwTimeoutMs) = 0;
virtual void AddRenderEngine(_In_ IRenderEngine* const pEngine) = 0;
};

View file

@ -40,7 +40,11 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe,
// the pipe.
[[nodiscard]] HRESULT XtermEngine::StartPaint() noexcept
{
RETURN_IF_FAILED(VtEngine::StartPaint());
const auto hr = VtEngine::StartPaint();
if (hr == S_FALSE)
{
return hr;
}
_trace.TraceLastText(_lastText);

View file

@ -24,6 +24,10 @@ using namespace Microsoft::Console::Types;
{
return S_FALSE;
}
if (_passthroughMode)
{
return S_FALSE;
}
// If there's nothing to do, quick return
bool somethingToDo = _fInvalidRectUsed ||

View file

@ -417,3 +417,19 @@ HRESULT VtEngine::RequestCursor() noexcept
RETURN_IF_FAILED(_Flush());
return S_OK;
}
void VtEngine::SetPassthroughMode(const bool enable)
{
_passthroughMode = enable;
}
void VtEngine::PassthroughString(const std::wstring& wstr)
{
LOG_IF_FAILED(WriteTerminalW(wstr));
LOG_IF_FAILED(_Flush());
}
bool VtEngine::IsInPassthroughMode()
{
return _passthroughMode;
}

View file

@ -95,6 +95,10 @@ namespace Microsoft::Console::Render
void SetTerminalOwner(Microsoft::Console::ITerminalOwner* const terminalOwner);
void SetPassthroughMode(const bool enable);
void PassthroughString(const std::wstring& wstr);
bool IsInPassthroughMode();
protected:
wil::unique_hfile _hFile;
std::string _buffer;
@ -133,6 +137,8 @@ namespace Microsoft::Console::Render
Microsoft::Console::VirtualTerminal::RenderTracing _trace;
bool _passthroughMode{ false };
[[nodiscard]] HRESULT _Write(std::string_view const str) noexcept;
[[nodiscard]] HRESULT _WriteFormattedString(const std::string* const pFormat, ...) noexcept;
[[nodiscard]] HRESULT _Flush() noexcept;

View file

@ -2,9 +2,178 @@
// Licensed under the MIT license.
#include <windows.h>
#include <wil\Common.h>
#include <wil\result.h>
#include <wil\resource.h>
#include <wil\wistd_functional.h>
#include <wil\wistd_memory.h>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <conio.h>
#include <deque>
#include <memory>
#include <vector>
#include <string>
#include <sstream>
#include <assert.h>
#define ENABLE_PASSTHROUGH_MODE 0x0020
std::string csi(std::string seq)
{
std::string fullSeq = "\x1b[";
fullSeq += seq;
return fullSeq;
}
std::string osc(std::string seq)
{
std::string fullSeq = "\x1b]";
fullSeq += seq;
fullSeq += "\x7";
return fullSeq;
}
void testOutput()
{
wprintf(L"Attempting to start passthrough mode...\n");
auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode = 0;
THROW_LAST_ERROR_IF(!GetConsoleMode(hOut, &dwMode));
wprintf(L"Original Mode: 0x%x\n", dwMode);
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
dwMode |= DISABLE_NEWLINE_AUTO_RETURN;
dwMode |= ENABLE_PASSTHROUGH_MODE;
wprintf(L"Requested Mode: 0x%x\n", dwMode);
THROW_LAST_ERROR_IF(!SetConsoleMode(hOut, dwMode));
DWORD roundtripMode = 0;
THROW_LAST_ERROR_IF(!GetConsoleMode(hOut, &roundtripMode));
wprintf(L"Rountripped Mode: 0x%x\n", dwMode);
if (roundtripMode != dwMode)
{
wprintf(L"Mode did not rountrip\n");
}
else
{
wprintf(L"Mode rountripped successfully\n");
}
wprintf(L"Press a key to continue\n");
_getch();
wprintf(L"We're going to write some VT straight to the terminal\n");
printf(csi("31m").c_str());
printf(osc("0;Title:foo").c_str());
wprintf(L"Press a key to continue\n");
_getch();
printf(csi("0m").c_str());
wprintf(L"Time for something more complicated...\n");
Sleep(500);
printf(csi("2;1H").c_str());
printf(csi("44m").c_str());
printf(csi("K").c_str());
Sleep(500);
printf(csi("9;1H").c_str());
printf(csi("46m").c_str());
printf(csi("K").c_str());
Sleep(500);
printf(csi("3;8r").c_str());
printf(csi("3;1H").c_str());
printf(csi("0m").c_str());
Sleep(500);
for (int i = 0; i < 10; i++)
{
wprintf(L"Print in the margins %d\n", i);
Sleep(500);
}
printf(csi("r").c_str());
wprintf(L"Press a key to continue\n");
_getch();
}
void launchChild(int argc, WCHAR* argv[])
{
auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);
auto hIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD dwMode = 0;
THROW_LAST_ERROR_IF(!GetConsoleMode(hOut, &dwMode));
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
dwMode |= DISABLE_NEWLINE_AUTO_RETURN;
dwMode |= ENABLE_PASSTHROUGH_MODE;
THROW_LAST_ERROR_IF(!SetConsoleMode(hOut, dwMode));
DWORD dwInMode = 0;
GetConsoleMode(hIn, &dwInMode);
dwInMode = ENABLE_VIRTUAL_TERMINAL_INPUT;
SetConsoleMode(hIn, dwInMode);
std::wstring commandline = L"";
for (int i = 0; i < argc; i++)
{
commandline += (argv[i]);
commandline += (L" ");
}
std::unique_ptr<wchar_t[]> mutableCommandline = std::make_unique<wchar_t[]>(commandline.length() + 1);
THROW_IF_NULL_ALLOC(mutableCommandline);
HRESULT hr = StringCchCopy(mutableCommandline.get(), commandline.length() + 1, commandline.c_str());
THROW_IF_FAILED(hr);
STARTUPINFO si = { 0 };
si.cb = sizeof(STARTUPINFOW);
PROCESS_INFORMATION _piClient;
bool fSuccess = !!CreateProcessW(
nullptr,
mutableCommandline.get(),
nullptr, // lpProcessAttributes
nullptr, // lpThreadAttributes
true, // bInheritHandles
false, // dwCreationFlags
nullptr, // lpEnvironment
nullptr, // lpCurrentDirectory
&si, // lpStartupInfo
&_piClient // lpProcessInformation
);
THROW_LAST_ERROR_IF(!fSuccess);
// Sleep(10000);
WaitForSingleObject(_piClient.hProcess, INFINITE);
}
// This wmain exists for help in writing scratch programs while debugging.
int __cdecl wmain(int /*argc*/, WCHAR* /*argv[]*/)
int __cdecl wmain(int argc, WCHAR* argv[])
{
for (int i = 0; i < argc; i++)
{
wprintf(argv[i]);
wprintf(L" ");
}
if (argc > 1)
{
std::wstring arg1 = argv[1];
if (arg1 == L"--test")
{
testOutput();
}
else if (arg1 == L"--")
{
launchChild(argc - 2, &argv[2]);
}
}
return 0;
}

5
tools/bzcon.cmd Normal file
View file

@ -0,0 +1,5 @@
@echo off
"%msbuild%" Openconsole.sln /t:Conhost\Host_EXE /m /p:Configuration=Debug /p:Platform=%ARCH%
:eof

24
tools/scratch.cmd Normal file
View file

@ -0,0 +1,24 @@
@echo off
rem openvt - launch the vtterm binary
rem Runs the VtPipeTerm.exe binary generated by the build in the debug directory.
rem Passes any args along.
setlocal
set _last_build=%OPENCON%\bin\%ARCH%\%_LAST_BUILD_CONF%
if not exist %_last_build%\scratch.exe (
echo Could not locate the scratch.exe in %_last_build%. Double check that it has been built and try again.
goto :eof
)
set _r=%random%
set copy_dir=OpenConsole\%_r%
rem Generate a unique name, so that we can debug multiple revisions of the binary at the same time if needed.
(xcopy /Y %_last_build%\OpenConsole.exe %TEMP%\%copy_dir%\conhost.exe*) > nul
(xcopy /Y %_last_build%\console.dll %TEMP%\%copy_dir%\console.dll*) > nul
(xcopy /Y %_last_build%\scratch.exe %TEMP%\%copy_dir%\scratch.exe*) > nul
echo Launching %TEMP%\%copy_dir%\scratch.exe...
%TEMP%\%copy_dir%\scratch.exe %*