diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index c37315a2e5601..be95e06eb46cb 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -428,6 +428,7 @@ namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; + writeOutputIsTTY?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; @@ -561,6 +562,9 @@ namespace ts { write(s: string): void { process.stdout.write(s); }, + writeOutputIsTTY() { + return process.stdout.isTTY; + }, readFile, writeFile, watchFile: getWatchFile(), diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index f16ca98c93dac..3c73eba86ef1a 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -19,11 +19,18 @@ namespace ts { let reportDiagnostic = createDiagnosticReporter(sys); function updateReportDiagnostic(options: CompilerOptions) { - if (options.pretty) { + if (shouldBePretty(options)) { reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true); } } + function shouldBePretty(options: CompilerOptions) { + if (typeof options.pretty === "undefined") { + return !!sys.writeOutputIsTTY && sys.writeOutputIsTTY(); + } + return options.pretty; + } + function padLeft(s: string, length: number) { while (s.length < length) { s = " " + s; @@ -159,7 +166,7 @@ namespace ts { } function createWatchStatusReporter(options: CompilerOptions) { - return ts.createWatchStatusReporter(sys, !!options.pretty); + return ts.createWatchStatusReporter(sys, shouldBePretty(options)); } function createWatchOfConfigFile(configParseResult: ParsedCommandLine, optionsToExtend: CompilerOptions) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 987d403e7cd9e..8962a7d028059 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4193,7 +4193,7 @@ namespace ts { preserveSymlinks?: boolean; /* @internal */ preserveWatchOutput?: boolean; project?: string; - /* @internal */ pretty?: DiagnosticStyle; + /* @internal */ pretty?: boolean; reactNamespace?: string; jsxFactory?: string; removeComments?: boolean; @@ -4291,12 +4291,6 @@ namespace ts { JSX, } - /* @internal */ - export const enum DiagnosticStyle { - Simple, - Pretty, - } - /** Either a parsed command line or a parsed tsconfig.json */ export interface ParsedCommandLine { options: CompilerOptions; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2e8e3f3871df3..be11525ffb76d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2888,6 +2888,7 @@ declare namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; + writeOutputIsTTY?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 378949d5b5b07..c0cab668854c6 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2888,6 +2888,7 @@ declare namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; + writeOutputIsTTY?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;