Skip to content

A GitHub action for removing ANSI color escape sequences from arbitrary strings.

License

Notifications You must be signed in to change notification settings

marcransome/remove-ansi-colors

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

paint

remove-ansi-colors

OpenSSF Scorecard Tests Issues Dependabot License

A GitHub action for removing ANSI color escape sequences from arbitrary strings.

Prerequisites

This action has a few dependencies that are generally satisfied by most GitHub-hosted runners (macos-* and ubuntu-* environment variants):

Usage

Add a suitable uses step to your GitHub workflow with a value for the colored step input (i.e. an output from a previous step that includes ANSI color escape sequences) and use the uncolored output in subsequent steps:

jobs:
  remove-ansi-colors:
    runs-on: ubuntu-latest
    steps:
      - name: A step that generates output with ANSI color escape sequences
        id: generate-colored-output
        run: |
          colored=$(printf '\e[0;31mCOLORED\e[0m')
          echo "colored=$colored" >> "$GITHUB_OUTPUT"
      - name: Remove ANSI color escape sequences
        uses: marcransome/remove-ansi-colors@v1
        id: remove-ansi-colors
        with:
          colored: ${{ steps.generate-colored-output.outputs.colored }}
      - name: Use uncolored output
        run: echo "${{ steps.remove-ansi-colors.outputs.uncolored }}"

Inputs

  • colored - A string containing ANSI color escape sequences.

Outputs

  • uncolored - The colored input string with ANSI color escape sequences removed.

Action versions

Use one of the following patterns when specifying the version reference for this action in your workflow (i.e. the {ref} value in uses: marcransome/remove-ansi-colors@{ref}):

Pattern Example Description
vX v1 the latest v1.* release including non-breaking changes and bug fixes
vX.Y v1.1 the latest v1.1.* release including bug fixes
vX.Y.Z v1.1.0 the v1.1.0 release only

The recommended pattern when using tags is vX (e.g. v1). This will ensure that the version of the action used in your workflow includes the latest non-breaking changes and bug fixes, and guarantees compatibility with previous versions of that major release number.

Tip

For improved security, pin the action to a full length commit SHA rather than a tag version and use Dependabot version updates to keep the action up to date. For example:

uses: marcransome/remove-ansi-colors@88e03a4ec5e23f3d97e93c76051c1cd7d4389881 # v1.4.1

Using a main branch reference in your workflow is not recommended as this branch may include breaking changes intended for the next major release.

Acknowledgements

License

remove-ansi-colors is provided under the terms of the MIT License.

Contact

Email me at marc.ransome@fidgetbox.co.uk or create an issue.

About

A GitHub action for removing ANSI color escape sequences from arbitrary strings.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project