summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/diagnostics.rs1
-rw-r--r--cli/dts/lib.deno.ns.d.ts27
-rw-r--r--cli/dts/lib.deno.unstable.d.ts34
-rw-r--r--cli/tests/integration/run_tests.rs2
-rw-r--r--cli/tests/testdata/run/unstable_worker.ts.out2
-rw-r--r--cli/tests/testdata/workers/worker_unstable.ts2
-rw-r--r--cli/tests/unit/tty_color_test.ts2
-rw-r--r--cli/tests/unit/tty_test.ts2
-rw-r--r--runtime/js/40_files.js5
-rw-r--r--runtime/js/40_tty.js6
-rw-r--r--runtime/js/90_deno_ns.js1
-rw-r--r--runtime/ops/tty.rs9
12 files changed, 43 insertions, 50 deletions
diff --git a/cli/diagnostics.rs b/cli/diagnostics.rs
index 6100bc9d5..c15832869 100644
--- a/cli/diagnostics.rs
+++ b/cli/diagnostics.rs
@@ -49,7 +49,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"osRelease",
"ppid",
"removeSignalListener",
- "setRaw",
"shutdown",
"Signal",
"startTls",
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index 095ae139a..f3e6b1376 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -1331,6 +1331,13 @@ declare namespace Deno {
readonly writable: WritableStream<Uint8Array>;
}
+ /** **UNSTABLE**: new API, yet to be vetted.
+ *
+ * @category I/O */
+ export interface SetRawOptions {
+ cbreak: boolean;
+ }
+
/** A handle for `stdin`.
*
* @category I/O
@@ -1338,6 +1345,26 @@ declare namespace Deno {
export const stdin: Reader & ReaderSync & Closer & {
readonly rid: number;
readonly readable: ReadableStream<Uint8Array>;
+ /** **UNSTABLE**: new API, yet to be vetted.
+ *
+ * Set TTY to be under raw mode or not. In raw mode, characters are read and
+ * returned as is, without being processed. All special processing of
+ * characters by the terminal is disabled, including echoing input
+ * characters. Reading from a TTY device in raw mode is faster than reading
+ * from a TTY device in canonical mode.
+ *
+ * The `cbreak` option can be used to indicate that characters that
+ * correspond to a signal should still be generated. When disabling raw
+ * mode, this option is ignored. This functionality currently only works on
+ * Linux and Mac OS.
+ *
+ * ```ts
+ * Deno.stdin.setRaw(true, { cbreak: true });
+ * ```
+ *
+ * @category I/O
+ */
+ setRaw(mode: boolean, options?: SetRawOptions): void;
};
/** A handle for `stdout`.
*
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index 6cb062396..54b328196 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -880,39 +880,7 @@ declare namespace Deno {
symbols: S,
): DynamicLibrary<S>;
- /** **UNSTABLE**: New API, yet to be vetted.
- *
- * @category I/O
- */
- export type SetRawOptions = {
- cbreak: boolean;
- };
-
- /** **UNSTABLE**: New API, yet to be vetted.
- *
- * Set TTY to be under raw mode or not. In raw mode, characters are read and
- * returned as is, without being processed. All special processing of
- * characters by the terminal is disabled, including echoing input characters.
- * Reading from a TTY device in raw mode is faster than reading from a TTY
- * device in canonical mode.
- *
- * The `cbreak` option can be used to indicate that characters that correspond
- * to a signal should still be generated. When disabling raw mode, this option
- * is ignored. This functionality currently only works on Linux and Mac OS.
- *
- * ```ts
- * Deno.setRaw(Deno.stdin.rid, true, { cbreak: true });
- * ```
- *
- * @category I/O
- */
- export function setRaw(
- rid: number,
- mode: boolean,
- options?: SetRawOptions,
- ): void;
-
- /** **UNSTABLE**: New API, yet to be vetted.
+ /** **UNSTABLE**: needs investigation into high precision time.
*
* Synchronously changes the access (`atime`) and modification (`mtime`) times
* of a file system object referenced by `path`. Given times are either in
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 3cafc79c6..e9285c603 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -3303,7 +3303,7 @@ fn set_raw_should_not_panic_on_no_tty() {
let output = util::deno_cmd()
.arg("eval")
.arg("--unstable")
- .arg("Deno.setRaw(Deno.stdin.rid, true)")
+ .arg("Deno.stdin.setRaw(true)")
// stdin set to piped so it certainly does not refer to TTY
.stdin(std::process::Stdio::piped())
// stderr is piped so we can capture output.
diff --git a/cli/tests/testdata/run/unstable_worker.ts.out b/cli/tests/testdata/run/unstable_worker.ts.out
index b40bdfeb8..182dc58a4 100644
--- a/cli/tests/testdata/run/unstable_worker.ts.out
+++ b/cli/tests/testdata/run/unstable_worker.ts.out
@@ -1,2 +1,2 @@
[Function: query]
-[Function: setRaw]
+[Function: consoleSize]
diff --git a/cli/tests/testdata/workers/worker_unstable.ts b/cli/tests/testdata/workers/worker_unstable.ts
index 5d14e228b..219f34e7b 100644
--- a/cli/tests/testdata/workers/worker_unstable.ts
+++ b/cli/tests/testdata/workers/worker_unstable.ts
@@ -1,5 +1,5 @@
console.log(Deno.permissions.query);
-console.log(Deno.setRaw);
+console.log(Deno.consoleSize);
self.onmessage = () => {
self.close();
};
diff --git a/cli/tests/unit/tty_color_test.ts b/cli/tests/unit/tty_color_test.ts
index feb4dd470..7662d039b 100644
--- a/cli/tests/unit/tty_color_test.ts
+++ b/cli/tests/unit/tty_color_test.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "./test_util.ts";
-// Note tests for Deno.setRaw is in integration tests.
+// Note tests for Deno.stdin.setRaw is in integration tests.
Deno.test(
{ permissions: { run: true, read: true } },
diff --git a/cli/tests/unit/tty_test.ts b/cli/tests/unit/tty_test.ts
index e50443aab..8787db3e1 100644
--- a/cli/tests/unit/tty_test.ts
+++ b/cli/tests/unit/tty_test.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assert, assertThrows } from "./test_util.ts";
-// Note tests for Deno.setRaw is in integration tests.
+// Note tests for Deno.stdin.setRaw is in integration tests.
Deno.test({ permissions: { read: true } }, function consoleSizeFile() {
const file = Deno.openSync("cli/tests/testdata/assets/hello.txt");
diff --git a/runtime/js/40_files.js b/runtime/js/40_files.js
index a2afdb09d..c864d3970 100644
--- a/runtime/js/40_files.js
+++ b/runtime/js/40_files.js
@@ -181,6 +181,11 @@
}
return this.#readable;
}
+
+ setRaw(mode, options = {}) {
+ const cbreak = !!(options.cbreak ?? false);
+ ops.op_stdin_set_raw(mode, cbreak);
+ }
}
class Stdout {
diff --git a/runtime/js/40_tty.js b/runtime/js/40_tty.js
index f43859ed7..be5154fa2 100644
--- a/runtime/js/40_tty.js
+++ b/runtime/js/40_tty.js
@@ -21,14 +21,8 @@
return !!isattyBuffer[0];
}
- const DEFAULT_CBREAK = false;
- function setRaw(rid, mode, options = {}) {
- ops.op_set_raw(rid, mode, options.cbreak || DEFAULT_CBREAK);
- }
-
window.__bootstrap.tty = {
consoleSize,
isatty,
- setRaw,
};
})(this);
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index e7b21640a..33b5d531a 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -117,7 +117,6 @@
};
__bootstrap.denoNsUnstable = {
- setRaw: __bootstrap.tty.setRaw,
consoleSize: __bootstrap.tty.consoleSize,
DiagnosticCategory: __bootstrap.diagnostics.DiagnosticCategory,
loadavg: __bootstrap.os.loadavg,
diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs
index e267fc07f..07c636e99 100644
--- a/runtime/ops/tty.rs
+++ b/runtime/ops/tty.rs
@@ -40,7 +40,7 @@ fn get_windows_handle(
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
- op_set_raw::decl(),
+ op_stdin_set_raw::decl(),
op_isatty::decl(),
op_console_size::decl(),
])
@@ -48,13 +48,14 @@ pub fn init() -> Extension {
}
#[op(fast)]
-fn op_set_raw(
+fn op_stdin_set_raw(
state: &mut OpState,
- rid: u32,
is_raw: bool,
cbreak: bool,
) -> Result<(), AnyError> {
- super::check_unstable(state, "Deno.setRaw");
+ super::check_unstable(state, "Deno.stdin.setRaw");
+
+ let rid = 0; // stdin is always rid=0
// From https://github.com/kkawakam/rustyline/blob/master/src/tty/windows.rs
// and https://github.com/kkawakam/rustyline/blob/master/src/tty/unix.rs