-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
fix: implement node:tty #20892
Merged
+325
−177
Merged
fix: implement node:tty #20892
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
980fb05
implement node:tty
littledivy eba9e82
Revert lazy stdin streams
littledivy c98a5ab
Fix lint
littledivy 8e8e7e7
Restore stdio on exit
littledivy b871a5a
x
littledivy 3b37419
fix lint windows
littledivy 181cddd
oopsie
littledivy 1496539
Merge branch 'main' into node_tty
littledivy 03cb93b
Merge branch 'main' into node_tty
littledivy cfed35d
windows fixes?
littledivy 2881000
Merge branch 'node_tty' of github.com:littledivy/deno into node_tty
littledivy a268c83
fmt
littledivy bc16899
fix js lint
littledivy 7bf3646
macOS fix?
littledivy 362fe08
maybe fixes really
littledivy 9e3e2a6
fmt
littledivy 4099f2a
implement guessHandleType
littledivy 8a34458
Merge branch 'node_tty' of github.com:littledivy/deno into node_tty
littledivy ad61842
zzz
littledivy 29db367
fixes
littledivy 2308af9
x
littledivy 71bae42
x
littledivy 7c350d3
add some tests
littledivy e9a79cf
fix
littledivy 709b635
x
littledivy 28db64c
x
littledivy 8896c9c
x
littledivy 3d56be1
x
littledivy 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
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
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,84 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { Socket } from "node:net"; | ||
import { ERR_INVALID_FD } from "ext:deno_node/internal/errors.ts"; | ||
import { LibuvStreamWrap } from "ext:deno_node/internal_binding/stream_wrap.ts"; | ||
import { providerType } from "ext:deno_node/internal_binding/async_wrap.ts"; | ||
|
||
const { Error } = globalThis.__bootstrap.primordials; | ||
|
||
// Returns true when the given numeric fd is associated with a TTY and false otherwise. | ||
function isatty(fd) { | ||
if (typeof fd !== "number") { | ||
return false; | ||
} | ||
try { | ||
return Deno.isatty(fd); | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
|
||
class TTY extends LibuvStreamWrap { | ||
constructor(handle) { | ||
super(providerType.TTYWRAP, handle); | ||
} | ||
} | ||
|
||
export class ReadStream extends Socket { | ||
constructor(fd, options) { | ||
if (fd >> 0 !== fd || fd < 0) { | ||
throw new ERR_INVALID_FD(fd); | ||
} | ||
|
||
// We only support `stdin`. | ||
if (fd != 0) throw new Error("Only fd 0 is supported."); | ||
littledivy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const tty = new TTY(Deno.stdin); | ||
super({ | ||
readableHighWaterMark: 0, | ||
handle: tty, | ||
manualStart: true, | ||
...options, | ||
}); | ||
|
||
this.isRaw = false; | ||
this.isTTY = true; | ||
} | ||
|
||
setRawMode(flag) { | ||
flag = !!flag; | ||
this._handle.setRaw(flag); | ||
|
||
this.isRaw = flag; | ||
return this; | ||
} | ||
} | ||
|
||
export class WriteStream extends Socket { | ||
constructor(fd) { | ||
if (fd >> 0 !== fd || fd < 0) { | ||
throw new ERR_INVALID_FD(fd); | ||
} | ||
|
||
// We only support `stdin`, `stdout` and `stderr`. | ||
if (fd > 2) throw new Error("Only fd 0, 1 and 2 are supported."); | ||
|
||
const tty = new TTY( | ||
fd === 0 ? Deno.stdin : (fd === 1 ? Deno.stdout : Deno.stderr), | ||
); | ||
|
||
super({ | ||
readableHighWaterMark: 0, | ||
handle: tty, | ||
manualStart: true, | ||
}); | ||
|
||
const { columns, rows } = Deno.consoleSize(); | ||
this.columns = columns; | ||
this.rows = rows; | ||
} | ||
} | ||
|
||
export { isatty }; | ||
export default { isatty, WriteStream, ReadStream }; |
This file was deleted.
Oops, something went wrong.
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.
cc @bartlomieju @mmastrac
This breaks code in
_streams.mjs
because of the use of Proxy:when its trying to update the eventsCount. I reverted it back to not lazy load the stdin/out/err streams which fixed the issue.