mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-08-09 23:18:18 +02:00
Add new command line options --color and --no-color
This commit is contained in:
@ -6,9 +6,7 @@
|
|||||||
boxes \- text mode box and comment drawing filter
|
boxes \- text mode box and comment drawing filter
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B boxes
|
.B boxes
|
||||||
[\-hlmrv] [\-a\ format] [\-d\ design] [\-e\ eol] [\-f\ file] [\-i\ indent]
|
[options] [infile [outfile]]
|
||||||
[\-k\ bool] [\-n\ encoding] [\-p\ pad] [\-q query] [\-s\ size] [\-t\ tabopts]
|
|
||||||
[infile [outfile]]
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.I Boxes
|
.I Boxes
|
||||||
is a text filter which can draw any kind of box around its input text. Box
|
is a text filter which can draw any kind of box around its input text. Box
|
||||||
@ -33,7 +31,7 @@ Options offered by
|
|||||||
.I boxes
|
.I boxes
|
||||||
are the following:
|
are the following:
|
||||||
.TP 0.6i
|
.TP 0.6i
|
||||||
\fB\-a\fP \fIstring\fP, \fB\-\-align\fP=\fIstring\fP
|
\fB\-a\fP \fIformat\fP, \fB\-\-align\fP=\fIformat\fP
|
||||||
Alignment/positioning of text inside box. This option takes a format string
|
Alignment/positioning of text inside box. This option takes a format string
|
||||||
argument which is read from left to right. The format string may not
|
argument which is read from left to right. The format string may not
|
||||||
contain whitespace and must consist of one or more of the following
|
contain whitespace and must consist of one or more of the following
|
||||||
@ -127,6 +125,30 @@ may of course be used in conjunction with any of the other options. By default,
|
|||||||
is not specified.
|
is not specified.
|
||||||
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
.TP 0.6i
|
.TP 0.6i
|
||||||
|
\fB\-\-color\fP, \fB\-\-no\-color\fP
|
||||||
|
Printing of color codes. Box designs and the text inside a box may contain ANSI
|
||||||
|
color codes, sometimes called "escape sequences". In this way, boxes and text
|
||||||
|
can be colored.
|
||||||
|
.br
|
||||||
|
Whether these escape sequences are printed by
|
||||||
|
.I boxes
|
||||||
|
is normally determined by the terminal capabilities (default). Using
|
||||||
|
\fB\-\-color\fP,
|
||||||
|
.I boxes
|
||||||
|
can be told to always output escape sequences even if it thinks the terminal
|
||||||
|
may not understand them. Using \fB\-\-no\-color\fP, escape sequences will
|
||||||
|
never be printed.
|
||||||
|
|
||||||
|
Of course, even with
|
||||||
|
.B \-\-color\fP,
|
||||||
|
a box will only appear colored if it is already defined with colors. In case
|
||||||
|
you want to auto-color some text that isn't yet, take a look at
|
||||||
|
.I lolcat\fP.
|
||||||
|
.br
|
||||||
|
These options consider all escape sequences to be color codes. Any other
|
||||||
|
escape sequences present will be printed or removed along with the color codes.
|
||||||
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
.TP 0.6i
|
||||||
\fB\-d\fP \fIstring\fP, \fB\-\-design\fP=\fIstring\fP
|
\fB\-d\fP \fIstring\fP, \fB\-\-design\fP=\fIstring\fP
|
||||||
Design selection. The one argument of this option is the name of the design to
|
Design selection. The one argument of this option is the name of the design to
|
||||||
use, which may either be a design's primary name or any of its alias names.
|
use, which may either be a design's primary name or any of its alias names.
|
||||||
@ -312,10 +334,12 @@ influence the box size (such as
|
|||||||
By default, the smallest possible box is created around the text.
|
By default, the smallest possible box is created around the text.
|
||||||
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
.TP 0.6i
|
.TP 0.6i
|
||||||
\fB\-t\fP \fIstring\fP, \fB\-\-tabs\fP=\fIstring\fP
|
\fB\-t\fP \fItabopts\fP, \fB\-\-tabs\fP=\fItabopts\fP
|
||||||
Tab handling. This option controls how tab characters in the input text are
|
Tab handling. This option controls how tab characters in the input text are
|
||||||
handled. The option string must always begin with a positive integer number
|
handled. The
|
||||||
indicating the distance between tab stops, sometimes called "spaces per tab".
|
.I tabopts
|
||||||
|
must always begin with a positive integer number indicating the distance
|
||||||
|
between tab stops, sometimes called "spaces per tab".
|
||||||
.br
|
.br
|
||||||
Immediately following the tab distance, an optional character can be appended,
|
Immediately following the tab distance, an optional character can be appended,
|
||||||
telling
|
telling
|
||||||
|
@ -84,6 +84,8 @@ void usage_long(FILE *st)
|
|||||||
fprintf(st, "Usage: %s [options] [infile [outfile]]\n", PROJECT);
|
fprintf(st, "Usage: %s [options] [infile [outfile]]\n", PROJECT);
|
||||||
fprintf(st, " -a, --align <fmt> Alignment/positioning of text inside box [default: hlvt]\n");
|
fprintf(st, " -a, --align <fmt> Alignment/positioning of text inside box [default: hlvt]\n");
|
||||||
fprintf(st, " -c, --create <str> Use single shape box design where str is the W shape\n");
|
fprintf(st, " -c, --create <str> Use single shape box design where str is the W shape\n");
|
||||||
|
fprintf(st, " --color Force output of ANSI sequences if present\n");
|
||||||
|
fprintf(st, " --no-color Force monochrome output (no ANSI sequences)\n");
|
||||||
fprintf(st, " -d, --design <name> Box design [default: first one in file]\n");
|
fprintf(st, " -d, --design <name> Box design [default: first one in file]\n");
|
||||||
fprintf(st, " -e, --eol <eol> Override line break type (experimental) [default: %s]\n",
|
fprintf(st, " -e, --eol <eol> Override line break type (experimental) [default: %s]\n",
|
||||||
strcmp(EOL_DEFAULT, "\r\n") == 0 ? "CRLF" : "LF");
|
strcmp(EOL_DEFAULT, "\r\n") == 0 ? "CRLF" : "LF");
|
||||||
@ -588,6 +590,7 @@ static void print_debug_info(opt_t *result)
|
|||||||
result->halign ? result->halign : '?', result->valign ? result->valign : '?');
|
result->halign ? result->halign : '?', result->valign ? result->valign : '?');
|
||||||
fprintf (stderr, "- Line justification (-a): \'%c\'\n", result->justify ? result->justify : '?');
|
fprintf (stderr, "- Line justification (-a): \'%c\'\n", result->justify ? result->justify : '?');
|
||||||
fprintf (stderr, "- Design Definition W shape (-c): %s\n", result->cld ? result->cld : "n/a");
|
fprintf (stderr, "- Design Definition W shape (-c): %s\n", result->cld ? result->cld : "n/a");
|
||||||
|
fprintf (stderr, "- Color mode: %d\n", result->color);
|
||||||
fprintf (stderr, "- Line terminator used (-e): %s\n",
|
fprintf (stderr, "- Line terminator used (-e): %s\n",
|
||||||
strcmp(result->eol, "\r\n") == 0 ? "CRLF" : (strcmp(result->eol, "\r") == 0 ? "CR" : "LF"));
|
strcmp(result->eol, "\r\n") == 0 ? "CRLF" : (strcmp(result->eol, "\r") == 0 ? "CR" : "LF"));
|
||||||
fprintf (stderr, "- Explicit config file (-f): %s\n", result->f ? result->f : "no");
|
fprintf (stderr, "- Explicit config file (-f): %s\n", result->f ? result->f : "no");
|
||||||
@ -639,6 +642,8 @@ opt_t *process_commandline(int argc, char *argv[])
|
|||||||
const struct option long_options[] = {
|
const struct option long_options[] = {
|
||||||
{ "align", required_argument, NULL, 'a' },
|
{ "align", required_argument, NULL, 'a' },
|
||||||
{ "create", required_argument, NULL, 'c' },
|
{ "create", required_argument, NULL, 'c' },
|
||||||
|
{ "color", no_argument, NULL, OPT_COLOR },
|
||||||
|
{ "no-color", no_argument, NULL, OPT_NO_COLOR },
|
||||||
{ "design", required_argument, NULL, 'd' },
|
{ "design", required_argument, NULL, 'd' },
|
||||||
{ "eol", required_argument, NULL, 'e' },
|
{ "eol", required_argument, NULL, 'e' },
|
||||||
{ "config", required_argument, NULL, 'f' },
|
{ "config", required_argument, NULL, 'f' },
|
||||||
@ -677,6 +682,14 @@ opt_t *process_commandline(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPT_COLOR:
|
||||||
|
result->color = force_ansi_color;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPT_NO_COLOR:
|
||||||
|
result->color = force_monochrome;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
if (design_choice(result, optarg) != 0) {
|
if (design_choice(result, optarg) != 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
/*
|
/*
|
||||||
* Some ints that define return values for getopt_long() to indicate certain long options.
|
* Some ints that define return values for getopt_long() to indicate certain long options.
|
||||||
*/
|
*/
|
||||||
|
#define OPT_COLOR 1001
|
||||||
|
#define OPT_NO_COLOR 1002
|
||||||
#define OPT_KILLBLANK 1003
|
#define OPT_KILLBLANK 1003
|
||||||
#define OPT_NO_KILLBLANK 1004
|
#define OPT_NO_KILLBLANK 1004
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user