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

Bring back clear impl #713

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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