Skip to content

Commit 0971cee

Browse files
committed
feat: Refactoring setRawMode and disableRawMode into the reporter
1 parent 2a43158 commit 0971cee

6 files changed

Lines changed: 38 additions & 17 deletions

File tree

src/common/base-command.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,8 @@ export abstract class BaseCommand extends Command {
7777
}
7878

7979
if (data.options.stdin) {
80-
await this.reporter.hide();
8180
console.log(chalk.blue(`Plugin "${pluginName}" is requesting stdin`));
82-
83-
if (this.reporter instanceof DefaultReporter) {
84-
this.reporter.rawOutput = true;
85-
}
86-
87-
// Raw mode is needed by stdin applications to function properly
88-
process.stdin.setRawMode(true);
81+
await this.reporter.setRawMode();
8982
}
9083

9184
const result = await spawnSafe(data.command, data.options, pluginName, password)
@@ -97,13 +90,7 @@ export abstract class BaseCommand extends Command {
9790
} finally {
9891
// Always disable raw mode after
9992
if (data.options.stdin) {
100-
process.stdin.setRawMode(false);
101-
102-
if (this.reporter instanceof DefaultReporter) {
103-
this.reporter.rawOutput = false;
104-
}
105-
106-
await this.reporter.displayProgress();
93+
await this.reporter.disableRawMode();
10794
}
10895
}
10996
});

src/ui/reporters/default-reporter.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,19 @@ export class DefaultReporter implements Reporter {
111111
}
112112

113113
async hide(): Promise<void> {
114-
await this.updateRenderState(RenderStatus.NOTHING);
114+
store.set(store.renderState, { status: RenderStatus.NOTHING, data: null });
115+
}
116+
117+
async setRawMode(): Promise<void> {
118+
this.rawOutput = true;
119+
process.stdin.setRawMode(true);
120+
await this.hide();
121+
}
122+
123+
async disableRawMode(): Promise<void> {
124+
this.rawOutput = false;
125+
process.stdin.setRawMode(false);
126+
await this.displayProgress();
115127
}
116128

117129
async displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void> {

src/ui/reporters/json-reporter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ export class JsonReporter implements Reporter {
6363

6464
async displayImportWarning(): Promise<void> {
6565
}
66+
67+
async setRawMode(): Promise<void> {
68+
throw new Error('Json reporter error: setRawMode is not supported. Raw stdin mode requires interactive terminal access.');
69+
}
70+
71+
async disableRawMode(): Promise<void> {
72+
throw new Error('Json reporter error: disableRawMode is not supported. Raw stdin mode requires interactive terminal access.');
73+
}
6674
}

src/ui/reporters/plain-reporter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ export class PlainReporter implements Reporter {
3939

4040
async hide(): Promise<void> {}
4141

42+
async setRawMode(): Promise<void> {
43+
process.stdin.setRawMode(true);
44+
}
45+
46+
async disableRawMode(): Promise<void> {
47+
process.stdin.setRawMode(false);
48+
}
49+
4250
async displayImportWarning(): Promise<void> {
4351
ctx.log(chalk.bold('Additional information is required to continue import'))
4452
ctx.log('Some of the resources specified in the import support multiple instances. Additional information is required to identify the specific instance to import. If importing multiple instances is desired (for ex: multiple git clones) additional imports can be added in the prompt.')

src/ui/reporters/reporter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export interface Reporter {
7777
displayMessage(message: string): void
7878

7979
displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void>
80+
81+
setRawMode(): Promise<void>
82+
83+
disableRawMode(): Promise<void>
8084
}
8185

8286
export enum ReporterType {

src/ui/reporters/stub-reporter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ export class StubReporter implements Reporter {
2222
async displayImportResult(importResult: ImportResult): Promise<void> {}
2323
async displayFileModifications(diff: Array<{ file: string, modification: FileModificationResult }>): Promise<void> {}
2424
async displayMessage(message: string): Promise<void> {}
25-
async displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void> {}
25+
async displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void> {}
26+
async setRawMode(): Promise<void> {}
27+
async disableRawMode(): Promise<void> {}
2628
}

0 commit comments

Comments
 (0)