Skip to content

Commit 8fe5df4

Browse files
qdeslandesDaanDeMeyer
authored andcommitted
Respect SYSTEMD_TINT_BACKGROUND and SYSTEMD_ADJUST_TERMINAL_TITLE
When mkosi creates a new console with systemd-pty-forward, it sets a custom (dark) color, which might not play nice depending on your terminal theme. Environment variables SYSTEMD_TINT_BACKGROUND and SYSTEMD_ADJUST_TERMINAL_TITLE allow the user the customize this behaviour, but they were ignored until a recent change in systemd (c.f. 9c3359f). Modify mkosi behaviour to respect SYSTEMD_TINT_BACKGROUND and SYSTEMD_ADJUST_TERMINAL_TITLE when calling systemd-pty-forward.
1 parent b9d2087 commit 8fe5df4

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

mkosi/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
parse_config,
8181
resolve_deps,
8282
summary,
83+
systemd_pty_forward,
8384
systemd_tool_version,
8485
want_kernel,
8586
want_selinux_relabel,
@@ -4059,13 +4060,8 @@ def run_box(args: Args, config: Config) -> None:
40594060

40604061
cmdline = [*args.cmdline]
40614062

4062-
if sys.stdin.isatty() and sys.stdout.isatty() and config.find_binary("systemd-pty-forward"):
4063-
cmdline = [
4064-
"systemd-pty-forward",
4065-
"--title=mkosi-sandbox",
4066-
"--background=48;2;12;51;51", # cyan
4067-
*cmdline,
4068-
]
4063+
if sys.stdin.isatty() and sys.stdout.isatty():
4064+
cmdline = systemd_pty_forward(config, "48;2;12;51;51", "mkosi-sandbox") + cmdline
40694065

40704066
with contextlib.ExitStack() as stack:
40714067
if config.tools() != Path("/"):

mkosi/config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6036,3 +6036,24 @@ def systemd_tool_version(*tool: PathString, sandbox: SandboxProtocol = nosandbox
60366036
logging.debug(f"Version reported by {tool[-1]} is {version}")
60376037

60386038
return version
6039+
6040+
6041+
def systemd_pty_forward(config: Config, background: str, title: str) -> list[str]:
6042+
tint_bg = parse_boolean(config.environment.get("SYSTEMD_TINT_BACKGROUND", "1")) and parse_boolean(
6043+
os.environ.get("SYSTEMD_TINT_BACKGROUND", "1")
6044+
)
6045+
adjust_title = parse_boolean(
6046+
config.environment.get("SYSTEMD_ADJUST_TERMINAL_TITLE", "1")
6047+
) and parse_boolean(os.environ.get("SYSTEMD_ADJUST_TERMINAL_TITLE", "1"))
6048+
6049+
if not tint_bg and not adjust_title:
6050+
return []
6051+
if not config.find_binary("systemd-pty-forward"):
6052+
return []
6053+
6054+
cmd = ["systemd-pty-forward"]
6055+
if tint_bg:
6056+
cmd += [f"--background={background}"]
6057+
if adjust_title:
6058+
cmd += ["--title=", title]
6059+
return cmd

mkosi/qemu.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
VsockCID,
4444
finalize_term,
4545
format_bytes,
46+
systemd_pty_forward,
4647
systemd_tool_version,
4748
want_selinux_relabel,
4849
yes_no,
@@ -1183,10 +1184,9 @@ def run_qemu(args: Args, config: Config) -> None:
11831184
cmdline: list[PathString] = []
11841185

11851186
if config.console in (ConsoleMode.interactive, ConsoleMode.read_only):
1186-
cmdline += [
1187-
"systemd-pty-forward", "--background=48;2;12;51;19", # green
1188-
"--title", f"Virtual Machine {config.machine_or_name()}",
1189-
] # fmt: skip
1187+
cmdline += systemd_pty_forward(
1188+
config, "48;2;12;51;19", f"Virtual Machine {config.machine_or_name()}"
1189+
)
11901190

11911191
if config.console == ConsoleMode.read_only:
11921192
cmdline += ["--read-only"]

0 commit comments

Comments
 (0)