@@ -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