Skip to content
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

Turn off syntax highlighting of hy expressions by default #1510

Closed
vodik opened this issue Feb 15, 2018 · 5 comments
Closed

Turn off syntax highlighting of hy expressions by default #1510

vodik opened this issue Feb 15, 2018 · 5 comments

Comments

@vodik
Copy link
Contributor

vodik commented Feb 15, 2018

The pretty printing is nice, and having the basic syntax highlighting to emphasis opening and closing brackets for HyExpression and HyList is certainly cool.

But I'm looking at embedding hy support in some of my Python projects and the ANSI colour codes are leaking into error messages, making them less legible. This should be opt-in feature of the REPL, not a default.

@Kodiologist
Copy link
Member

See also #1429.

@gilch
Copy link
Member

gilch commented Feb 15, 2018

See also #1360. There are ways to turn this off, but if it wasn't the default, many users would never notice the feature even exists. That was my rationale for making pretty opt-out instead of opt-in. We could also perhaps add a command-line switch or environment variable to turn this off.

@vodik
Copy link
Contributor Author

vodik commented Feb 15, 2018

I think turning it on by default inside the REPL is great, but my concern is more so that it leaks outside the context and creates a something less readable. Hy objects will cross the Python boundry:

>>> foo = hy.HyExpression([hy.HySymbol('foo')])
>>> repr(foo)
"\x1b[33m\x1b[22mHyExpression\x1b[39m\x1b[22m\x1b[33m\x1b[22m([\x1b[39m\x1b[22m\n  HySymbol('foo')\x1b[33m\x1b[22m])\x1b[39m\x1b[22m"

What happens if I'm logging exceptions with context and there's a Hy expression? Now there's noise I have to strip out

Here's another example where it creates noise in pytest:

>       assert not hy.HyExpression([hy.HySymbol('foo')])
E       AssertionError: assert not HyExpression([\n  HySymbol('foo')])
E        +  where HyExpression([\n  HySymbol('foo')]) = <class 'hy.models.HyExpression'>([HySymbol('foo')])
E        +    where <class 'hy.models.HyExpression'> = <module 'hy' from '/home/simon/src/hy/hy/__init__.py'>.HyExpression

pytest correctly strips escape sequences, but the newline characters are literally printed and, imho, impede understanding. Because technically we're abusing repr.

And looking at #1360, @kirbyfan64 properly points out this:

Python reprs that are known to not round trip are conventionally contained in <>, for example:

But the escape sequences prevent round tripping from working.

@gilch
Copy link
Member

gilch commented Mar 21, 2018

I think turning it on by default inside the REPL is great

So, how do you want this to work?

It does round-trip if you copy-paste in most terminals, since the coloring doesn't make it into the system clipboard. This is the usual use case for round-tripping. You can also strip the color codes programmatically using clint if you need to eval a string repr for some reason. But this seems rarely useful.

In your Python repr example, you're using internal Hy models directly in a python repl. If you're creating Hy modules to be consumed from Python, you won't be exporting this stuff. Even then, making it readable in the console is as simple as >>> print(repr(foo)).

I said before that managing this kind of thing would be easier with dynamic vars hylang/hyrule#51. But until that's implemented we have to settle for a module-level global. We could have hy.models.PRETTY off by default, but make the repl turn it on upon startup.

Hy doesn't have a debugger of its own, but is mostly compatible with pdb, so it would be nice if the Hy model reprs were pretty there too.

Repl startup activation would prevent the Python repl from getting the pretty reprs. But it might also prevent certain uses of pdb. You can turn it back on every time, of course, but this is inconvenient. Hence my environment variable suggestion.

There might also be cases where we'd want to launch a Hy repl from a Python repl. #1323. The embedded Hy repl could also turn PRETTY on, but if you quit back to python, PRETTY would still be on. Maybe you could turn it off at exit. If it doesn't crash.

@gilch
Copy link
Member

gilch commented Mar 21, 2018

As for the Pytest example, pytest needs special instructions to find Hy files in the first place. Whatever setup code is doing that could also turn off PRETTY. But I don't know that it improves readability that much. For a simple '(foo), sure, but once it gets nested very deeply, you'd have to copy it out, paste into your editor and indent it manually to see the structure. It would be easier to leave PRETTY on, paste it into a string literal and print it at a repl.

brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 11, 2018
This commit refactors the exception/error classes and their handling, keeps Hy
source string and their originating file (if any) information closer to the
origin of an exception (so that calling code isn't responsible for annotating
exceptions), and provides minimally intrusive traceback print-out filtering via
a context manager that temporarily alters `sys.excepthook`.

It also provides an environment variable, `HY_COLORED_ERRORS`, and package
variable, `hy.errors.__colored_errors`, that enables/disables manual error
coloring.

Closes hylang#657, closes hylang#1510, closes hylang#1429.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 11, 2018
This commit refactors the exception/error classes and their handling, keeps Hy
source strings and their originating file (if any) information closer to the
origin of an exception (so that calling code isn't responsible for annotating
exceptions), and provides minimally intrusive traceback print-out filtering via
a context manager that temporarily alters `sys.excepthook` (enabled by default
for the Hy interpreter).

It also provides an environment variable, `HY_COLORED_ERRORS`, and package
variable, `hy.errors.__colored_errors`, that enables/disables manual error
coloring.

Closes hylang#657, closes hylang#1510, closes hylang#1429.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 11, 2018
This commit refactors the exception/error classes and their handling, keeps Hy
source strings and their originating file information (if any) closer to the
origin of an exception (so that calling code isn't responsible for annotating
exceptions), and provides minimally intrusive traceback print-out filtering via
a context manager that temporarily alters `sys.excepthook` (enabled by default
for the Hy interpreter).

It also provides an environment variable, `HY_COLORED_ERRORS`, and package
variable, `hy.errors.__colored_errors`, that enables/disables manual error
coloring.

Closes hylang#657, closes hylang#1510, closes hylang#1429.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 13, 2018
This commit refactors the exception/error classes and their handling, keeps Hy
source strings and their originating file information (if any) closer to the
origin of an exception (so that calling code isn't responsible for annotating
exceptions), and provides minimally intrusive traceback print-out filtering via
a context manager that temporarily alters `sys.excepthook` (enabled by default
for the Hy interpreter).

It also provides an environment variable, `HY_COLORED_ERRORS`, and package
variable, `hy.errors.__colored_errors`, that enables/disables manual error
coloring.

Closes hylang#657, closes hylang#1510, closes hylang#1429.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 13, 2018
This commit refactors the exception/error classes and their handling, keeps Hy
source strings and their originating file information (if any) closer to the
origin of an exception (so that calling code isn't responsible for annotating
exceptions), and provides minimally intrusive traceback print-out filtering via
a context manager that temporarily alters `sys.excepthook` (enabled by default
for the Hy interpreter).

It also provides an environment variable, `HY_COLORED_ERRORS`, and package
variable, `hy.errors.__colored_errors`, that enables/disables manual error
coloring.

Closes hylang#657, closes hylang#1510, closes hylang#1429.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 14, 2018
This commit refactors the exception/error classes and their handling, keeps Hy
source strings and their originating file information (if any) closer to the
origin of an exception (so that calling code isn't responsible for annotating
exceptions), and provides minimally intrusive traceback print-out filtering via
a context manager that temporarily alters `sys.excepthook` (enabled by default
for the Hy interpreter).

It also provides an environment variable, `HY_COLORED_ERRORS`, and package
variable, `hy.errors.__colored_errors`, that enables/disables manual error
coloring.

Closes hylang#657, closes hylang#1510, closes hylang#1429.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 17, 2018
This commit refactors the exception/error classes and their handling, keeps Hy
source strings and their originating file information (if any) closer to the
origin of an exception (so that calling code isn't responsible for annotating
exceptions), and provides minimally intrusive traceback print-out filtering via
a context manager that temporarily alters `sys.excepthook` (enabled by default
for the Hy interpreter).

It also provides an environment variable, `HY_COLORED_ERRORS`, and package
variable, `hy.errors.__colored_errors`, that enables/disables manual error
coloring.

Closes hylang#657, closes hylang#1510, closes hylang#1429.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 28, 2018
This commit refactors the exception/error classes and their handling, keeps Hy
source strings and their originating file information (if any) closer to the
origin of an exception (so that calling code isn't responsible for annotating
exceptions), and provides minimally intrusive traceback print-out filtering via
a context manager that temporarily alters `sys.excepthook` (enabled by default
for the Hy interpreter).

It also provides an environment variable, `HY_COLORED_ERRORS`, and package
variable, `hy.errors.__colored_errors`, that enables/disables manual error
coloring.

Closes hylang#657, closes hylang#1510, closes hylang#1429.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 29, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 29, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Oct 30, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 1, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 10, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 28, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 29, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Dec 1, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Dec 2, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Dec 7, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
Kodiologist pushed a commit to brandonwillard/hy that referenced this issue Dec 8, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
Kodiologist pushed a commit to brandonwillard/hy that referenced this issue Dec 12, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_FILTER_INTERNAL_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Dec 17, 2018
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_COLORED_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Jan 17, 2019
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_COLORED_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
Kodiologist pushed a commit to Kodiologist/hy that referenced this issue Jan 20, 2019
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_COLORED_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
Kodiologist pushed a commit to Kodiologist/hy that referenced this issue Jan 26, 2019
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_COLORED_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang#1429, closes hylang#1510.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants