🎨 MS Paint in your terminal.
Go to file
2023-04-17 03:12:30 -04:00
.vscode Add dev helper to inspect layout 2023-04-17 01:21:19 -04:00
__init__.py Add non-functional menu bar 2023-04-12 20:54:21 -04:00
.gitattributes Initial commit 2023-04-10 16:51:39 -04:00
.gitignore Initial commit 2023-04-10 16:51:39 -04:00
cspell.json Update development section 2023-04-16 19:23:00 -04:00
LICENSE.txt Initial commit 2023-04-10 16:51:39 -04:00
menus.py Fix AttributeError for "parent_menu.focus" for menu bar (top level menu) 2023-04-15 23:50:45 -04:00
paint.css Let menu buttons vary in width 2023-04-16 20:35:09 -04:00
paint.py Ctrl+MMB to colorize without adding borders to inspect layout without modifying it 2023-04-17 03:12:30 -04:00
README.md Note parallelogram candidates for eraser icon 2023-04-17 01:57:27 -04:00
requirements.txt Save and load ANSI files 2023-04-11 21:18:11 -04:00
screenshot.svg Apply SVG fix-up script (contained in the SVG) 2023-04-14 19:15:45 -04:00
windows.py Submit dialogs with enter, unless a button has focus 2023-04-16 02:03:28 -04:00

Textual Paint

MS Paint in your terminal.

This is a TUI (Text User Interface) image editor, inspired by MS Paint, built with Textual.

MS Paint like interface
This screenshot of Textual Paint is the terminal's screen buffer copied as HTML, wrapped in SVG, placed in HTML inside Markdown.
This might not render correctly in your browser.

Features

  • Open and save images
    • PNG (.png)
    • Bitmap (.bmp)
    • ANSI (.ans)
      • only supports loading files saved by this program; ANSI files can vary a lot and even encode animations
  • Tools
    • Free-Form Select
    • Rectangular Select
    • Eraser
      • Color Eraser
    • Fill With Color
    • Pick Color
    • Magnifier
    • Pencil
    • Brush
    • Airbrush
    • Text
    • Line
    • Curve
    • Rectangle
    • Polygon
    • Ellipse
    • Rounded Rectangle
  • Color palette
  • Undo/Redo
  • Efficient screen updates and undo/redo history, by tracking regions affected by each action
    • You could totally use this program over SSH! Haha, this "what if" project could actually be useful. Of course, it should be mentioned that you can also run graphical programs over SSH, but this might be more responsive, or just fit your vibe better.
  • Brush previews
  • Menu bar

Usage

Command Line Options

$ python3 paint.py --help
usage: paint.py [-h] [--theme THEME] [--ascii-only-icons] [--inspect-layout] [--clear-screen] [filename]

Paint in the terminal.

positional arguments:
  filename            File to open

options:
  -h, --help          show this help message and exit
  --theme THEME       Theme to use, either "light" or "dark"
  --ascii-only-icons  Use only ASCII characters for tool icons
  --inspect-layout    Inspect the layout with middle click, for development
  --clear-screen      Clear the screen before starting; useful for development, to avoid seeing fixed errors

Keyboard Shortcuts

  • Ctrl+D: Toggle Dark Mode
  • Ctrl+Q: Quit
  • Ctrl+Shift+S: Save As IF SHIFT IS DETECTED — might trigger Save instead, and overwrite the open file! ⚠️
  • Ctrl+Shift+Z: Redo IF SHIFT IS DETECTED — might trigger Undo instead.

The rest match MS Paint's keyboard shortcuts:

  • Ctrl+S: Save
  • Ctrl+O: Open
  • Ctrl+N: New
  • Ctrl+T: Toggle Tools Box
  • Ctrl+W: Toggle Colors Box
  • Ctrl+Z: Undo
  • Ctrl+Y: Redo
  • F4: Redo

Development

Install Textual and Stransi:

pip install "textual[dev]" "stransi"

Run via Textual's CLI for live-reloading CSS support:

textual run --dev "paint.py --clear-screen"

Or run more basically:

python paint.py --clear-screen

--clear-screen is useful for development, because it's sometimes jarring to see error messages that have actually been fixed, when exiting the program.

There are also launch tasks configured for VS Code, so you can run the program from the Run and Debug panel.

I tried running via modd to automatically reload the program when (non-CSS) files change, but it doesn't handle ANSI escape sequences well. I wonder if it would work better now with the --clear-screen option. (I could also look for another tool that's more part of the Python ecosystem.)

License

MIT

Unicode Symbols and Emojis for Paint Tools

The first thing I did in this project was to collect possible characters to represent all the tool icons in MS Paint, to gauge how good of a recreation it would be possible to achieve, starting from looks. Unfortunately, I haven't run into any significant roadblocks, so I'm apparently recreating MS Paint. Again.

These are the symbols I've found so far:

  • Free-Form Select: ✂️📐🆓🕸🫥🇫/🇸◌⁛⁘ ⢼⠮
  • Rectangular Select: ⬚▧🔲 ⣏⣹
  • Eraser/Color Eraser: 🧼🧽🧹🚫👋🗑️▰▱
  • Fill With Color: 🌊💦💧🌈🎉🎊🪣🫗
  • Pick Color: 🎨💉💅💧📌📍⤤𝀃🝯🍶
  • Magnifier: 🔍🔎👀🔬🔭🧐🕵️‍♂️🕵️‍♀️
  • Pencil: ✏️✍️🖎🖊️🖋️✒️🖆📝🖍️
  • Brush: 🖌️🖌👨‍🎨🧑‍🎨💅
  • Airbrush: 💨ᖜ╔🧴🥤🫠
  • Text: 🆎📝📄📃🔤📜A
  • Line: 📏📉📈⟍𝈏╲⧹\
  • Curve: ↪️🪝🌙〰️◡◠~∼≈∽∿〜〰﹋﹏≈≋~⁓
  • Rectangle: ▭▬▮▯🟥🟧🟨🟩🟦🟪🟫◼️◻️▪️▫️
  • Polygon: ▙𝗟𝙇﹄』⬣⬟🔶🔷🔸🔹🔺🔻△▲
  • Ellipse: ⬭🔴🟠🟡🟢🔵🟣🟤🫧
  • Rounded Rectangle: ▢

The default symbols used may not be the best on your particular system, so I may add some kind of configuration for this in the future.

Cursor

A crosshair cursor could use one of +✜✛✚╋╬, but whilst that imitates the look, it might be better to show the pixel under the cursor, i.e. character cell, surrounded by dashes, like this:

 ╻
╺█╸
 ╹

See Also

  • JavE, an advanced Java-based ASCII art editor
  • Playscii, a beautiful ASCII/ANSI art editor
  • cmdpxl, a pixel art editor for the terminal using the keyboard
  • pypixelart, a pixel art editor using vim-like keybindings, inspired by cmdpxl but not terminal-based