Skip to content

Commit 59771c0

Browse files
committed
Bring back clear impl
Fixes microsoft#711
1 parent cb94da7 commit 59771c0

3 files changed

Lines changed: 30 additions & 23 deletions

File tree

src/native.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface IConptyNative {
66
startProcess(file: string, cols: number, rows: number, debug: boolean, pipeName: string, conptyInheritCursor: boolean, useConptyDll: boolean): IConptyProcess;
77
connect(ptyId: number, commandLine: string, cwd: string, env: string[], onExitCallback: (exitCode: number) => void): { pid: number };
88
resize(ptyId: number, cols: number, rows: number, useConptyDll: boolean): void;
9-
clear(ptyId: number): void;
9+
clear(ptyId: number, useConptyDll: boolean): void;
1010
kill(ptyId: number, useConptyDll: boolean): void;
1111
}
1212

src/win/conpty.cc

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -479,29 +479,36 @@ static Napi::Value PtyClear(const Napi::CallbackInfo& info) {
479479
Napi::Env env(info.Env());
480480
Napi::HandleScope scope(env);
481481

482-
if (info.Length() != 1 ||
483-
!info[0].IsNumber()) {
484-
throw Napi::Error::New(env, "Usage: pty.clear(id)");
482+
if (info.Length() != 2 ||
483+
!info[0].IsNumber() ||
484+
!info[1].IsBoolean()) {
485+
throw Napi::Error::New(env, "Usage: pty.clear(id, useConptyDll)");
486+
}
487+
488+
int id = info[0].As<Napi::Number>().Int32Value();
489+
const bool useConptyDll = info[1].As<Napi::Boolean>().Value();
490+
491+
// This API is only supported for conpty.dll as it was introduced in a later version of Windows.
492+
// We could hook it up to point at >= a version of Windows only, but the future is conpty.dll
493+
// anyway.
494+
if (!useConptyDll) {
495+
return env.Undefined();
485496
}
486497

487-
// int id = info[0].As<Napi::Number>().Int32Value();
488-
489-
// const pty_baton* handle = get_pty_baton(id);
490-
491-
// if (handle != nullptr) {
492-
// HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0);
493-
// bool fLoadedDll = hLibrary != nullptr;
494-
// if (fLoadedDll)
495-
// {
496-
// PFNCLEARPSEUDOCONSOLE const pfnClearPseudoConsole = (PFNCLEARPSEUDOCONSOLE)GetProcAddress(
497-
// (HMODULE)hLibrary,
498-
// useConptyDll ? "ConptyClearPseudoConsole" : "ClearPseudoConsole");
499-
// if (pfnClearPseudoConsole)
500-
// {
501-
// pfnClearPseudoConsole(handle->hpc);
502-
// }
503-
// }
504-
// }
498+
const pty_baton* handle = get_pty_baton(id);
499+
500+
if (handle != nullptr) {
501+
HANDLE hLibrary = LoadConptyDll(info, useConptyDll);
502+
bool fLoadedDll = hLibrary != nullptr;
503+
if (fLoadedDll)
504+
{
505+
PFNCLEARPSEUDOCONSOLE const pfnClearPseudoConsole = (PFNCLEARPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ConptyClearPseudoConsole");
506+
if (pfnClearPseudoConsole)
507+
{
508+
pfnClearPseudoConsole(handle->hpc);
509+
}
510+
}
511+
}
505512

506513
return env.Undefined();
507514
}

src/windowsPtyAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class WindowsPtyAgent {
153153

154154
public clear(): void {
155155
if (this._useConpty) {
156-
(this._ptyNative as IConptyNative).clear(this._pty);
156+
(this._ptyNative as IConptyNative).clear(this._pty, this._useConptyDll);
157157
}
158158
}
159159

0 commit comments

Comments
 (0)