From a954a5ea2fe08317182b953b562ffbe69f72017e Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Sat, 8 Mar 2025 14:57:26 +0000 Subject: [PATCH] libcmd/markdown: avoid stripping ANSI escapes Instead, we instruct lowdown not to emit them in the first place. Fixes #622. Change-Id: I596bb873943c2c0b5067c5357a90457f01307cfa --- doc/manual/rl-next/fix-help.md | 9 +++++++++ lix/libcmd/markdown.cc | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 doc/manual/rl-next/fix-help.md diff --git a/doc/manual/rl-next/fix-help.md b/doc/manual/rl-next/fix-help.md new file mode 100644 index 000000000..f531deeb1 --- /dev/null +++ b/doc/manual/rl-next/fix-help.md @@ -0,0 +1,9 @@ +--- +synopsis: "Fix `--help` formatting" +issues: [fj#622] +cls: [2776] +category: "Fixes" +credits: ["lheckemann"] +--- + +The help printed when invoking `nix` or `nix-store` and subcommands with `--help` previously contained garbled terminal escapes. These have been removed. diff --git a/lix/libcmd/markdown.cc b/lix/libcmd/markdown.cc index 0010abedb..7264a9471 100644 --- a/lix/libcmd/markdown.cc +++ b/lix/libcmd/markdown.cc @@ -21,6 +21,9 @@ std::string renderMarkdownToTerminal(std::string_view markdown) .feat = LOWDOWN_COMMONMARK | LOWDOWN_FENCED | LOWDOWN_DEFLIST | LOWDOWN_TABLES, .oflags = LOWDOWN_TERM_NOLINK, }; + if (!shouldANSI()) { + opts.oflags |= LOWDOWN_TERM_NOANSI; + } auto doc = lowdown_doc_new(&opts); if (!doc) @@ -47,7 +50,7 @@ std::string renderMarkdownToTerminal(std::string_view markdown) if (!rndr_res) throw Error("allocation error while rendering Markdown"); - return filterANSIEscapes(std::string(buf->data, buf->size), !shouldANSI()); + return std::string(buf->data, buf->size); } }