Skip to content

Commit 79400d5

Browse files
committed
feat: try to infer COLORTERM if not set
If `COLORTERM` is not set, which usually happens inside of an SSH session, check `TERM` and see if it maps to a modern terminal detected (ghostty, kitty, alacritty, ...). If it does, assume `COLORTERM=truecolor`.
1 parent a4a5099 commit 79400d5

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/isd_tui/isd.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,12 +2991,27 @@ def render_model_as_yaml(model: Settings) -> str:
29912991

29922992

29932993
def main():
2994-
app = InteractiveSystemd(fake_startup_count=None)
2995-
# In theory, I could trigger a custom exit code for the application
2996-
# if a change is detected and then restart the application here.
2997-
# But let's keep it simple for now. If somebody actually asks for this
2998-
# feature, I might take a closer look at it.
2999-
app.run()
2994+
from unittest.mock import patch
2995+
from rich.color import ColorSystem
2996+
2997+
_TERM_COLORS = {
2998+
"kitty": ColorSystem.TRUECOLOR,
2999+
"ghostty": ColorSystem.TRUECOLOR,
3000+
"wezterm": ColorSystem.TRUECOLOR,
3001+
"256color": ColorSystem.TRUECOLOR,
3002+
# If this is too aggressive, I could only trigger this if I am inside of an SSH session.
3003+
# if os.getenv("SSH_TTY")
3004+
# else ColorSystem.EIGHT_BIT,
3005+
"alacritty": ColorSystem.TRUECOLOR,
3006+
}
3007+
with patch("rich.console._TERM_COLORS", new=_TERM_COLORS):
3008+
app = InteractiveSystemd(fake_startup_count=None)
3009+
3010+
# In theory, I could trigger a custom exit code for the application
3011+
# if a change is detected and then restart the application here.
3012+
# But let's keep it simple for now. If somebody actually asks for this
3013+
# feature, I might take a closer look at it.
3014+
app.run()
30003015

30013016

30023017
if __name__ == "__main__":

0 commit comments

Comments
 (0)