-
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
Closed
+379
−14
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c1d839
Open PR
imjamesb 454836f
Cargo.lock
imjamesb 0994b82
Revert "Cargo.lock"
imjamesb bf8b039
added op_pty_open
imjamesb bff202e
added op_pty_wait, note that it is currently not working
imjamesb 531e479
Remove portable-pty
imjamesb c438a93
added features
imjamesb 72b4847
help not needed on unix close
imjamesb 17095d2
Merge branch 'main' into pty
imjamesb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.