Skip to content

Crash when print ANSI escape code to color output text #915

Closed

Description

@arian-deimling

Tried printing out an ANSI escape sequence that changes the color of terminal output to red (see: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors), and it crashed. If I don't pass the end='' parameter to the print function, it works fine; looks like bpython was expecting the cursor to advance but only changing the color doesn't do that.

~ % bpython
bpython version 0.21 on top of Python 3.8.2 /Library/Developer/CommandLineTools/usr/bin/python3
>>> print('\033[91m', end='')

Traceback (most recent call last):
  File "/Users/arian/Library/Python/3.8/bin/bpython", line 8, in <module>
    sys.exit(main())
  File "/Users/arian/Library/Python/3.8/lib/python/site-packages/bpython/curtsies.py", line 201, in main
    exit_value = repl.mainloop(True, paste)
  File "/Users/arian/Library/Python/3.8/lib/python/site-packages/bpython/curtsies.py", line 121, in mainloop
    self.process_event_and_paint(e)
  File "/Users/arian/Library/Python/3.8/lib/python/site-packages/bpython/curtsies.py", line 95, in process_event_and_paint
    array, cursor_pos = self.paint()
  File "/Users/arian/Library/Python/3.8/lib/python/site-packages/bpython/curtsiesfrontend/repl.py", line 1610, in paint
    assert cursor_row >= 0 and cursor_column >= 0, (
AssertionError: (-1, 74, 9, 0, 0)

Activity

  1. arian-deimling commented on Sep 25, 2021

    @arian-deimling
    ContributorAuthor

    Can I work on this or are you going to?

  2. arian-deimling commented on Oct 2, 2021

    @arian-deimling
    ContributorAuthor

    Duplicate of #900.

  3. thomasballinger commented on Oct 7, 2021

    @thomasballinger
    Member

    @arian-deimling late to reply, but you're welcome to look. I suspect https://github.com/bpython/curtsies/blob/main/curtsies/escseqparse.py may be useful to look at, and that we may need to special case printing what we're going to treat as printing nothing.

  4. arian-deimling commented on Oct 7, 2021

    @arian-deimling
    ContributorAuthor

    @thomasballinger I'd be happy to look at this over the weekend. Do you want me to work on this or is there anything else that's more pressing?

  5. thomasballinger commented on Oct 7, 2021

    @thomasballinger
    Member

    This bug might even be the most pressing bug right now? It's been an issue for a long time though, so it's not urgent. It looks pretty involved, decisions made here about how we handle operationally blank output lines may have far-reaching effects.

    I'm starting on some mypy types, that's a potential thing to work on if that's fun. In the autocompletion vein, you could take a look at #889 or #897 or similar. I'm interested in #826, which is related to the escape codes issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions