colored output breaks if output sequence has a newline
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 1.4k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 24
Description
Describe the bug
Though github actions typically don't have a colored output by default (see https://github.com/actions/runner/issues/750), it's still usually possible to set some environment variable/provide some flag to force program to output colored.
But the problem is, if output has newlines, then it seems to be splitted by them and then color codes have no effect - effectively they color only the first line.
To Reproduce
Steps to reproduce the behavior:
- Run the action below.
- Examine the output.
-
Note that
Hello Worldproduced bypython -c "print('\033[33mHello, \nworld!\033[0m')"have only the first line colored.
Same forCMake Warning at CMakeLists.txt:3 (message): A colored warning message from CMake. -
If we examine the logs, we can also note that message is splitted by different lines, which is probably what leads to this.
2025-12-19T06:26:02.6569047Z [33mHello,
2025-12-19T06:26:02.6569492Z world![0m
2025-12-19T06:26:03.1327967Z [33mCMake Warning at CMakeLists.txt:3 (message):
2025-12-19T06:26:03.1328514Z A colored warning message from CMake
2025-12-19T06:26:03.1328916Z
2025-12-19T06:26:03.1329067Z [0m
Expected behavior
Output to be properly colored.
Example action to run
Can be forked from https://github.com/Andrej730/cmake-color-test
All cmake related stuff is optional, it can be reproduced with just python -c "print('\033[33mHello, \nworld!\033[0m')".
Adding cmake for a reference of real-life application of this.
Attach .yml code below, in case repo will be removed in the future.
name: test-makefile-logs
on:
workflow_dispatch:
jobs:
test-makefile-logs:
runs-on: ubuntu-24.04
env:
CLICOLOR_FORCE: "1"
CMAKE_COLOR_DIAGNOSTICS: "ON"
steps:
- name: Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: astral-sh/setup-uv@v7
- name: Run cmake
run: |
env
uv tool install cmake
cmake --version
python -c "print('\033[33mHello, \nworld!\033[0m')"
echo "cmake_minimum_required(VERSION 3.21)" > CMakeLists.txt
echo "project(test-package)" >> CMakeLists.txt
echo "message(WARNING \"A colored warning message from CMake\")" >> CMakeLists.txt
cmake .
make -j VERBOSE=1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue in a GitHub Actions workflow with the provided Python command and forced color settings. Trace how the runner splits command output into log lines and handles ANSI color sequences across newlines; done means multi-line output remains colored throughout, including the CMake warning example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- ci-cd
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100