Colored Jenkins output

This commit is contained in:
Dragorn421 2024-09-27 12:32:53 +02:00
parent d4a87889ff
commit 3bf1e4afd9
No known key found for this signature in database
GPG Key ID: 381AEBAF3D429335
2 changed files with 9 additions and 1 deletions

4
Jenkinsfile vendored
View File

@ -3,6 +3,10 @@ pipeline {
label 'oot' label 'oot'
} }
options {
ansiColor('xterm')
}
stages { stages {
stage('Check formatting (full)') { stage('Check formatting (full)') {
when { when {

View File

@ -13,6 +13,7 @@ from dataclasses import dataclass
import io import io
import multiprocessing import multiprocessing
import multiprocessing.pool import multiprocessing.pool
import os
from pathlib import Path from pathlib import Path
import re import re
import shlex import shlex
@ -36,9 +37,12 @@ import mapfile_parser.mapfile
# Set on program start since we replace sys.stdout in worker processes # Set on program start since we replace sys.stdout in worker processes
stdout_isatty = sys.stdout.isatty() stdout_isatty = sys.stdout.isatty()
# https://no-color.org/
enable_colors = os.environ.get("NO_COLOR", "") == ""
def output(message: str = "", color: Optional[str] = None, end: str = "\n"): def output(message: str = "", color: Optional[str] = None, end: str = "\n"):
if color and stdout_isatty: if color and enable_colors:
print(f"{color}{message}{colorama.Fore.RESET}", end=end) print(f"{color}{message}{colorama.Fore.RESET}", end=end)
else: else:
print(message, end=end) print(message, end=end)