Skip to content

--no-strip-ansi prints ANSI codes and garbles output #785

@srithon

Description

@srithon

This flag was introduced in PR #784, after a commit in PR #739 unconditionally stripped ANSI codes from stdin. PR #739 was made in response to issue #689; in order to prevent the display from being garbled by incorrect ANSI code handling, we opted to simply strip ANSI codes from the input entirely. The implementation in PR #784 (and my own draft implementation in PR #782) simply undo that stripping behavior without addressing the underlying issues from #689, resulting in strange outputs in certain cases. Below is a minimal example which results in garbled output on my machine in Kitty, Alacritty and st.

#!/bin/sh

green=$(tput setaf 2)
reset=$(tput sgr0)

{
  echo "Option 1"
  echo "Option 2"
  echo "${green}Option 3${reset}"
} | gum filter --no-strip-ansi

Here are recordings for each tested terminal. Note that Kitty was a lot worse than the others; interestingly, when I tried using asciinema to record Kitty's output, the recording showed the same 2m result as the other terminals; to show what it actually looked like on-screen I had to use a screen recording.

  1. Kitty
  2. Alacritty
  3. st

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions