-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
Evan Martin » ninja #472 SUCCESS |
Evan Martin » ninja #488 SUCCESS |
Evan Martin » ninja #492 SUCCESS |
Evan Martin » ninja #494 SUCCESS |
Evan Martin » ninja #504 FAILURE |
Evan Martin » ninja #505 SUCCESS |
Evan Martin » ninja #506 SUCCESS |
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
Evan Martin » ninja #508 SUCCESS |
This is ready for merging in to master. I've tested it on linux & windows, added a test case to misc, and added documentation. |
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).
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).
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).
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).
Thanks for the PR! Sorry for the long silence.
Wouldn't this work anyway since you're piping to sed which would disable the smart terminal features? |
This comment was marked as abuse.
This comment was marked as abuse.
Closing due to inactivity. Also there's now |
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, $,,'