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

[WIP] feat(unstable): add Deno.openPty() #14535

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
106 changes: 106 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

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

Copy link
Contributor Author

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!

Copy link
Contributor Author

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.


[target.'cfg(windows)'.dependencies]
fwdansi = "1.1.0"
Expand Down
69 changes: 69 additions & 0 deletions runtime/js/40_pty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
"use strict";
((window) => {
const core = window.Deno.core;
const { pathFromURL } = window.__bootstrap.util;
const { illegalConstructorKey } = window.__bootstrap.webUtil;
const {
ArrayPrototypeMap,
ObjectEntries,
String,
TypeError,
Uint8Array,
PromiseAll,
} = window.__bootstrap.primordials;
const { readableStreamForRid, writableStreamForRid } =
window.__bootstrap.streamUtils;

class Pty {
#rid;

#pid;
get pid() {
return this.#pid;
}

constructor(key = null, { rid, pid }) {
if (key !== illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}

this.#rid = rid;
this.#pid = pid;

this.readable = readableStreamForRid(rid);
this.writable = writableStreamForRid(rid);

this.success = core.opAsync("op_pty_wait", rid).then((res) => {
console.log(res);
this.#rid = null;
return res;
});
}
}

function openPty(command, {
args = [],
cwd = undefined,
clearEnv = false,
env = {},
rows,
columns,
}) {
const pty = core.opSync("op_pty_open", {
cmd: pathFromURL(command),
args: ArrayPrototypeMap(args, String),
cwd: pathFromURL(cwd),
clearEnv,
env: ObjectEntries(env),
rows,
columns,
});
return new Pty(illegalConstructorKey, pty);
}

window.__bootstrap.pty = {
Pty,
openPty,
};
})(this);
2 changes: 2 additions & 0 deletions runtime/js/90_deno_ns.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,7 @@
spawnChild: __bootstrap.spawn.spawnChild,
spawn: __bootstrap.spawn.spawn,
spawnSync: __bootstrap.spawn.spawnSync,
openPty: __bootstrap.pty.openPty,
Pty: __bootstrap.pty.Pty,
};
})(this);
1 change: 1 addition & 0 deletions runtime/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod io;
pub mod os;
pub mod permissions;
pub mod process;
pub mod pty;
pub mod runtime;
pub mod signal;
pub mod spawn;
Expand Down
Loading