sapling/tests/test-fb-hgext-morecolors.t
Mark Thomas 60e99a245c ui: add labelled prefixes to ui.write
Summary:
Add optional prefix keyword arguments to `ui.write` (and thus `ui.status`,
`ui.warn`, etc.).  These prefixes can be used to indicate an error condition,
some notice to the user, or to mark a message as coming from a particular
component.  The prefixes are labelled so that they can be colored to stand
out from the surrounding text.  The default colors are red for errors, yellow
for notices, and cyan for components.

Add a component parameter to `error.Abort` (and thus any exception that
inherits from it) that can be used by callers to mark which component is
responsible for the exception.   When the error is printed, the component is
passed as the component prefix of the error message.

Reviewed By: mitrandir77

Differential Revision: D15201946

fbshipit-source-id: 02e3da40e9563704fa1d7ce81366e6e7f66c7f34
2019-05-09 06:55:11 -07:00

40 lines
1.1 KiB
Perl

$ cat >> $HGRCPATH << EOF
> [extensions]
> morecolors=
> [ui]
> color=always
> [color]
> mode=ansi
> EOF
Traceback has color:
$ cat > repocrash.py << EOF
> from edenscm.mercurial import error
> def reposetup(ui, repo):
> raise error.Abort('.')
> EOF
$ hg init repo1
$ cd repo1
$ hg commit --config extensions.repocrash=$TESTTMP/repocrash.py --traceback 2>&1 | egrep -v '^ '
Traceback (most recent call last):
\x1b[0;31;1m File "$TESTTMP/repocrash.py", line 3, in reposetup\x1b[0m (esc)
\x1b[0;31;1m raise error.Abort('.')\x1b[0m (esc)
\x1b[0;31;1mAbort: .\x1b[0m (esc)
\x1b[0;91mabort:\x1b[0m . (esc)
Uncaught exception has color:
$ cat > $TESTTMP/uncaughtcrash.py <<EOF
> def reposetup(ui, repo):
> raise RuntimeError('.')
> EOF
$ hg commit --config extensions.repocrash=$TESTTMP/uncaughtcrash.py 2>&1 | egrep -v '^ '
Traceback (most recent call last):
\x1b[0;31;1m File "$TESTTMP/uncaughtcrash.py", line 2, in reposetup\x1b[0m (esc)
\x1b[0;31;1m raise RuntimeError('.')\x1b[0m (esc)
\x1b[0;31;1mRuntimeError: .\x1b[0m (esc)