[equo] add --color option, see bug #2381

This commit is contained in:
Fabio Erculiani
2011-04-29 17:12:13 +02:00
parent bc63e0fee8
commit 41f816ea9f
3 changed files with 17 additions and 6 deletions

View File

@@ -55,10 +55,6 @@ etp_exit_messages = {
7: _("Go to hell."),
}
# Check if we need to disable colors
if not is_stdout_a_tty():
nocolor()
help_opts = [
None,
(0, " ~ %s ~ " % ("equo",), 2,
@@ -69,6 +65,7 @@ help_opts = [
(1, '--help', 2, _('this output')),
(1, '--version', 1, _('print version')),
(1, '--nocolor', 1, _('disable colorized output')),
(1, '--color', 2, _('force colorized output')),
(1, '--bashcomp', 1, _('print a bash completion script to stdout')),
None,
(0, _('Application Options'), 0, None),
@@ -773,9 +770,12 @@ for n in range(len(options)):
options.extend(x_found_opts)
bashcomp_enabled = False
force_color = False
for opt in options:
if opt in ["--nocolor", "-N"]:
nocolor()
elif opt in ["--color", "-C"]:
force_color = True
elif opt == "--debug":
continue
elif opt in ["--quiet", "-q"]:
@@ -796,6 +796,10 @@ for opt in options:
_options.append(opt)
options = _options
# Check if we need to disable colors
if (not force_color) and (not is_stdout_a_tty()):
nocolor()
if bashcomp_enabled:
print_bashcomp(help_opts + help_opts_extended, options, BASHCOMP_MAP)
raise SystemExit(0)

View File

@@ -47,6 +47,10 @@ print version
disable colorized output
=item B<--color>
force colorized output
=item [1] B<--bashcomp>
print a bash completion script to stdout

View File

@@ -123,8 +123,8 @@
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "A 1"
.TH A 1 "2011-04-05" "perl v5.12.2" "User Contributed Perl Documentation"
.IX Title "EQUO 1"
.TH EQUO 1 "2011-04-29" "perl v5.12.2" "Entropy"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -168,6 +168,9 @@ print version
.IP "[1] \fB\-\-nocolor\fR" 4
.IX Item "[1] --nocolor"
disable colorized output
.IP "\fB\-\-color\fR" 4
.IX Item "--color"
force colorized output
.IP "[1] \fB\-\-bashcomp\fR" 4
.IX Item "[1] --bashcomp"
print a bash completion script to stdout