mirror of
https://github.com/1j01/textual-paint.git
synced 2024-09-11 15:56:03 +03:00
Fix preventing icon swaps during pytest, for Windows Terminal and Kitty
If git blame tools were smarter/easier to use, or if I was using a node-based programming paradigm, I would've never made this mistake. I would have done the natural and correct thing in the first place, but instead, I tried to avoid indenting a large block of code, which generates a noisy commit, and a barrier when using git blame.
This commit is contained in:
parent
857e459b2d
commit
8cd164bb37
@ -67,72 +67,73 @@ 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
|
||||
# Don't swap out tool button icons when running in pytest, to avoid snapshot differences across platforms.
|
||||
TERM_PROGRAM = "pytest" if PYTEST else 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 "⢼⠮"
|
||||
elif os.environ.get("WT_SESSION"):
|
||||
# The new Windows Terminal app sets WT_SESSION to a GUID.
|
||||
# Caveats:
|
||||
# - If you run `cmd` inside WT, this env var will be inherited.
|
||||
# - If you run a GUI program that launches another terminal emulator, this env var will be inherited.
|
||||
# - If you run via ssh, using Microsoft's official openssh server, WT_SESSION will not be set.
|
||||
# - If you hold alt and right click in Windows Explorer, and say Open Powershell Here, WT_SESSION will not be set,
|
||||
# because powershell.exe is launched outside of the Terminal app, then later attached to it.
|
||||
# Source: https://github.com/microsoft/terminal/issues/11057
|
||||
if not PYTEST:
|
||||
# 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
|
||||
# Don't swap out tool button icons when running in pytest, to avoid snapshot differences across platforms.
|
||||
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 "⢼⠮"
|
||||
elif os.environ.get("WT_SESSION"):
|
||||
# The new Windows Terminal app sets WT_SESSION to a GUID.
|
||||
# Caveats:
|
||||
# - If you run `cmd` inside WT, this env var will be inherited.
|
||||
# - If you run a GUI program that launches another terminal emulator, this env var will be inherited.
|
||||
# - If you run via ssh, using Microsoft's official openssh server, WT_SESSION will not be set.
|
||||
# - If you hold alt and right click in Windows Explorer, and say Open Powershell Here, WT_SESSION will not be set,
|
||||
# because powershell.exe is launched outside of the Terminal app, then later attached to it.
|
||||
# Source: https://github.com/microsoft/terminal/issues/11057
|
||||
|
||||
# Windows Terminal has alignment problems with the default Pencil symbol "✏️"
|
||||
# as well as alternatives "🖍️", "🖊️", "🖋️", "✍️", "✒️"
|
||||
# "🖎" and "🖆" don't cause alignment issues, but don't show in color and are illegibly small.
|
||||
if self == Tool.pencil:
|
||||
# This looks more like it would represent the Text tool than the Pencil,
|
||||
# so it's far from ideal, especially when there IS an actual pencil emoji...
|
||||
return "📝"
|
||||
# "🖌️" is causes misalignment (and is hard to distinguish from "✏️" at a glance)
|
||||
# "🪮" shows as tofu
|
||||
if self == Tool.brush:
|
||||
return "🧹"
|
||||
# "🪣" shows as tofu
|
||||
if self == Tool.fill:
|
||||
return "🌊"
|
||||
elif os.environ.get("KITTY_WINDOW_ID"):
|
||||
# Kitty terminal has alignment problems with the default Pencil symbol "✏️"
|
||||
# as well as alternatives "🖍️", "🖊️", "🖋️", "✍️", "✒️", "🪈"
|
||||
# and Brush symbol "🖌️" and alternatives "🧹", "🪮"
|
||||
# "🖎", "🖆", and "✎" don't cause alignment issues, but don't show in color and are illegibly small.
|
||||
if self == Tool.pencil:
|
||||
# Working for me: "🪶", "🥖", "🥕", "▪", and "📝", the last one looking more like a Text tool than a Pencil tool,
|
||||
# but at least has a pencil...
|
||||
return "📝"
|
||||
if self == Tool.brush:
|
||||
# Working for me: "👨🎨", "💅", "🪥", "🪒", "🪠", "▭⋹" (basically any of the lame options)
|
||||
# return "[tan]▬[/][#5c2121]⋹[/]"
|
||||
return "[tan]▬[/]▤"
|
||||
if self == Tool.text:
|
||||
# The wide character "A" isn't centered-looking? And is faint/small...
|
||||
return "𝐴" # not centered, but closer to MS Paint's icon, with serifs
|
||||
if self == Tool.curve:
|
||||
# "~" appears tiny!
|
||||
# "〜" looks good; should I use that for other platforms too?
|
||||
# (It's funny, they look identical in my IDE (VS Code))
|
||||
return "〜"
|
||||
# Windows Terminal has alignment problems with the default Pencil symbol "✏️"
|
||||
# as well as alternatives "🖍️", "🖊️", "🖋️", "✍️", "✒️"
|
||||
# "🖎" and "🖆" don't cause alignment issues, but don't show in color and are illegibly small.
|
||||
if self == Tool.pencil:
|
||||
# This looks more like it would represent the Text tool than the Pencil,
|
||||
# so it's far from ideal, especially when there IS an actual pencil emoji...
|
||||
return "📝"
|
||||
# "🖌️" is causes misalignment (and is hard to distinguish from "✏️" at a glance)
|
||||
# "🪮" shows as tofu
|
||||
if self == Tool.brush:
|
||||
return "🧹"
|
||||
# "🪣" shows as tofu
|
||||
if self == Tool.fill:
|
||||
return "🌊"
|
||||
elif os.environ.get("KITTY_WINDOW_ID"):
|
||||
# Kitty terminal has alignment problems with the default Pencil symbol "✏️"
|
||||
# as well as alternatives "🖍️", "🖊️", "🖋️", "✍️", "✒️", "🪈"
|
||||
# and Brush symbol "🖌️" and alternatives "🧹", "🪮"
|
||||
# "🖎", "🖆", and "✎" don't cause alignment issues, but don't show in color and are illegibly small.
|
||||
if self == Tool.pencil:
|
||||
# Working for me: "🪶", "🥖", "🥕", "▪", and "📝", the last one looking more like a Text tool than a Pencil tool,
|
||||
# but at least has a pencil...
|
||||
return "📝"
|
||||
if self == Tool.brush:
|
||||
# Working for me: "👨🎨", "💅", "🪥", "🪒", "🪠", "▭⋹" (basically any of the lame options)
|
||||
# return "[tan]▬[/][#5c2121]⋹[/]"
|
||||
return "[tan]▬[/]▤"
|
||||
if self == Tool.text:
|
||||
# The wide character "A" isn't centered-looking? And is faint/small...
|
||||
return "𝐴" # not centered, but closer to MS Paint's icon, with serifs
|
||||
if self == Tool.curve:
|
||||
# "~" appears tiny!
|
||||
# "〜" looks good; should I use that for other platforms too?
|
||||
# (It's funny, they look identical in my IDE (VS Code))
|
||||
return "〜"
|
||||
return {
|
||||
Tool.free_form_select: "⚝",
|
||||
Tool.select: "⬚",
|
||||
|
Loading…
Reference in New Issue
Block a user