From 5d466da62c0333aafa7932c3c2406b72d183e27b Mon Sep 17 00:00:00 2001 From: Etienne Noel Date: Wed, 20 Mar 2024 12:41:31 -0700 Subject: [PATCH 1/2] - Update to add some options --- packages/cli/src/cli.module.ts | 1 + packages/cli/src/managers/console.manager.ts | 10 ++++++++-- packages/cli/src/options/console-readline.options.ts | 7 +++++++ packages/cli/src/options/options.ts | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 packages/cli/src/options/console-readline.options.ts create mode 100644 packages/cli/src/options/options.ts diff --git a/packages/cli/src/cli.module.ts b/packages/cli/src/cli.module.ts index 0d3e4778c..504c0dc1c 100644 --- a/packages/cli/src/cli.module.ts +++ b/packages/cli/src/cli.module.ts @@ -12,6 +12,7 @@ export * from "./event-payloads/event-payloads"; export * from "./interfaces/interfaces"; export * from "./managers/managers"; export * from "./mappers/mappers"; +export * from "./options/options"; export * from "./types/types"; export const CliModule: ModuleInterface = { diff --git a/packages/cli/src/managers/console.manager.ts b/packages/cli/src/managers/console.manager.ts index 09e5a56db..c3eb0ae05 100644 --- a/packages/cli/src/managers/console.manager.ts +++ b/packages/cli/src/managers/console.manager.ts @@ -2,7 +2,9 @@ import {injectable} from "tsyringe"; import {moduleScoped} from "@pristine-ts/common"; import {CliModuleKeyname} from "../cli.module.keyname"; import * as readline from 'node:readline/promises'; +import {moveCursor} from 'node:readline'; import { stdin as input, stdout as output } from 'node:process'; +import {ConsoleReadlineOptions} from "../options/console-readline.options"; @injectable() @moduleScoped(CliModuleKeyname) @@ -19,11 +21,15 @@ export class ConsoleManager { return process.stdin.read() as string; } - async readLine(question: string): Promise { + async readLine(question: string, options: ConsoleReadlineOptions = new ConsoleReadlineOptions()): Promise { const rl = readline.createInterface({ input, output }); const answer: string = await rl.question(question); - + + if(!options.showCharactersOnTyping) { + moveCursor(output, 0, -1); + } + rl.close(); return answer; diff --git a/packages/cli/src/options/console-readline.options.ts b/packages/cli/src/options/console-readline.options.ts new file mode 100644 index 000000000..8219cfcec --- /dev/null +++ b/packages/cli/src/options/console-readline.options.ts @@ -0,0 +1,7 @@ +export class ConsoleReadlineOptions { + showCharactersOnTyping: boolean = true; + + constructor(options: Partial) { + this.showCharactersOnTyping = options.showCharactersOnTyping ?? this.showCharactersOnTyping; + } +} \ No newline at end of file diff --git a/packages/cli/src/options/options.ts b/packages/cli/src/options/options.ts new file mode 100644 index 000000000..358af6f6f --- /dev/null +++ b/packages/cli/src/options/options.ts @@ -0,0 +1 @@ +export * from "./console-readline.options"; \ No newline at end of file From d4afbffaedc1dc95d8e9a1fe66cb2f1653326af5 Mon Sep 17 00:00:00 2001 From: Etienne Noel Date: Wed, 20 Mar 2024 12:44:08 -0700 Subject: [PATCH 2/2] update --- packages/cli/src/options/console-readline.options.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/options/console-readline.options.ts b/packages/cli/src/options/console-readline.options.ts index 8219cfcec..e03fd41a9 100644 --- a/packages/cli/src/options/console-readline.options.ts +++ b/packages/cli/src/options/console-readline.options.ts @@ -1,7 +1,7 @@ export class ConsoleReadlineOptions { showCharactersOnTyping: boolean = true; - constructor(options: Partial) { - this.showCharactersOnTyping = options.showCharactersOnTyping ?? this.showCharactersOnTyping; + constructor(options?: Partial) { + this.showCharactersOnTyping = options?.showCharactersOnTyping ?? this.showCharactersOnTyping; } } \ No newline at end of file