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] tty: Deno.stdin.setRaw(), Option 2 #3958

Open
wants to merge 8 commits into
base: master
from

Conversation

@kevinkassimo
Copy link
Contributor

kevinkassimo commented Feb 11, 2020

Difference from the first option:

  • Deno.setRaw(rid, mode) to turn on/off raw mode
  • Added Deno.isatty(rid) that can test any resources, not just stdin/stdout/stderr (personally prefer deprecating current Deno.isTTY())
Deno.setRaw(0, true);
Deno.setRaw(0, true); // safe

const buf = new Uint8Array(6);
for (let i = 0; i < 6; i++) {
  const nread = await Deno.stdin.read(buf);
  if (nread === Deno.EOF) {
    break;
  } else {
    console.log(`READ ${nread} bytes:`, new TextDecoder().decode(buf.subarray(0, nread)));
  }
}

Deno.setRaw(0, false);
Deno.setRaw(0, false); // safe
@kevinkassimo kevinkassimo force-pushed the kevinkassimo:tty/raw_mode_2 branch 3 times, most recently from 7a553ae to 8776116 Feb 11, 2020
/** An instance of `File` for stdout. */
export const stdout: File;
/** An instance of `File` for stderr. */
export const stderr: File;

This comment has been minimized.

Copy link
@ry

ry Feb 13, 2020

Collaborator

I like the minimality of isatty(rid). Maybe you can do something similar here, instead of defining this new class TTYInput you could just add a new function... something like Deno.setRaw(rid). What do you think?

Additionally can you mark in the JSDOC any new APIs as

/** UNSTABLE: newly added API
  *
  *  Check if a given resource is TTY
  */
export function isatty(rid: number): boolean;

This comment has been minimized.

Copy link
@kevinkassimo

kevinkassimo Feb 13, 2020

Author Contributor

Do you think the original returning a restoration function after calling Deno.setRaw(rid) works here? (In case I want to store the information for restoring without exposing? This would be a pure TS side change, and similar to what I did in the old PR, but without wrapping in a class)

This comment has been minimized.

Copy link
@ry

ry Feb 13, 2020

Collaborator

I don't think storing the restore state is so important. The user can do that.

This comment has been minimized.

Copy link
@kevinkassimo

kevinkassimo Feb 13, 2020

Author Contributor

I don't think they can with current proposed API (unless we expose a full representation of <termios> utilities) if we do not store for them? And there is the discrepancy between Unix and Windows here

Node does not provide the API for direct restoration either. I believe with tty.ReadStream::setRaw(false) libuv simply sets back to the saved original mode

This comment has been minimized.

Copy link
@ry

ry Feb 13, 2020

Collaborator

libuv simply sets back to the saved original mode

Yes we should do that too... I mean that the JS interface does not need to expose state restoration just boolean on/off is good enough.

This comment has been minimized.

Copy link
@kevinkassimo

kevinkassimo Feb 13, 2020

Author Contributor

The slight annoyance is that we will need to accompany StreamResource (including FsFile) with such optional data. I'll see where would be the best place for me to place this piece of info.

@kevinkassimo kevinkassimo force-pushed the kevinkassimo:tty/raw_mode_2 branch from 6c96486 to b4429f4 Feb 13, 2020
@kevinkassimo kevinkassimo force-pushed the kevinkassimo:tty/raw_mode_2 branch from b4429f4 to 4999c68 Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.