Skip to content

Commit 2d830f3

Browse files
Merge pull request #881 from anwesha-palit-redhat/feat/SRVKP-10407
SRVKP-10407: Adds ANSI color support to the log viewer components, enabling colored output for Tekton task and pipeline run logs.
2 parents c373d1e + 3cacd32 commit 2d830f3

File tree

7 files changed

+139
-4
lines changed

7 files changed

+139
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"cypress-generate": "marge -o ./integration-tests/screenshots/ -f cypress-report -t 'OpenShift Console Plugin Template Cypress Test Results' -p 'OpenShift Cypress Plugin Template Test Results' --showPassed false --assetsDir ./integration-tests/screenshots/cypress/assets ./integration-tests/screenshots/cypress.json",
2121
"cypress-postreport": "yarn cypress-merge && yarn cypress-generate",
2222
"generate-types": "openapi-typescript openapi/spec.yml --output src/types/api.ts",
23-
"dev": "NODE_ENV=development NODE_OPTIONS=--max-old-space-size=8192 rm -rf dist && yarn ts-node ./node_modules/.bin/webpack serve --progress",
23+
"dev": "NODE_ENV=development rm -rf dist && node --max-old-space-size=8192 -r ts-node/register ./node_modules/.bin/webpack serve --progress",
2424
"test": "jest",
2525
"memsource-upload": "./i18n-scripts/memsource-upload.sh",
2626
"memsource-download": "./i18n-scripts/memsource-download.sh",

src/components/logs/LogsWrapperComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const LogsWrapperComponent: React.FC<
5050
taskRun?.spec.taskRef?.name ||
5151
'-';
5252

53-
if (loaded && !error && resource.name === obj.metadata.name) {
53+
if (loaded && !error && resource.name === obj?.metadata?.name) {
5454
resourceRef.current = obj;
5555
} else if (error) {
5656
resourceRef.current = null;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
@use './ansi-log-colors' as *;
2+
13
.odc-tekton-taskrun-log {
24
overflow: hidden;
35

46
.pf-v5-c-log-viewer__text {
57
white-space: pre;
68
}
9+
10+
@include ansi-log-colors;
711
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Shared ANSI color classes for LogViewer with useAnsiClasses
2+
// Import this mixin in any SCSS file that wraps a LogViewer component
3+
4+
@mixin ansi-log-colors {
5+
// Foreground colors (optimized for dark/black background)
6+
.ansi-black-fg {
7+
color: #6e6e6e;
8+
}
9+
.ansi-red-fg {
10+
color: #f14c4c;
11+
}
12+
.ansi-green-fg {
13+
color: #23d18b;
14+
}
15+
.ansi-yellow-fg {
16+
color: #f5f543;
17+
}
18+
.ansi-blue-fg {
19+
color: #3b8eea;
20+
}
21+
.ansi-magenta-fg {
22+
color: #d670d6;
23+
}
24+
.ansi-cyan-fg {
25+
color: #29b8db;
26+
}
27+
.ansi-white-fg {
28+
color: #e5e5e5;
29+
}
30+
31+
// Bright foreground colors
32+
.ansi-bright-black-fg {
33+
color: #a0a0a0;
34+
}
35+
.ansi-bright-red-fg {
36+
color: #f14c4c;
37+
}
38+
.ansi-bright-green-fg {
39+
color: #23d18b;
40+
}
41+
.ansi-bright-yellow-fg {
42+
color: #f5f543;
43+
}
44+
.ansi-bright-blue-fg {
45+
color: #73c3ff;
46+
}
47+
.ansi-bright-magenta-fg {
48+
color: #ff7eff;
49+
}
50+
.ansi-bright-cyan-fg {
51+
color: #5ff;
52+
}
53+
.ansi-bright-white-fg {
54+
color: #fff;
55+
}
56+
57+
// Background colors
58+
.ansi-black-bg {
59+
background-color: #000;
60+
}
61+
.ansi-red-bg {
62+
background-color: #bb0000;
63+
}
64+
.ansi-green-bg {
65+
background-color: #00bb00;
66+
}
67+
.ansi-yellow-bg {
68+
background-color: #bbbb00;
69+
}
70+
.ansi-blue-bg {
71+
background-color: #0000bb;
72+
}
73+
.ansi-magenta-bg {
74+
background-color: #bb00bb;
75+
}
76+
.ansi-cyan-bg {
77+
background-color: #00bbbb;
78+
}
79+
.ansi-white-bg {
80+
background-color: #fff;
81+
}
82+
83+
// Bright background colors
84+
.ansi-bright-black-bg {
85+
background-color: #555;
86+
}
87+
.ansi-bright-red-bg {
88+
background-color: #f55;
89+
}
90+
.ansi-bright-green-bg {
91+
background-color: #0f0;
92+
}
93+
.ansi-bright-yellow-bg {
94+
background-color: #ff5;
95+
}
96+
.ansi-bright-blue-bg {
97+
background-color: #55f;
98+
}
99+
.ansi-bright-magenta-bg {
100+
background-color: #f5f;
101+
}
102+
.ansi-bright-cyan-bg {
103+
background-color: #5ff;
104+
}
105+
.ansi-bright-white-bg {
106+
background-color: #fff;
107+
}
108+
109+
// Text styles
110+
.ansi-bold {
111+
font-weight: bold;
112+
}
113+
.ansi-faint {
114+
opacity: 0.5;
115+
}
116+
.ansi-italic {
117+
font-style: italic;
118+
}
119+
.ansi-underline {
120+
text-decoration: underline;
121+
}
122+
}

src/components/pipelineRuns-details/PipelineRunLogs.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use '../logs/ansi-log-colors' as *;
2+
13
.odc-pipeline-run-logs {
24
display: flex;
35
flex: 1;
@@ -10,6 +12,9 @@
1012
.pf-v5-c-log-viewer__text {
1113
white-space: pre;
1214
}
15+
16+
@include ansi-log-colors;
17+
1318
&__nav {
1419
padding-top: 0;
1520
list-style-type: none;

src/components/pipelineRuns-details/PipelineRunLogs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class PipelineRunLogsWithTranslation extends React.Component<
235235
</NavList>
236236
</Nav>
237237
) : (
238-
<div className="odc-pipeline-run-logs__nav">
238+
<div className="odc-pipeline-run-logs__nav pf-v5-u-text-align-center">
239239
{t('No task runs found')}
240240
</div>
241241
)}
@@ -251,7 +251,7 @@ class PipelineRunLogsWithTranslation extends React.Component<
251251
/>
252252
) : (
253253
<div
254-
className="odc-pipeline-run-logs__logcontainer pf-v5-u-w-100"
254+
className="pf-v5-u-w-100 pf-v5-u-pr-xl"
255255
data-test-id="task-logs-error"
256256
>
257257
<LogViewer

src/components/pipelines-tasks/tasks-details-pages/TaskRunLog.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use '../../logs/ansi-log-colors' as *;
2+
13
.odc-task-run-log {
24
display: flex;
35
flex: 1;
@@ -6,4 +8,6 @@
68
.pf-v5-c-log-viewer__text {
79
white-space: pre;
810
}
11+
12+
@include ansi-log-colors;
913
}

0 commit comments

Comments
 (0)