Skip to content

Turn on line wrapping in usage and status messages, adds ANSI color to doctor and analysis messages. - #22656

Merged
gspencergoog merged 7 commits into
flutter:masterfrom
gspencergoog:wrap_usage
Oct 6, 2018
Merged

gspencergoog merged 7 commits into
flutter:masterfrom
gspencergoog:wrap_usage

Conversation

@gspencergoog

@gspencergoog gspencergoog commented Oct 4, 2018 •

Copy link
Copy Markdown
Contributor

This turns on text wrapping for usage messages and status messages. When on a terminal, wraps to the width of the terminal. When writing to a non-terminal, wrap lines at a default column width (currently defined to be 100 chars). If --no-wrap is specified, then no wrapping occurs. If --wrap-column is specified, wraps to that column (if --wrap is on).

Adds ANSI color to the doctor and analysis output on terminals. This is in this PR with the wrapping, since wrapping needs to know how to count visible characters in the presence of ANSI sequences. (This is just one more step towards re-implementing all of Curses for Flutter. :-)) Will not print ANSI sequences when sent to a non-terminal, or of --no-color is specified.

Fixes ANSI color and bold sequences so that they can be combined (bold, colored text), and a small bug in indentation calculation for wrapping.

Since wrapping is now turned on, also removed many redundant '\n's in the code.

Some examples of how things look now (in a narrow terminal):

flutter analyze:
image

flutter doctor -v:
image

@gspencergoog gspencergoog changed the title Turn on line wrapping in usage and status messages, adds ANSI color to doctor messages. Turn on line wrapping in usage and status messages, adds ANSI color to doctor and analysis messages. Oct 4, 2018
@gspencergoog
gspencergoog force-pushed the wrap_usage branch 7 times, most recently from bc80da0 to 0136b41 Compare October 5, 2018 00:54
@gspencergoog
gspencergoog requested a review from xster October 5, 2018 00:56
@gspencergoog

Copy link
Copy Markdown
Contributor Author

One thing to think about for the review: Would it be better to just do no wrapping at all if not outputting to a terminal? Right now it wraps at 100 chars in that case.

@xster xster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can add a test for this one too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Document the params in the dartdoc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

dartdocs for these. I couldn't figure out what they are from name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

;]+m?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, I want to remove them all, since the next line adds a reset that would cancel them all, or be redundant anyhow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I meant swapping *m to +m. I assume you want 1 or more rather than 0 or more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. Yeah, definitely, although it's probably moot, since ^[[m isn't a valid ANSI escape (or commonly typed sequence!). Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe describe a bit what issues this solves? Since there are some risks associated with the regex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is the above public and this is not? Seems like they should be known to the user to the same extent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I guess so. It kind of seemed like an implementation detail, but I suppose you might want to know it to take it into account somewhere. Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just make it clear about whether it's in addition or instead of indent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not the same with hangingIndent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because I forgot to add it when I added hangingIndent. Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some indent issues :D

@gspencergoog
gspencergoog force-pushed the wrap_usage branch 3 times, most recently from bbb8b57 to 5cf50c3 Compare October 5, 2018 23:55
@xster

xster commented Oct 6, 2018

Copy link
Copy Markdown
Contributor

Still LGTM

@gspencergoog
gspencergoog merged commit e438632 into flutter:master Oct 6, 2018
gspencergoog added a commit to gspencergoog/flutter that referenced this pull request Oct 6, 2018
… color to doctor and analysis messages. (flutter#22656)"

This reverts commit e438632
because it breaks 160 benchmarks, and several devicelab tests,
due to changing the format of the output.
gspencergoog added a commit that referenced this pull request Oct 6, 2018
… color to doctor and analysis messages. (#22656)" (#22759)

This reverts commit e438632
because it breaks 160 benchmarks, and several devicelab tests,
due to changing the format of the output.
gspencergoog added a commit to gspencergoog/flutter that referenced this pull request Oct 10, 2018
…color to doctor and analysis messages. (flutter#22656)

    This turns on text wrapping for usage messages and status messages. When on a terminal, wraps to the width of the terminal. When writing to a non-terminal, wrap lines at a default column width (currently defined to be 100 chars). If --no-wrap is specified, then no wrapping occurs. If --wrap-column is specified, wraps to that column (if --wrap is on).

    Adds ANSI color to the doctor and analysis output on terminals. This is in this PR with the wrapping, since wrapping needs to know how to count visible characters in the presence of ANSI sequences. (This is just one more step towards re-implementing all of Curses for Flutter. :-)) Will not print ANSI sequences when sent to a non-terminal, or of --no-color is specified.

    Fixes ANSI color and bold sequences so that they can be combined (bold, colored text), and a small bug in indentation calculation for wrapping.

    Since wrapping is now turned on, also removed many redundant '\n's in the code.
gspencergoog added a commit that referenced this pull request Oct 11, 2018
This attempts to re-land #22656.

There are two changes from the original:

I turned off wrapping completely when not sending output to a terminal. Previously I had defaulted to wrapping at and arbitrary 100 chars in that case, just to keep long messages from being too long, but that turns out the be a bad idea because there are tests that are relying on the specific form of the output. It's also pretty arbitrary, and mostly people sending output to a non-terminal will want unwrapped text.

I found a better way to terminate ANSI color/bold sequences, so that they can be embedded within each other without needed quite as complex a dance with removing redundant sequences.

As part of these changes, I removed the Logger.supportsColor setter so that the one source of truth for color support is in AnsiTerminal.supportsColor.

*     Turn on line wrapping again in usage and status messages, adds ANSI color to doctor and analysis messages. (#22656)

    This turns on text wrapping for usage messages and status messages. When on a terminal, wraps to the width of the terminal. When writing to a non-terminal, wrap lines at a default column width (currently defined to be 100 chars). If --no-wrap is specified, then no wrapping occurs. If --wrap-column is specified, wraps to that column (if --wrap is on).

    Adds ANSI color to the doctor and analysis output on terminals. This is in this PR with the wrapping, since wrapping needs to know how to count visible characters in the presence of ANSI sequences. (This is just one more step towards re-implementing all of Curses for Flutter. :-)) Will not print ANSI sequences when sent to a non-terminal, or of --no-color is specified.

    Fixes ANSI color and bold sequences so that they can be combined (bold, colored text), and a small bug in indentation calculation for wrapping.

    Since wrapping is now turned on, also removed many redundant '\n's in the code.
@rmacnak-google

Copy link
Copy Markdown
Contributor

Can we disable this when printing command lines in verbose mode? The line breaks mean I can no longer just copy and paste the command, and the commands I'm interested in running manually are usually very long and tedious to fix up.

@gspencergoog

gspencergoog commented Nov 1, 2018 •

Copy link
Copy Markdown
Contributor Author

I'm not sure which "command lines" you're referring to, but you can always add --no-wrap to turn it off, or pipe it to cat.

@rmacnak-google

Copy link
Copy Markdown
Contributor

I mean the "executing: long/path/gen_snapshot --many --options" etc. --no-wrap works for me, thanks!

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 9, 2021
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.

4 participants