-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[WIP] feat(unstable): add Deno.openPty() #14535
Conversation
@kitsonk Any feedback to the current structure? |
To be inline with the new declare namespace Deno {
interface PtyChild {
readonly readable: ReadableStream<Uint8Array>;
readonly writable: WritableStream<Uint8Array>;
readonly pid: number;
readonly status: Promise<ChildStatus>;
kill(signo: Signal): void;
size(): ConsoleSize;
resize(consoleSize: ConsoleSize): void;
}
interface ConsoleSize {
columns: number;
rows: number;
}
interface SpawnPtyOptions extends ConsoleSize {
args: string[];
clearEnv?: boolean;
env?: Record<string, string>;
}
/** Requires --allow-run */
function spawnPty(command: string | URL, options: SpawnPtyOptions): PtyChild;
} |
Agreed! @nayeemrmn
|
A way to poll for the return code, yeah that was a discussion with |
I see, I guess there's a point there! Let's keep the |
Signed-off-by: James Bradlee <[email protected]>
This reverts commit 454836f.
Signed-off-by: James Bradlee <[email protected]>
Signed-off-by: James Bradlee <[email protected]>
|
runtime/Cargo.toml
Outdated
@@ -82,6 +82,7 @@ sys-info = "0.9.1" | |||
termcolor = "1.1.3" | |||
tokio = { version = "1.17", features = ["full"] } | |||
uuid = { version = "1.0.0", features = ["v4"] } | |||
portable-pty = "0.7.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could instead refactor and reuse the code in test_util/src/pty.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could instead refactor and reuse the code in test_util/src/pty.rs
Maybe, but it needs to be async on the input and output, so some tokio magic would have to be used. I'll take a look and see what I find out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems doable, I'm gonna try to get some work done on it, but most likely won't really get to it until next week.
Signed-off-by: James Bradlee <[email protected]>
Signed-off-by: James Bradlee <[email protected]>
Signed-off-by: James Bradlee <[email protected]>
Fixes #3994.
Todos:
pty
)openpty(size)
- Open/fork a PTY.write(buf)
- Synchronously write to the PTYs input.read(buf)
- Synchronously read from the PTYs output.close()
- Close and dispose of the PTY.resize(size)
- Set a new size on the pty.size()
- Get the current size known to the kernel. (Already taken care of by Deno's tty op).openpty(size)
- Open/fork a pseudoconsole.write(buf)
- Synchronously Write to the console.read(buf)
- Synchronously Read from the console.close()
- Close and dispose of the pseudoconsole.resize(size)
- Set a new size on the pseudoconsole.size()
- Get the current size known to the kernel. (Already taken care of by Deno's tty op).Deno.consoleSize(rid)
Deno.isatty(rid)
Deno.setRaw(rid, state, options?)
op_pty_open({size}) -> rid
op_pty_resize({rid, size})
op_pty_open({size}) -> rid
op_pty_resize({rid, size})
spawn.rs
should support a pty property to spawn processes onto the PTY.Pty
class.rid
getter.resize()
.close()
aliased toDeno.close(this.#rid)
.consoleSize()
aliased toDeno.consoleSize(this.#rid)
.isatty()
aliased toDeno.isatty(this.#rid)
.setRaw(state, options?)
aliased toDeno.setRaw(this.#rid, state, options)
Deno.consoleSize(rid)
- Make return type its own interface.interface ConsoleSize {rows, columns}
...Pty
interface.pty?
option inSpawnOptions
interface.openPty(size)
function.op_spawn_sync
op_spawn_child
Interface(s):