Skip to content

Commit 6ee4989

Browse files
Merge pull request #23408 from Microsoft/autoPretty
--pretty-er output by default
2 parents 238ed7a + 25bb581 commit 6ee4989

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

src/compiler/sys.ts

+4
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ namespace ts {
428428
newLine: string;
429429
useCaseSensitiveFileNames: boolean;
430430
write(s: string): void;
431+
writeOutputIsTTY?(): boolean;
431432
readFile(path: string, encoding?: string): string | undefined;
432433
getFileSize?(path: string): number;
433434
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
@@ -561,6 +562,9 @@ namespace ts {
561562
write(s: string): void {
562563
process.stdout.write(s);
563564
},
565+
writeOutputIsTTY() {
566+
return process.stdout.isTTY;
567+
},
564568
readFile,
565569
writeFile,
566570
watchFile: getWatchFile(),

src/compiler/tsc.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ namespace ts {
1919

2020
let reportDiagnostic = createDiagnosticReporter(sys);
2121
function updateReportDiagnostic(options: CompilerOptions) {
22-
if (options.pretty) {
22+
if (shouldBePretty(options)) {
2323
reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true);
2424
}
2525
}
2626

27+
function shouldBePretty(options: CompilerOptions) {
28+
if (typeof options.pretty === "undefined") {
29+
return !!sys.writeOutputIsTTY && sys.writeOutputIsTTY();
30+
}
31+
return options.pretty;
32+
}
33+
2734
function padLeft(s: string, length: number) {
2835
while (s.length < length) {
2936
s = " " + s;
@@ -159,7 +166,7 @@ namespace ts {
159166
}
160167

161168
function createWatchStatusReporter(options: CompilerOptions) {
162-
return ts.createWatchStatusReporter(sys, !!options.pretty);
169+
return ts.createWatchStatusReporter(sys, shouldBePretty(options));
163170
}
164171

165172
function createWatchOfConfigFile(configParseResult: ParsedCommandLine, optionsToExtend: CompilerOptions) {

src/compiler/types.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -4195,7 +4195,7 @@ namespace ts {
41954195
preserveSymlinks?: boolean;
41964196
/* @internal */ preserveWatchOutput?: boolean;
41974197
project?: string;
4198-
/* @internal */ pretty?: DiagnosticStyle;
4198+
/* @internal */ pretty?: boolean;
41994199
reactNamespace?: string;
42004200
jsxFactory?: string;
42014201
removeComments?: boolean;
@@ -4293,12 +4293,6 @@ namespace ts {
42934293
JSX,
42944294
}
42954295

4296-
/* @internal */
4297-
export const enum DiagnosticStyle {
4298-
Simple,
4299-
Pretty,
4300-
}
4301-
43024296
/** Either a parsed command line or a parsed tsconfig.json */
43034297
export interface ParsedCommandLine {
43044298
options: CompilerOptions;

tests/baselines/reference/api/tsserverlibrary.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,7 @@ declare namespace ts {
28892889
newLine: string;
28902890
useCaseSensitiveFileNames: boolean;
28912891
write(s: string): void;
2892+
writeOutputIsTTY?(): boolean;
28922893
readFile(path: string, encoding?: string): string | undefined;
28932894
getFileSize?(path: string): number;
28942895
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;

tests/baselines/reference/api/typescript.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,7 @@ declare namespace ts {
28892889
newLine: string;
28902890
useCaseSensitiveFileNames: boolean;
28912891
write(s: string): void;
2892+
writeOutputIsTTY?(): boolean;
28922893
readFile(path: string, encoding?: string): string | undefined;
28932894
getFileSize?(path: string): number;
28942895
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;

0 commit comments

Comments
 (0)