Skip to content

Commit

Permalink
Merge pull request #686 from magieno/add-console-readline
Browse files Browse the repository at this point in the history
- Update to add some options
  • Loading branch information
etiennenoel authored Mar 20, 2024
2 parents 4d08f2d + d4afbff commit b593742
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/cli.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/managers/console.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -19,11 +21,15 @@ export class ConsoleManager {
return process.stdin.read() as string;
}

async readLine(question: string): Promise<string> {
async readLine(question: string, options: ConsoleReadlineOptions = new ConsoleReadlineOptions()): Promise<string> {
const rl = readline.createInterface({ input, output });

const answer: string = await rl.question(question);


if(!options.showCharactersOnTyping) {
moveCursor(output, 0, -1);
}

rl.close();

return answer;
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/options/console-readline.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class ConsoleReadlineOptions {
showCharactersOnTyping: boolean = true;

constructor(options?: Partial<ConsoleReadlineOptions>) {
this.showCharactersOnTyping = options?.showCharactersOnTyping ?? this.showCharactersOnTyping;
}
}
1 change: 1 addition & 0 deletions packages/cli/src/options/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./console-readline.options";

0 comments on commit b593742

Please sign in to comment.