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

Add NINJA_SMART_TERMINAL environment variable, with on, off, and hide_newline options #581

Closed
wants to merge 1 commit into from

Conversation

rgeary1
Copy link
Contributor

@rgeary1 rgeary1 commented May 22, 2013

This patch allows you to manually enable or disable the smart terminal behaviour, and adds a hide_newline smart-terminal mode to allow sed processing.

Like NINJA_STATUS, I have added this optional feature as an environment variable rather than a typical command line option. Since it only affects how the progress is displayed, this would appear to be a good place for it, and minimises command line option clutter.

Use cases : Currently ninja will turn off smart terminal mode if you are piping to a file. Occasionally you want to force this behaviour on, to replicate the smart line display through a pipe, or you may want to force it off if your terminal emulator doesn't support special escape characters (eg. emacs)

Additionally, you can export NINJA_SMART_TERMINAL="hide_newline" :
This feature prints a \n newline and move-up-1-line escape-char \e[1A at the end of each line to allow sed processing. The stream editor "sed" usually processes the stream one line at a time, so it waits for a newline \n character before printing the piped output. The "hide_newline" feature allows the smart terminal behaviour whilst using sed.

This allows the following script, which highlights directories in blue & files in red :

~/inet/ninja-master/ninja | sed -e 's,^, ,' -e 's,$, ,' -e "s,([^+ ][A-Za-z/][-A-Za-z0-9/.]/)([^ :]_.[ :]),\x1b[0;34m\1\x1b[m\x1b[1;31m\21b[m,g" -e 's,^ ,,' -e 's, $,,'

@buildhive
Copy link

Evan Martin » ninja #472 SUCCESS
This pull request looks good
(what's this?)

@buildhive
Copy link

Evan Martin » ninja #488 SUCCESS
This pull request looks good
(what's this?)

@buildhive
Copy link

Evan Martin » ninja #492 SUCCESS
This pull request looks good
(what's this?)

@buildhive
Copy link

Evan Martin » ninja #494 SUCCESS
This pull request looks good
(what's this?)

@buildhive
Copy link

Evan Martin » ninja #504 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive
Copy link

Evan Martin » ninja #505 SUCCESS
This pull request looks good
(what's this?)

@buildhive
Copy link

Evan Martin » ninja #506 SUCCESS
This pull request looks good
(what's this?)

  Prints a \n and move-up-1-line char at the end of each line
  to allow sed processing
Add misc/long-lines-test.ninja and documentation
Fix ElideMiddle rounding bug
@buildhive
Copy link

Evan Martin » ninja #508 SUCCESS
This pull request looks good
(what's this?)

@rgeary1
Copy link
Contributor Author

rgeary1 commented Jun 15, 2013

This is ready for merging in to master. I've tested it on linux & windows, added a test case to misc, and added documentation.

mgiuffrida added a commit to mgiuffrida/ninja that referenced this pull request Jan 27, 2017
Adds the general-purpose -o flag to address ninja-build#746, with options for
verbosity (ninja-build#480) and control sequence stripping (ninja-build#581, ninja-build#672, ninja-build#916). Also
provides the ability to enable both verbose and raw output as a
workaround for ninja-build#1214 without changing the existing verbose behavior.

-o verbose  show all command lines while building
-o quiet    hide command lines and outputs while building
-o raw      never strip control sequences from output
-o strip    always strip control sequences from output
-o color    strip most control sequences from output, but retain color codes

This patch does not affect Ninja's defaults of normal verbosity and
smart terminal detection for escape sequence stripping.

"-o color" is particularly useful for utilities like `head` and
`less -R` that interpret color codes from stdin and pass this colored
output to stdout. Any valid ANSI color code, of the form:

    `'ESC' '[' [ colors ] 'm'`

where `colors` is a semicolon-delimited list of optional integers:

   `[ n ] [ ';' colors ]`

is retained in its entirety when using "-o color" (any other CSI escape
sequences besides ANSI color codes are still stripped for non-smart
terminals).
mgiuffrida added a commit to mgiuffrida/ninja that referenced this pull request Jan 27, 2017
Adds the general-purpose -o flag to address ninja-build#746, with options for
verbosity (ninja-build#480) and control sequence stripping (ninja-build#581, ninja-build#672, ninja-build#916). Also
provides the ability to enable both verbose and raw output as a
workaround for ninja-build#1214 without changing the existing verbose behavior.

-o verbose  show all command lines while building
-o quiet    hide command lines and outputs while building
-o raw      never strip control sequences from output
-o strip    always strip control sequences from output
-o color    strip most control sequences from output, but retain color codes

This patch does not affect Ninja's defaults of normal verbosity and
smart terminal detection for escape sequence stripping.

"-o color" is particularly useful for utilities like `head` and
`less -R` that interpret color codes from stdin and pass this colored
output to stdout. Any valid ANSI color code, of the form:

    `'ESC' '[' [ colors ] 'm'`

where `colors` is a semicolon-delimited list of optional integers:

   `[ n ] [ ';' colors ]`

is retained in its entirety when using "-o color" (any other CSI escape
sequences besides ANSI color codes are still stripped for non-smart
terminals).
mgiuffrida added a commit to mgiuffrida/ninja that referenced this pull request Jan 27, 2017
Adds the general-purpose -o flag to address ninja-build#746, with options for
verbosity (ninja-build#480) and control sequence stripping (ninja-build#581, ninja-build#672, ninja-build#916). Also
provides the ability to enable both verbose and raw output as a
workaround for ninja-build#1214 without changing the existing verbose behavior.

-o verbose  show all command lines while building
-o quiet    hide command lines and outputs while building
-o raw      never strip control sequences from output
-o strip    always strip control sequences from output
-o color    strip most control sequences from output, but retain color codes

This patch does not affect Ninja's defaults of normal verbosity and
smart terminal detection for escape sequence stripping.

"-o color" is particularly useful for utilities like `head` and
`less -R` that interpret color codes from stdin and pass this colored
output to stdout. Any valid ANSI color code, of the form:

    `'ESC' '[' [ colors ] 'm'`

where `colors` is a semicolon-delimited list of optional integers:

   `[ n ] [ ';' colors ]`

is retained in its entirety when using "-o color" (any other CSI escape
sequences besides ANSI color codes are still stripped for non-smart
terminals).
timniederhausen pushed a commit to timniederhausen/ninja that referenced this pull request Sep 19, 2017
Adds the general-purpose -o flag to address ninja-build#746, with options for
verbosity (ninja-build#480) and control sequence stripping (ninja-build#581, ninja-build#672, ninja-build#916). Also
provides the ability to enable both verbose and raw output as a
workaround for ninja-build#1214 without changing the existing verbose behavior.

-o verbose  show all command lines while building
-o quiet    hide command lines and outputs while building
-o raw      never strip control sequences from output
-o strip    always strip control sequences from output
-o color    strip most control sequences from output, but retain color codes

This patch does not affect Ninja's defaults of normal verbosity and
smart terminal detection for escape sequence stripping.

"-o color" is particularly useful for utilities like `head` and
`less -R` that interpret color codes from stdin and pass this colored
output to stdout. Any valid ANSI color code, of the form:

    `'ESC' '[' [ colors ] 'm'`

where `colors` is a semicolon-delimited list of optional integers:

   `[ n ] [ ';' colors ]`

is retained in its entirety when using "-o color" (any other CSI escape
sequences besides ANSI color codes are still stripped for non-smart
terminals).
@jhasse
Copy link
Collaborator

jhasse commented Nov 13, 2018

Thanks for the PR! Sorry for the long silence.

This allows the following script, which highlights directories in blue & files in red

Wouldn't this work anyway since you're piping to sed which would disable the smart terminal features?

@jonesmz

This comment was marked as abuse.

@jhasse
Copy link
Collaborator

jhasse commented Dec 3, 2020

Closing due to inactivity. Also there's now CLICOLOR_FORCE, so I'm not sure if this is still needed.

@jhasse jhasse closed this Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants