Skip to content

colored output breaks if output sequence has a newline #4165

@Andrej730

Description

@Andrej730

Describe the bug
Though github actions typically don't have a colored output by default (see #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:

  1. Run the action below.
  2. Examine the output.
Image
  1. Note that Hello World produced by python -c "print('\033[33mHello, \nworld!\033[0m')" have only the first line colored.
    Same for CMake Warning at CMakeLists.txt:3 (message): A colored warning message from CMake.

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions