diff --git a/README.md b/README.md index 5bb9d18..4811a5e 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,7 @@ This is a TUI (Text User Interface) image editor, inspired by MS Paint, built wi - File formats, chosen by typing a file extension in the Save As dialog: - [x] ANSI (.ans) — Note that while it handles many more ANSI control codes when loading than those that it uses to save files, you may have limited success loading other ANSI files that you find on the web, or create with other tools. ANSI files can vary a lot and even encode animations! - [x] Plain Text (.txt) — discards color information - - [x] SVG (.svg) — mainly save only; can open SVGs saved by Textual Paint, but it's not a perfect round-trip - - wide characters are treated as one cell wide when opening, leading to shifting of cells to the right - - beware opening large documents saved as SVG, as it gets exponentially slower with size - - note that for fun, as a challenge, I made it quite flexible; it can handle uneven grids of unsorted rectangles (but probably to fix the performance, I'll make it more strict) + - [x] SVG (.svg) — can open SVGs saved by Textual Paint, which embed ANSI data; can also open some other SVGs that consist of a grid of rectangles and text elements. For fun, as a challenge, I made it quite flexible; it can handle uneven grids of unsorted rectangles. But that's only used as a fallback, because it's not perfect. - [x] HTML (.html) — save only - [x] PNG (.png) - [x] Bitmap (.bmp) diff --git a/cspell.json b/cspell.json index a476204..b24b16b 100644 --- a/cspell.json +++ b/cspell.json @@ -100,6 +100,7 @@ "truecolor", "tspan", "tspans", + "txtpnt", "ufeff", "undoable", "undos", diff --git a/src/textual_paint/paint.py b/src/textual_paint/paint.py index ace464c..23e1241 100755 --- a/src/textual_paint/paint.py +++ b/src/textual_paint/paint.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import base64 +import html import io import os from pathlib import Path @@ -574,11 +576,19 @@ assert ansi_detector_pattern.search("\x80") is None, "Ç (in CP 437) or € (U+0 # This SVG template is based on the template in rich/_export_format.py # It removes the simulated window frame, and crops the SVG to just the terminal content. +# It also adds a placeholder for ANSI data to be stored in the SVG, +# in order to support opening the file after saving it, in a perfectly lossless way. +# (I have also implemented a more general SVG loading mechanism, but it's now a fallback.) # It was very nice during development to automate saving a file as SVG: # textual run --dev "src.textual_paint.paint --restart-on-changes samples/ship.ans" --press ctrl+shift+s,.,s,v,g,enter # (The Ctrl+Shift+S shortcut doesn't work when actually trying it as a user, but it works to simulate it.) CUSTOM_CONSOLE_SVG_FORMAT = """\ - +