From 530532ca8a21314cc1ff2fafb42ad2ec6d02351c Mon Sep 17 00:00:00 2001 From: Lily Ballard Date: Sun, 11 May 2025 17:53:32 -0700 Subject: [PATCH] libcmd: use correct stream for ANSI testing for markdown Rendering markdown tests if ANSI is supported in order to tell lowdown to disable ANSI escapes. Unfortunately it was testing stderr and yet nearly all rendered markdown output was printed to stdout. Change-Id: Id0000000f0e667d235239c095330d355a9b7714a --- lix/libcmd/markdown.cc | 4 ++-- lix/libcmd/markdown.hh | 3 ++- lix/nix/flake.cc | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lix/libcmd/markdown.cc b/lix/libcmd/markdown.cc index 7264a9471..8fac6b166 100644 --- a/lix/libcmd/markdown.cc +++ b/lix/libcmd/markdown.cc @@ -8,7 +8,7 @@ namespace nix { -std::string renderMarkdownToTerminal(std::string_view markdown) +std::string renderMarkdownToTerminal(std::string_view markdown, StandardOutputStream fileno) { int windowWidth = getWindowSize().second; @@ -21,7 +21,7 @@ std::string renderMarkdownToTerminal(std::string_view markdown) .feat = LOWDOWN_COMMONMARK | LOWDOWN_FENCED | LOWDOWN_DEFLIST | LOWDOWN_TABLES, .oflags = LOWDOWN_TERM_NOLINK, }; - if (!shouldANSI()) { + if (!shouldANSI(fileno)) { opts.oflags |= LOWDOWN_TERM_NOANSI; } diff --git a/lix/libcmd/markdown.hh b/lix/libcmd/markdown.hh index ac881d335..2588ba189 100644 --- a/lix/libcmd/markdown.hh +++ b/lix/libcmd/markdown.hh @@ -1,10 +1,11 @@ #pragma once ///@file +#include "lix/libutil/terminal.hh" #include "lix/libutil/types.hh" namespace nix { -std::string renderMarkdownToTerminal(std::string_view markdown); +std::string renderMarkdownToTerminal(std::string_view markdown, StandardOutputStream fileno = StandardOutputStream::Stdout); } diff --git a/lix/nix/flake.cc b/lix/nix/flake.cc index cbc0e2d75..be3b7a165 100644 --- a/lix/nix/flake.cc +++ b/lix/nix/flake.cc @@ -927,7 +927,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand auto welcomeText = cursor->maybeGetAttr(*evalState, "welcomeText"); if (welcomeText) { notice("\n"); - notice(renderMarkdownToTerminal(welcomeText->getString(*evalState))); + notice(renderMarkdownToTerminal(welcomeText->getString(*evalState), StandardOutputStream::Stderr)); } if (!conflictedFiles.empty())