denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.94k stars 5.39k forks source link

Support a pty interface #3994

Open kitsonk opened 4 years ago

kitsonk commented 4 years ago

Deno should support forking of pty interfaces (psuedo terminals) which would allow Deno workloads to be able to "pretend" to be a terminal, which can allow Deno workloads to be a terminal emulator or allow certain programs to think a Deno workload is an terminal to send it control sequences.

Node.js Prior art: https://github.com/microsoft/node-pty (which is used to provide the terminal interface in VSCode) Likely this crate can be used: https://docs.rs/portable-pty/0.2.0/portable_pty/ which provides Linux/Mac and Windows support.

cc/ @Lerc

bnoordhuis commented 4 years ago

https://github.com/libuv/libuv/issues/2640 might be instructive. Notably, pty emulation on Windows < 10 is highly arcane - it involves setting up a console, positioning it off-screen and scraping it with an agent process. Yes.

The crate you link to offloads that to winpty but it requires that winpty.dll be installed separately. Not a great out-of-the-box experience.

kitsonk commented 4 years ago

@bnoordhuis actually it uses conpty which is included in Windows 10+, it is only pre-Windows 10 where winpty is required (just like node-pty).

bnoordhuis commented 4 years ago

That's what I said, didn't I? Windows < 10.

As a data point: Windows 7 + 8 still makes up 55% of Node's Windows user base, if I read the download stats right.

musm commented 4 years ago

@bnoordhuis Is that really the percentage? So 55% of Deno''s Windows user base is using an unsupported OS that has stopped receiving technical support for any issues, software updates, and security updates or fixes? That's a bit unsettling.

IMO it makes no sense to keep supporting Windows 7-8 when MSFT itself has dropped support. Using conpty for child processes would help alleviate several important issues in my case when launching child processes.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

kt3k commented 11 months ago

Subprocess API design has been updated to Deno.Command in https://github.com/denoland/deno/pull/17628

Probably the API design should be like:

export class Command {
  ...
  spawnPty(options: SpawnPtyOptions): PtyChildProcess;
}

interface ConsoleSize {
  columns: number;
  rows: number;
}

interface SpawnPtyOptions extends ConsoleSize {}

export class PtyChildProcess extends ChildProcess {
  consoleSize(): ConsoleSize;
  resize(size: ConsoleSize): void;
}
kt3k commented 11 months ago

Another note: We have our own pty implementation in test_util/src/pty.rs

kt3k commented 11 months ago

In std, we landed promptSecret, but it's only tested manually by contributors. I think we are now strongly in need of this feature.

rivy commented 1 month ago

FYI, linking a reference to currently in-use rust support code for Deno tests utilizing a PTY ... https://github.com/denoland/deno/blob/2de4faa483982478e9a36ad4ab891a887b4779f1/tests/util/server/src/pty.rs.

It might be useful as a reference if/when this gains some forward momentum.