summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/js/files.ts63
-rw-r--r--cli/js/lib.deno.ns.d.ts24
-rw-r--r--cli/js/web/console.ts7
3 files changed, 82 insertions, 12 deletions
diff --git a/cli/js/files.ts b/cli/js/files.ts
index 97a8c1e2b..9b4738ba5 100644
--- a/cli/js/files.ts
+++ b/cli/js/files.ts
@@ -97,9 +97,66 @@ export class File
}
}
-export const stdin = new File(0);
-export const stdout = new File(1);
-export const stderr = new File(2);
+class Stdin implements Reader, SyncReader, Closer {
+ readonly rid: number;
+ constructor() {
+ this.rid = 0;
+ }
+
+ read(p: Uint8Array): Promise<number | EOF> {
+ return read(this.rid, p);
+ }
+
+ readSync(p: Uint8Array): number | EOF {
+ return readSync(this.rid, p);
+ }
+
+ close(): void {
+ close(this.rid);
+ }
+}
+
+class Stdout implements Writer, SyncWriter, Closer {
+ readonly rid: number;
+ constructor() {
+ this.rid = 1;
+ }
+
+ write(p: Uint8Array): Promise<number> {
+ return write(this.rid, p);
+ }
+
+ writeSync(p: Uint8Array): number {
+ return writeSync(this.rid, p);
+ }
+
+ close(): void {
+ close(this.rid);
+ }
+}
+
+export class Stderr implements Writer, SyncWriter, Closer {
+ readonly rid: number;
+ constructor() {
+ this.rid = 2;
+ }
+
+ write(p: Uint8Array): Promise<number> {
+ return write(this.rid, p);
+ }
+
+ writeSync(p: Uint8Array): number {
+ return writeSync(this.rid, p);
+ }
+
+ close(): void {
+ close(this.rid);
+ }
+}
+
+export const stdin = new Stdin();
+export const stdout = new Stdout();
+export const stderr = new Stderr();
function checkOpenOptions(options: OpenOptions): void {
if (Object.values(options).filter((val) => val === true).length === 0) {
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 84e287fca..493ebd5e2 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -825,12 +825,24 @@ declare namespace Deno {
close(): void;
}
- /** An instance of `Deno.File` for `stdin`. */
- export const stdin: File;
- /** An instance of `Deno.File` for `stdout`. */
- export const stdout: File;
- /** An instance of `Deno.File` for `stderr`. */
- export const stderr: File;
+ export interface Stdin extends Reader, SyncReader, Closer {
+ readonly rid: number;
+ }
+
+ export interface Stdout extends Writer, SyncWriter, Closer {
+ readonly rid: number;
+ }
+
+ export interface Stderr extends Writer, SyncWriter, Closer {
+ readonly rid: number;
+ }
+
+ /** A handle for `stdin`. */
+ export const stdin: Stdin;
+ /** A handle for `stdout`. */
+ export const stdout: Stdout;
+ /** A handle for `stderr`. */
+ export const stderr: Stderr;
export interface OpenOptions {
/** Sets the option for read access. This option, when `true`, means that the
diff --git a/cli/js/web/console.ts b/cli/js/web/console.ts
index 3a274e086..7f320398c 100644
--- a/cli/js/web/console.ts
+++ b/cli/js/web/console.ts
@@ -1,7 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { isTypedArray, TypedArray } from "./util.ts";
import { TextEncoder } from "./text_encoding.ts";
-import { File, stdout } from "../files.ts";
+import { SyncWriter } from "../io.ts";
+import { stdout } from "../files.ts";
import { cliTable } from "./console_table.ts";
import { exposeForTest } from "../internals.ts";
import { PromiseState } from "./promise.ts";
@@ -38,12 +39,12 @@ export class CSI {
/* eslint-disable @typescript-eslint/no-use-before-define */
-function cursorTo(stream: File, _x: number, _y?: number): void {
+function cursorTo(stream: SyncWriter, _x: number, _y?: number): void {
const uint8 = new TextEncoder().encode(CSI.kClear);
stream.writeSync(uint8);
}
-function clearScreenDown(stream: File): void {
+function clearScreenDown(stream: SyncWriter): void {
const uint8 = new TextEncoder().encode(CSI.kClearScreenDown);
stream.writeSync(uint8);
}