static NAN_METHOD()

in src/win/conpty.cc [386:418]


static NAN_METHOD(PtyResize) {
  Nan::HandleScope scope;

  if (info.Length() != 3 ||
      !info[0]->IsNumber() ||
      !info[1]->IsNumber() ||
      !info[2]->IsNumber()) {
    Nan::ThrowError("Usage: pty.resize(id, cols, rows)");
    return;
  }

  int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust();
  SHORT cols = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust();
  SHORT rows = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust();

  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)
    {
      PFNRESIZEPSEUDOCONSOLE const pfnResizePseudoConsole = (PFNRESIZEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ResizePseudoConsole");
      if (pfnResizePseudoConsole)
      {
        COORD size = {cols, rows};
        pfnResizePseudoConsole(handle->hpc, size);
      }
    }
  }

  return info.GetReturnValue().SetUndefined();
}