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

Respect TERM=dumb and emit no colour escape codes #847

Open
andreastt opened this Issue Feb 9, 2017 · 6 comments

Comments

4 participants
@andreastt

andreastt commented Feb 9, 2017

Certain shells are not particularly happy with colour escape codes. To make them happy, clap should respect TERM=dumb and refrain from emitting colour escape codes.

Rust Version

rustc 1.15.0 (10893a9a3 2017-01-19)

Affected Version of clap

% grep clap Cargo.toml
clap = "2.19.0"

Expected Behavior Summary

For a program using clap to respect TERM=dumb and emit no colour escape codes.

Actual Behavior Summary

Program using clap emits colour escape codes as shown in BurntSushi/ripgrep#353.

Steps to Reproduce the issue

Compile any program using clap as a dependency and use an unrecognised flag:

% rg --color never -asd
�[1;31merror:�[0m Found argument '�[33m-d�[0m' which wasn't expected, or isn't valid in this context

USAGE:
    
    rg [OPTIONS] <pattern> [<path> ...]
    rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
    rg [OPTIONS] --files [<path> ...]
    rg [OPTIONS] --type-list

For more information try �[32m--help�[0m
@kbknapp

This comment has been minimized.

Member

kbknapp commented Feb 9, 2017

Thanks!

Relates to #836

@kbknapp kbknapp added this to the 2.21.0 milestone Feb 12, 2017

@kbknapp kbknapp added this to Up Next in Status Feb 12, 2017

@kbknapp kbknapp moved this from Up Next to Triaged in Status Mar 27, 2017

@kbknapp kbknapp added W: 3.x blocker and removed W: 2.x labels May 9, 2017

@nateozem

This comment has been minimized.

Contributor

nateozem commented May 15, 2017

I wonder if someone can reference TERM=dumb is standardize across applications. Is there any documentation that explains how it should behave?

@BurntSushi

This comment has been minimized.

Contributor

BurntSushi commented May 15, 2017

@nateozem This is the best I could find: https://linux.die.net/man/7/term --- TL;DR the TERM=dumb convention is quite old. The behavior today is to treat TERM=dumb as "don't emit escape sequences because the terminal being used won't know how to use them."

@nateozem

This comment has been minimized.

Contributor

nateozem commented May 16, 2017

@BurntSushi, interesting.
Seem like the behavior would depend on each individual machine. In most probability, everyone has the same capability for dumb, but there can be an instance where someone can change how the terminal type behaves by using the tic command.
On my system, I can do this to check the definition: $ infocmp -L dumb

$ infocmp -L dumb
#       Reconstructed via infocmp from file: /usr/share/terminfo/64/dumb
dumb|80-column dumb tty,
		auto_right_margin,
		columns#80,
		bell=^G, carriage_return=^M, cursor_down=^J,
		scroll_forward=^J,

My expectation of moving forward is by calling "curses interfaces to terminfo database" ($ man curs_terminfo(3X)). What do you guys think?

When I discover anything more, I'll report back.

@BurntSushi

This comment has been minimized.

Contributor

BurntSushi commented May 16, 2017

@nateozem Consulting terminfo is certainly one path. It's a complex one, but it's valid. On the other hand, just respecting TERM=dumb will solve a good number of problems. Perhaps not all of them, but some of them. :-)

An example of a popular piece of software that generally gets colors correct is GNU grep, but they don't consult terminfo at all. This sacrifices compatibility on some very obscure terminal environments, but standard ANSI escapes pretty much work everywhere. (And GNU grep supports TERM=dumb explicitly.)

@nateozem

This comment has been minimized.

Contributor

nateozem commented May 16, 2017

We could do almost the same thing as they have done

http://git.savannah.gnu.org/cgit/grep.git/tree/lib/colorize-posix.c:

/* Return non-zero if we should highlight matches in output to file
   descriptor FD.  */
int
should_colorize (void)
{
  char const *t = getenv ("TERM");
  return t && strcmp (t, "dumb") != 0;
}

It's very simple. Think this would work for us?

nateozem added a commit to nateozem/clap-rs that referenced this issue May 17, 2017

kbknapp added a commit that referenced this issue May 29, 2017

@kbknapp kbknapp modified the milestones: 2.21.0, v3-alpha1 Feb 2, 2018

@kbknapp kbknapp added W: 3.x and removed W: 3.x blocker labels Feb 5, 2018

@kbknapp kbknapp modified the milestones: v3-alpha.1, v3-beta.1 Jul 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment