Skip to content

chafa images won't open by defaultΒ #12

@bitplane

Description

@bitplane

steps

  1. chafa some_file.png > output.ans
  2. textual-paint output.ans

example file

what happened?

Crash

Traceback (most recent call last):
  File "/home/gaz/πŸ’»/lib/python3.12/site-packages/textual_paint/paint.py", line 1154, in open_from_file_path
    go_ahead()
  File "/home/gaz/πŸ’»/lib/python3.12/site-packages/textual_paint/paint.py", line 1122, in go_ahead
    new_image = AnsiArtDocument.decode_based_on_file_extension(content, file_path)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gaz/πŸ’»/lib/python3.12/site-packages/textual_paint/ansi_art_document.py", line 1048, in decode_based_on_file_extension
    return AnsiArtDocument.from_ansi(content.decode("utf-8"), default_bg, default_fg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gaz/πŸ’»/lib/python3.12/site-packages/textual_paint/ansi_art_document.py", line 499, in from_ansi
    for instruction in ansi.instructions():
                        ^^^^^^^^^^^^^^^^^
  File "/home/gaz/πŸ’»/lib/python3.12/site-packages/stransi/ansi.py", line 50, in instructions
    yield from escape.instructions()
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/gaz/πŸ’»/lib/python3.12/site-packages/stransi/escape.py", line 58, in instructions
    while token := next(tokens, None):
                   ^^^^^^^^^^^^^^^^^^
  File "/home/gaz/πŸ’»/lib/python3.12/site-packages/stransi/escape.py", line 42, in tokens
    yield Token(kind=kind, data=int(param))
                                 ^^^^^^^^^

ValueError: invalid literal for int() with base 10: '?25'

An unexpected error occurred while reading:
/home/gaz/src/bitplane.net/~/doc/thoughts/lens/words/src/1.1.library.ans

Why?

chafa turns the cursor off when it draws and on again afterwards:

  • ^[[?25l (hide)
  • ^[[?25h (show)

stransi tries to int('?25') and fails. This bug and fix have been open for a while, so it might be better to filter here or patch it or something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions