Skip to content

Commit c4049f6

Browse files
committed
fix: align systemctl stderr behavior
In reference to #16, `isd` now correctly merges stderr and stdout.
1 parent aeb2ba0 commit c4049f6

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

flake.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@
188188
cp ${css} $out/asciinema-player.css
189189
cp ${js} $out/asciinema-player.min.js
190190
'';
191+
isd-example-templated-unit =
192+
inputs.systemd-nix.lib.${system}.mkUserService "0-isd-example-unit-template@"
193+
{
194+
description = "isd-example instantiated unit %i";
195+
documentation = [ "man:python" ];
196+
serviceConfig = {
197+
Type = "oneshot";
198+
ExecStart = "${lib.getExe' pkgs.coreutils "echo"} 'I am unit %i'";
199+
RemainAfterExit = true;
200+
};
201+
};
202+
191203
isd-example-units =
192204
let
193205
gen_unit =

src/isd/isd.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,15 +1182,10 @@ async def update_preview_window(self) -> None:
11821182
case other:
11831183
self.notify(f"Unknown state {other}", severity="error")
11841184
return
1185-
1186-
output = (
1187-
Text.from_ansi(stdout)
1188-
if stderr == ""
1189-
else Text.from_markup(
1190-
f"[b][red]Error while calling [code]{tabbed_content.active}[/code]:[/red][/b]\n\n"
1191-
)
1192-
+ Text.from_ansi(stderr)
1193-
)
1185+
# style it like systemctl from CLI
1186+
# For example, previewing a template file with `status` raises
1187+
# an error but it shouldn't "cover" stdout.
1188+
output = Text.from_ansi(stdout if stderr == "" else stderr + "\n" + stdout)
11941189
# Not sure if this comparison makes it slower or faster
11951190
if output != self.last_output:
11961191
preview.clear()
@@ -1706,7 +1701,9 @@ def action_open_preview_in_pager(self) -> None:
17061701
with self.suspend():
17071702
cmd_args = self.preview_output_command_builder(cur_tab)
17081703
env = env_with_color()
1709-
p1 = subprocess.Popen(cmd_args, env=env, stdout=subprocess.PIPE)
1704+
p1 = subprocess.Popen(
1705+
cmd_args, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
1706+
)
17101707
if p1.stdout is not None:
17111708
# for true `more` support I must inject the following
17121709
# environment variable but make sure to not bleed it here!
@@ -1729,12 +1726,15 @@ def action_open_preview_in_editor(self) -> None:
17291726
cur_tab = cast(TabbedContent, self.query_one(TabbedContent)).active
17301727
with self.suspend():
17311728
args = self.preview_output_command_builder(cur_tab)
1732-
# env = env_with_color(colors=False)
1733-
# self.notify(" ".join(args))
1734-
p1 = subprocess.run(args, capture_output=True, text=True)
1729+
p1 = subprocess.run(
1730+
args, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
1731+
)
17351732
with tempfile.NamedTemporaryFile() as tmp_file:
17361733
p = Path(tmp_file.name)
1737-
p.write_text(p1.stdout)
1734+
p.write_text(
1735+
# capture_output appends a newline to non-empty stderr!
1736+
p1.stdout
1737+
)
17381738
subprocess.call([self.editor, p.absolute()])
17391739
self.refresh()
17401740

0 commit comments

Comments
 (0)