Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--pretty-er output by default #23408

Merged
merged 6 commits into from
Apr 19, 2018
Merged

--pretty-er output by default #23408

merged 6 commits into from
Apr 19, 2018

Conversation

DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Apr 14, 2018

This pull request always makes TypeScript's output --pretty when the compiler can detect whether its "output device" is appropriate for more colorful output.

If TypeScript's output is a psuedo-TTY, then it will enable today's prettified output and emit escape characters to the console; however, when piping to another file or program, it will automatically turned off.

Programs that want to specify the behavior can specifically set --pretty, or the new --diagnosticStyle flag.

This PR also affords us the room to give more variation in out emit modes. For example, with --diagnosticStyle, we could have a more colorful simple/terse mode as requested in #10745.

Fixes #10488.

@DanielRosenwasser DanielRosenwasser changed the title Automatically enable --pretty Enable --pretty automatically Apr 14, 2018
@DanielRosenwasser DanielRosenwasser changed the title Enable --pretty automatically --pretty-er output by default Apr 14, 2018
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we... Have a way we can test this? Oh! Maybe We could write a unit test that shells out to the built local tsc and baselines the output!

Locals pretty straightforward; you got any details on what terms/apps this causes pretty by default in now?

@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Apr 14, 2018

I know the last time I did this (i.e. when I originally wrote --pretty), there were issues with either Cygwin's bash terminal or MinGW. I forgot which, but I'll have to peek at that again.

Tests are Monday-Daniel-and-Wesley's problem. 😄

function shouldBePretty(options: CompilerOptions) {
if ((typeof options.pretty === "undefined" && typeof options.diagnosticStyle === "undefined") || options.diagnosticStyle === DiagnosticStyle.Auto) {
return !!sys.writeOutputIsTty && sys.writeOutputIsTty();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

pretty: DiagnosticStyle.Pretty,
simple: DiagnosticStyle.Simple,
}),
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true);
}
}

function shouldBePretty(options: CompilerOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now there are two CLI flags that can tell tsc it's pretty. What if the user provides tsc --pretty false --diagnosticStyle pretty or tsc --pretty true --diagnosticStyle simple? Should there be a warning for providing both?

@@ -56,6 +56,14 @@ namespace ts {
category: Diagnostics.Command_line_Options,
description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather we do not add a new flag if we can. i think auto is just pretty === undefined.

if we really need a new value i would make pretty take boolean | "auto"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean | "auto" | "simple" | "styled"? (Where boolean toggles between auto and styled).

if ((typeof options.pretty === "undefined" && typeof options.diagnosticStyle === "undefined") || options.diagnosticStyle === DiagnosticStyle.Auto) {
return !!sys.writeOutputIsTty && sys.writeOutputIsTty();
}
return options.diagnosticStyle === DiagnosticStyle.Pretty || options.pretty;
Copy link
Contributor

@mhegazy mhegazy Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! options.pretty

Copy link
Contributor

@mhegazy mhegazy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please 1. remove the extra flag, and 2. test on chakra

@@ -428,6 +428,7 @@ namespace ts {
newLine: string;
useCaseSensitiveFileNames: boolean;
write(s: string): void;
writeOutputIsTty?(): boolean;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a reasonable name @weswigham?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TTY, not Tty.

reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true);
}
}

function shouldBePretty(options: CompilerOptions) {
if ((typeof options.pretty === "undefined")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra parens.

@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Apr 19, 2018

Tried it out. tsc.exe (the Chakra host-wrapped tsc) reverts to the old behavior. Like before, --pretty on tsc.exe produces garbled text when explicitly specified, but that's always been the behavior. I'm going to pull this in so we can get it in tonight's nightly release.

@DanielRosenwasser DanielRosenwasser merged commit 6ee4989 into master Apr 19, 2018
@DanielRosenwasser DanielRosenwasser deleted the autoPretty branch April 19, 2018 06:10
@mhegazy
Copy link
Contributor

mhegazy commented Apr 19, 2018

@DanielRosenwasser please update https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Compiler%20Options.md as well.

@kpreisser
Copy link
Contributor

kpreisser commented Apr 23, 2018

Hi @DanielRosenwasser,

Like before, --pretty on tsc.exe produces garbled text when explicitly specified, but that's always been the behavior.

I guess this is because tsc.exe doesn't set the console mode on Windows to enable processing of Virtual Terminal Sequences (ENABLE_VIRTUAL_TERMINAL_PROCESSING).
Starting with Windows 10 Version 1511, this mode can be set to enable the parsing of terminal sequences, so that --pretty should work with tsc.exe on Windows 10.

(I think Node.js parses these sequences itself and then calls the corresponding APIs like SetConsoleTextAttribute, so that it works also with older Windows versions.)

Can tsc.exe be updated to set this console mode?

Thanks!

@DanielRosenwasser
Copy link
Member Author

Thanks for the pointers, I might look into it @kpreisser!

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants