Passthrough input too

This commit is contained in:
Mike Griese 2019-07-19 15:13:46 -05:00
parent 90271426e9
commit 491ec14291
12 changed files with 529 additions and 6 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

@ -402,6 +402,10 @@ 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 };

View file

@ -38,6 +38,7 @@ namespace Microsoft::Console::VirtualTerminal
void SetPassthroughMode(const bool enable);
void PassthroughString(std::wstring_view view);
bool IsInPassthroughMode();
private:
// After CreateIoHandlers is called, these will be invalid.

View file

@ -941,11 +941,12 @@ using Microsoft::Console::VirtualTerminal::StateMachine;
const DWORD dwFlags,
_Inout_opt_ PSHORT const psScrollY)
{
if (WI_IsFlagSet(screenInfo.OutputMode, ENABLE_PASSTHROUGH_MODE))
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);
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
gci.GetVtIo()->PassthroughString({ pwchRealUnicode, cch });
// *pcb += BufferSize;
// return STATUS_SUCCESS;

View file

@ -428,3 +428,8 @@ void VtEngine::PassthroughString(const std::wstring& wstr)
LOG_IF_FAILED(WriteTerminalW(wstr));
LOG_IF_FAILED(_Flush());
}
bool VtEngine::IsInPassthroughMode()
{
return _passthroughMode;
}

View file

@ -97,6 +97,7 @@ namespace Microsoft::Console::Render
void SetPassthroughMode(const bool enable);
void PassthroughString(const std::wstring& wstr);
bool IsInPassthroughMode();
protected:
wil::unique_hfile _hFile;

View file

@ -34,8 +34,7 @@ std::string osc(std::string seq)
return fullSeq;
}
// This wmain exists for help in writing scratch programs while debugging.
int __cdecl wmain(int /*argc*/, WCHAR* /*argv[]*/)
void testOutput()
{
wprintf(L"Attempting to start passthrough mode...\n");
auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);
@ -101,6 +100,80 @@ int __cdecl wmain(int /*argc*/, WCHAR* /*argv[]*/)
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[])
{
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;
}

View file

@ -21,4 +21,4 @@ rem Generate a unique name, so that we can debug multiple revisions of the binar
(xcopy /Y %_last_build%\scratch.exe %TEMP%\%copy_dir%\scratch.exe*) > nul
echo Launching %TEMP%\%copy_dir%\scratch.exe...
%TEMP%\%copy_dir%\scratch.exe
%TEMP%\%copy_dir%\scratch.exe %*