From 4383a882ee4a20e967a4d1345b49766747d5b31a Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Thu, 20 Jul 2023 18:52:42 -0400 Subject: [PATCH] Use alternative tool icons for iTerm2 --- README.md | 8 ++------ src/textual_paint/paint.py | 31 ++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3b79ab4..a4a2adb 100644 --- a/README.md +++ b/README.md @@ -226,13 +226,9 @@ GNOME Terminal works best, with crisp triangles used for icons in dialogs, emoji Tested on OSX 10.14 (Mojave), with iTerm2, and VS Code's integrated terminal. -iTerm2 mostly works, but two tool icons are missing (Free-Form Select and Fill With Color). -They show as a square with a question mark in it, and may cause the rest of the row of characters to be misaligned, including the canvas. -(I carefully picked the symbols to avoid this on Ubuntu, so I may need to do the same for macOS, conditioning on the `TERM_PROGRAM` environment variable.) +In VS Code, Free-Form Select shows as tofu (a missing character symbol). -In VS Code, only Free-Form Select shows as tofu (a missing character symbol), and there's no misalignment. - -The default Terminal app has the same problems as iTerm2, plus borders are not rendered nicely, giving it a sort of *frayed fabric* look, and it's limited to 256 colors. +The default Terminal has missing characters, causing misalignment of everything to the right of them, plus borders are not rendered nicely, giving it a sort of *frayed fabric* look, and it's limited to 256 colors. ### Windows diff --git a/src/textual_paint/paint.py b/src/textual_paint/paint.py index 8b95187..ede9357 100755 --- a/src/textual_paint/paint.py +++ b/src/textual_paint/paint.py @@ -241,25 +241,34 @@ class Tool(Enum): Tool.rounded_rectangle: "(_)", # "(_)" ("(\x1B[53m_\x1B[55m)" doesn't work right, is there no overline tag?) } return enum_to_icon[self] + # Some glyphs cause misalignment of everything to the right of them, including the canvas, + # so alternative characters need to be chosen carefully for each platform. # "๐Ÿซ—" causes jutting out in Ubuntu terminal, "๐Ÿชฃ" causes the opposite in VS Code terminal # VS Code sets TERM_PROGRAM to "vscode", so we can use that to detect it - if os.environ.get("TERM_PROGRAM") == "vscode": - # fill_icon = "๐Ÿซ—" # is also hard to see in the light theme - fill_icon = "๐ŸŒŠ" # is a safe alternative - # fill_icon = "[on black]๐Ÿซ— [/]" # no way to make this not look like a selection highlight - # "โœ๏ธ" doesn't display in color in VS Code - pencil_icon = "๐Ÿ–๏ธ" # or "๐Ÿ–Š๏ธ", "๐Ÿ–‹๏ธ" - else: - fill_icon = "๐Ÿชฃ" - pencil_icon = "โœ๏ธ" + TERM_PROGRAM = os.environ.get("TERM_PROGRAM") + if TERM_PROGRAM == "vscode": + if self == Tool.fill: + # return "๐Ÿซ—" # is also hard to see in the light theme + return "๐ŸŒŠ" # is a safe alternative + # return "[on black]๐Ÿซ— [/]" # no way to make this not look like a selection highlight + if self == Tool.pencil: + # "โœ๏ธ" doesn't display in color in VS Code + return "๐Ÿ–๏ธ" # or "๐Ÿ–Š๏ธ", "๐Ÿ–‹๏ธ" + elif TERM_PROGRAM == "iTerm.app": + # ๐Ÿชฃ (Fill With Color) and โš (Free-Form Select) defaults are missing in iTerm2 on macOS 10.14 (Mojave) + # They show as a question mark in a box, and cause the rest of the row to be misaligned. + if self == Tool.fill: + return "๐ŸŒŠ" + if self == Tool.free_form_select: + return "โขผโ ฎ" return { Tool.free_form_select: "โš", Tool.select: "โฌš", Tool.eraser: "๐Ÿงผ", - Tool.fill: fill_icon, + Tool.fill: "๐Ÿชฃ", Tool.pick_color: "๐Ÿ’‰", Tool.magnifier: "๐Ÿ”", - Tool.pencil: pencil_icon, + Tool.pencil: "โœ๏ธ", Tool.brush: "๐Ÿ–Œ๏ธ", Tool.airbrush: "๐Ÿ’จ", Tool.text: "๏ผก",