From 8e9ab9e33ea2c972762cc345c584391c37731b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 27 Apr 2020 15:40:47 +0200 Subject: refactor: decouple Console implementation from stdout (#4899) When creating a console instance, one must pass "printFunc" arg which is used internally by Console to output messages. Due to numerous refactors there was a single method ("console.clear()") that used "Deno.stdout" instead of "printFunc". This commit unifies how "Console" outpus message, by using "printFunc" in all methods; consequently "Deno.stdout" is no longer imported in "cli/js/console.ts" making it a standalone module that doesn't depend on any CLI-specific APIs. --- cli/js/web/console.ts | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'cli/js/web') diff --git a/cli/js/web/console.ts b/cli/js/web/console.ts index 061147887..5544ded3c 100644 --- a/cli/js/web/console.ts +++ b/cli/js/web/console.ts @@ -1,8 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { isTypedArray, TypedArray } from "./util.ts"; -import { TextEncoder } from "./text_encoding.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"; @@ -39,16 +36,6 @@ export class CSI { /* eslint-disable @typescript-eslint/no-use-before-define */ -function cursorTo(stream: SyncWriter, _x: number, _y?: number): void { - const uint8 = new TextEncoder().encode(CSI.kClear); - stream.writeSync(uint8); -} - -function clearScreenDown(stream: SyncWriter): void { - const uint8 = new TextEncoder().encode(CSI.kClearScreenDown); - stream.writeSync(uint8); -} - function getClassInstanceName(instance: unknown): string { if (typeof instance !== "object") { return ""; @@ -934,8 +921,8 @@ export class Console { clear = (): void => { this.indentLevel = 0; - cursorTo(stdout, 0, 0); - clearScreenDown(stdout); + this.#printFunc(CSI.kClear, false); + this.#printFunc(CSI.kClearScreenDown, false); }; trace = (...args: unknown[]): void => { -- cgit v1.2.3