Skip to content

Commit

Permalink
Merge pull request microsoft#713 from microsoft/tyriar/711
Browse files Browse the repository at this point in the history
Bring back clear impl
  • Loading branch information
Tyriar authored Sep 27, 2024
2 parents cb94da7 + 59771c0 commit 796e11e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface IConptyNative {
startProcess(file: string, cols: number, rows: number, debug: boolean, pipeName: string, conptyInheritCursor: boolean, useConptyDll: boolean): IConptyProcess;
connect(ptyId: number, commandLine: string, cwd: string, env: string[], onExitCallback: (exitCode: number) => void): { pid: number };
resize(ptyId: number, cols: number, rows: number, useConptyDll: boolean): void;
clear(ptyId: number): void;
clear(ptyId: number, useConptyDll: boolean): void;
kill(ptyId: number, useConptyDll: boolean): void;
}

Expand Down
49 changes: 28 additions & 21 deletions src/win/conpty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,29 +479,36 @@ static Napi::Value PtyClear(const Napi::CallbackInfo& info) {
Napi::Env env(info.Env());
Napi::HandleScope scope(env);

if (info.Length() != 1 ||
!info[0].IsNumber()) {
throw Napi::Error::New(env, "Usage: pty.clear(id)");
if (info.Length() != 2 ||
!info[0].IsNumber() ||
!info[1].IsBoolean()) {
throw Napi::Error::New(env, "Usage: pty.clear(id, useConptyDll)");
}

int id = info[0].As<Napi::Number>().Int32Value();
const bool useConptyDll = info[1].As<Napi::Boolean>().Value();

// This API is only supported for conpty.dll as it was introduced in a later version of Windows.
// We could hook it up to point at >= a version of Windows only, but the future is conpty.dll
// anyway.
if (!useConptyDll) {
return env.Undefined();
}

// int id = info[0].As<Napi::Number>().Int32Value();

// const pty_baton* handle = get_pty_baton(id);

// if (handle != nullptr) {
// HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0);
// bool fLoadedDll = hLibrary != nullptr;
// if (fLoadedDll)
// {
// PFNCLEARPSEUDOCONSOLE const pfnClearPseudoConsole = (PFNCLEARPSEUDOCONSOLE)GetProcAddress(
// (HMODULE)hLibrary,
// useConptyDll ? "ConptyClearPseudoConsole" : "ClearPseudoConsole");
// if (pfnClearPseudoConsole)
// {
// pfnClearPseudoConsole(handle->hpc);
// }
// }
// }
const pty_baton* handle = get_pty_baton(id);

if (handle != nullptr) {
HANDLE hLibrary = LoadConptyDll(info, useConptyDll);
bool fLoadedDll = hLibrary != nullptr;
if (fLoadedDll)
{
PFNCLEARPSEUDOCONSOLE const pfnClearPseudoConsole = (PFNCLEARPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ConptyClearPseudoConsole");
if (pfnClearPseudoConsole)
{
pfnClearPseudoConsole(handle->hpc);
}
}
}

return env.Undefined();
}
Expand Down
2 changes: 1 addition & 1 deletion src/windowsPtyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class WindowsPtyAgent {

public clear(): void {
if (this._useConpty) {
(this._ptyNative as IConptyNative).clear(this._pty);
(this._ptyNative as IConptyNative).clear(this._pty, this._useConptyDll);
}
}

Expand Down

0 comments on commit 796e11e

Please sign in to comment.