Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add the global --color option to control output of color VT escapes to CLI, similar to `ls', `grep' and other utilities. Useful when piping `fossil search' results through a pager utility. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | standard-cli-colors |
| Files: | files | file ages | folders |
| SHA3-256: |
210b7d2fe0bd4ae9dd3da6607bb7e963 |
| User & Date: | florian 2025-04-18 07:16:00.000 |
Context
|
2025-04-18
| ||
| 07:19 | Add support for the FOSSIL_COLOR environment variable to define the color VT escape to highlight CLI text, also similar to `ls', `grep' and other utilities. ... (check-in: 50e0931bc7 user: florian tags: standard-cli-colors) | |
| 07:16 | Add the global --color option to control output of color VT escapes to CLI, similar to `ls', `grep' and other utilities. Useful when piping `fossil search' results through a pager utility. ... (check-in: 210b7d2fe0 user: florian tags: standard-cli-colors) | |
| 07:08 | Amend [2b6ad00ea3]: Minor wording improvements to `fossil ssl-config show -v' output. ... (check-in: a9b075af83 user: florian tags: trunk) | |
Changes
Changes to src/dispatch.c.
| ︙ | ︙ | |||
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 | static const char zOptions[] = @ Command-line options common to all commands: @ @ --args FILENAME Read additional arguments and options from FILENAME @ --case-sensitive BOOL Set case sensitivity for file names @ --cgitrace Active CGI tracing @ --chdir PATH Change to PATH before performing any operations @ --errorlog FILENAME Log errors to FILENAME @ --help Show help on the command rather than running it @ --httptrace Trace outbound HTTP requests @ --localtime Display times using the local timezone @ --nocgi Do not act as CGI @ --no-th-hook Do not run TH1 hooks @ --quiet Reduce the amount of output | > | 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 | static const char zOptions[] = @ Command-line options common to all commands: @ @ --args FILENAME Read additional arguments and options from FILENAME @ --case-sensitive BOOL Set case sensitivity for file names @ --cgitrace Active CGI tracing @ --chdir PATH Change to PATH before performing any operations @ --color WHEN Emit VT color escapes: 'never', 'always', or 'auto' @ --errorlog FILENAME Log errors to FILENAME @ --help Show help on the command rather than running it @ --httptrace Trace outbound HTTP requests @ --localtime Display times using the local timezone @ --nocgi Do not act as CGI @ --no-th-hook Do not run TH1 hooks @ --quiet Reduce the amount of output |
| ︙ | ︙ |
Changes to src/main.c.
| ︙ | ︙ | |||
233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
const char *zPidKey; /* Saved value of the --usepidkey option. Only
* applicable when using SEE on Windows or Linux. */
#endif
int useLocalauth; /* No login required if from 127.0.0.1 */
int noPswd; /* Logged in without password (on 127.0.0.1) */
int userUid; /* Integer user id */
int isHuman; /* True if access by a human, not a spider or bot */
int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be
** accessed through get_comment_format(). */
const char *zSockName; /* Name of the unix-domain socket file */
const char *zSockMode; /* File permissions for unix-domain socket */
const char *zSockOwner; /* Owner, or owner:group for unix-domain socket */
/* Information used to populate the RCVFROM table */
| > | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
const char *zPidKey; /* Saved value of the --usepidkey option. Only
* applicable when using SEE on Windows or Linux. */
#endif
int useLocalauth; /* No login required if from 127.0.0.1 */
int noPswd; /* Logged in without password (on 127.0.0.1) */
int userUid; /* Integer user id */
int isHuman; /* True if access by a human, not a spider or bot */
int colorOutput; /* Control output of color VT escapes to CLI */
int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be
** accessed through get_comment_format(). */
const char *zSockName; /* Name of the unix-domain socket file */
const char *zSockMode; /* File permissions for unix-domain socket */
const char *zSockOwner; /* Owner, or owner:group for unix-domain socket */
/* Information used to populate the RCVFROM table */
|
| ︙ | ︙ | |||
637 638 639 640 641 642 643 |
}
}
fossil_warning("%s", blob_str(&msg));
blob_reset(&msg);
}
/*
| | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
}
}
fossil_warning("%s", blob_str(&msg));
blob_reset(&msg);
}
/*
** Initialize the g.comFmtFlags and g.colorOutput global variables.
**
** The global command-line options --comfmtflags or --comment-format to
** set the comment format are undocumented and deprecated, and are only
** for backwards compatibility.
**
** If the --color option isn't found, the NO_COLOR environment variable
** may disable colored output (but is otherwise trumped by the option).
*/
static void fossil_init_flags_from_options(void){
char *zEnvVar;
const char *zValue = find_option("comfmtflags", 0, 1);
if( zValue==0 ){
zValue = find_option("comment-format", 0, 1);
}
if( zValue ){
g.comFmtFlags = atoi(zValue);
}else{
g.comFmtFlags = COMMENT_PRINT_UNSET; /* Command-line option not found. */
}
g.colorOutput = COLOR_VT_UNSET;
zValue = find_option("color", 0, 1);
if( zValue ){
if( fossil_strcmp(zValue,"never")==0 ){
g.colorOutput = COLOR_VT_NEVER;
}
else if( fossil_strcmp(zValue,"always")==0 ){
g.colorOutput = COLOR_VT_ALWAYS;
}
else if( fossil_strcmp(zValue,"auto")==0 ){
g.colorOutput = COLOR_VT_AUTO;
}else{
fossil_fatal("the --color option must be 'never', 'always', or 'auto'");
}
}
if( g.colorOutput==COLOR_VT_UNSET ){
zEnvVar = fossil_getenv("NO_COLOR");
if( zEnvVar ){
if( is_false(zEnvVar) ){
g.colorOutput = COLOR_VT_NEVER;
}
fossil_path_free(zEnvVar);
}
}
}
/*
** Check to see if the Fossil binary contains an appended repository
** file using the appendvfs extension. If so, change command-line arguments
** to cause Fossil to launch with "fossil ui" on that repo.
|
| ︙ | ︙ |
Changes to src/terminal.c.
| ︙ | ︙ | |||
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/*
** Terminal size defined in terms of columns and lines.
*/
struct TerminalSize {
unsigned int nColumns; /* Number of characters on a single line */
unsigned int nLines; /* Number of lines */
};
#endif
/* Get the current terminal size by calling a system service.
**
** Return 1 on success. This sets the size parameters to the values retured by
** the system call, when such is supported; set the size to zero otherwise.
| > > > > > > > > | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
/*
** Terminal size defined in terms of columns and lines.
*/
struct TerminalSize {
unsigned int nColumns; /* Number of characters on a single line */
unsigned int nLines; /* Number of lines */
};
/*
** Values of g.ColorOutput to control output of color VT escapes to CLI.
*/
#define COLOR_VT_UNSET (-1) /* Not initialized. */
#define COLOR_VT_NEVER (0) /* Never emit color VT escapes. */
#define COLOR_VT_ALWAYS (1) /* Always emit color VT escapes. */
#define COLOR_VT_AUTO (2) /* Only emit color VT escapes on terminal. */
#endif
/* Get the current terminal size by calling a system service.
**
** Return 1 on success. This sets the size parameters to the values retured by
** the system call, when such is supported; set the size to zero otherwise.
|
| ︙ | ︙ | |||
141 142 143 144 145 146 147 |
fossil_print("%d %d\n", ts.nColumns, ts.nLines);
}
/*
** Return true if it is reasonable is emit VT100 escape codes.
*/
int terminal_is_vt100(void){
| | > > | | | < < | < | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
fossil_print("%d %d\n", ts.nColumns, ts.nLines);
}
/*
** Return true if it is reasonable is emit VT100 escape codes.
*/
int terminal_is_vt100(void){
if( g.colorOutput==COLOR_VT_NEVER) return 0;
if( g.colorOutput==COLOR_VT_ALWAYS) return 1;
/* Check the terminal if g.colorOutput is COLOR_VT_UNSET or COLOR_VT_AUTO. */
#ifdef _WIN32
return win32_terminal_is_vt100(1);
#else /* !_WIN32 */
return fossil_isatty(1);
#endif /* !_WIN32 */
return 0;
}
#ifdef _WIN32
/*
** Return true if the Windows console supports VT100 escape codes.
**
|
| ︙ | ︙ |
Changes to www/env-opts.md.
| ︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | most sensible condition. `--cgitrace`: Active CGI tracing. `--chdir DIRECTORY`: Change to the named directory before processing any commands. `--comfmtflags NUMBER`: Specify flags that control how check-in comments and certain other text outputs are formatted for display. The flags are individual bits in `NUMBER`, which must be specified in base 10: * _0_ — Uses the revised algorithm with no special handling. | > > > > > > > > > > > > > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
most sensible condition.
`--cgitrace`: Active CGI tracing.
`--chdir DIRECTORY`: Change to the named directory before processing
any commands.
`--color WHEN`: Control output of color VT escapes to CLI (supersedes
the `NO_COLOR` environment variable explained later in this document):
* _never_ — Never emit color VT escapes.
* _always_ — Always emit color VT escapes; useful when piping
Fossil command output through a pager utility.
* _auto_ — Only emit color VT escapes when output goes to a
terminal, and not if output is redirected to a pipe, a file, or any
other device.
`--comfmtflags NUMBER`: Specify flags that control how check-in comments
and certain other text outputs are formatted for display. The flags are
individual bits in `NUMBER`, which must be specified in base 10:
* _0_ — Uses the revised algorithm with no special handling.
|
| ︙ | ︙ | |||
228 229 230 231 232 233 234 235 236 237 238 239 240 241 | `LOGNAME`: Name of the logged in user on many Unix-like platforms. Used as the fossil user name if `FOSSIL_USER` is not specified. See the discussion of Fossil Username below for a lot more detail. `NO_COLOR`: If defined and not set to a `false` value (i.e. "off", "no", "false", "0"), the `fossil search` command skips colorization of console output using ANSI escape codes (VT100). `PATH`: Used by most platforms to locate programs invoked without a fully qualified name. Explicitly used by `fossil ui` on certain platforms to choose the browser to launch. `PATH_INFO`: If defined, included in error log messages. | > | 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | `LOGNAME`: Name of the logged in user on many Unix-like platforms. Used as the fossil user name if `FOSSIL_USER` is not specified. See the discussion of Fossil Username below for a lot more detail. `NO_COLOR`: If defined and not set to a `false` value (i.e. "off", "no", "false", "0"), the `fossil search` command skips colorization of console output using ANSI escape codes (VT100). Note the `--color` option takes precedence over the `NO_COLOR` variable. `PATH`: Used by most platforms to locate programs invoked without a fully qualified name. Explicitly used by `fossil ui` on certain platforms to choose the browser to launch. `PATH_INFO`: If defined, included in error log messages. |
| ︙ | ︙ |