@@ -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}
0 commit comments