From 72af1496d9bc180b49d42976a31b331d0be1b975 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 23 Sep 2022 09:35:45 +0530 Subject: perf: use fast ops for tty (#15976) --- runtime/js/40_tty.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'runtime/js') diff --git a/runtime/js/40_tty.js b/runtime/js/40_tty.js index 9cf351cc0..f43859ed7 100644 --- a/runtime/js/40_tty.js +++ b/runtime/js/40_tty.js @@ -2,24 +2,28 @@ "use strict"; ((window) => { + const { + Uint32Array, + Uint8Array, + } = window.__bootstrap.primordials; const core = window.Deno.core; const ops = core.ops; + const size = new Uint32Array(2); function consoleSize(rid) { - return ops.op_console_size(rid); + ops.op_console_size(rid, size); + return { columns: size[0], rows: size[1] }; } + const isattyBuffer = new Uint8Array(1); function isatty(rid) { - return ops.op_isatty(rid); + ops.op_isatty(rid, isattyBuffer); + return !!isattyBuffer[0]; } - const DEFAULT_SET_RAW_OPTIONS = { - cbreak: false, - }; - + const DEFAULT_CBREAK = false; function setRaw(rid, mode, options = {}) { - const rOptions = { ...DEFAULT_SET_RAW_OPTIONS, ...options }; - ops.op_set_raw({ rid, mode, options: rOptions }); + ops.op_set_raw(rid, mode, options.cbreak || DEFAULT_CBREAK); } window.__bootstrap.tty = { -- cgit v1.2.3