Skip to content

Commit

Permalink
Only write heading in blue if stdout is terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
lassik committed Oct 11, 2018
1 parent 7388058 commit d7c85cc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import chalk from "chalk";

export abstract class BaseCommand {
protected stdout: NodeJS.WriteStream = process.stdout;
protected stderr: NodeJS.WriteStream = process.stderr;
Expand All @@ -6,6 +8,10 @@ export abstract class BaseCommand {
this.stdout.write(text + "\n");
}

protected writeOutHeading(text: string): void {
this.writeOut(this.stdout.isTTY ? chalk.blue(text) : text);
}

protected writeError(text: string): void {
this.stderr.write(text + "\n");
}
Expand Down
4 changes: 1 addition & 3 deletions src/commands/SupportCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import chalk from "chalk";

import {
getSupportedLanguages,
findInstalledBeautifiers,
Expand Down Expand Up @@ -49,7 +47,7 @@ export class SupportCommand extends BaseCommand {

private listPrinter = (info: SupportInfo) => {
Object.keys(info).forEach(section => {
this.writeOut(chalk.blue(`Supported ${section}`));
this.writeOutHeading(`Supported ${section}`);
const items = info[section];
items.forEach((item, index) => this.writeOut(`${index + 1}. ${item}`));
});
Expand Down
6 changes: 3 additions & 3 deletions test/commands/__snapshots__/SupportCommand.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ exports[`SupportCommand Support without JSON installed beautifiers 1`] = `
Object {
"exitCode": 0,
"stderr": "",
"stdout": "[34mSupported beautifiers[39m
"stdout": "Supported beautifiers
1. @unibeautify/beautifier-eslint
",
}
Expand All @@ -514,7 +514,7 @@ exports[`SupportCommand Support without JSON languages 1`] = `
Object {
"exitCode": 0,
"stderr": "",
"stdout": "[34mSupported languages[39m
"stdout": "Supported languages
1. 1C Enterprise
2. ABAP
3. ABNF
Expand Down Expand Up @@ -1002,7 +1002,7 @@ exports[`SupportCommand Support without JSON supported languages 1`] = `
Object {
"exitCode": 0,
"stderr": "",
"stdout": "[34mSupported languages[39m
"stdout": "Supported languages
1. JSX
2. JavaScript
",
Expand Down

0 comments on commit d7c85cc

Please sign in to comment.