Skip to content

Commit 26a3234

Browse files
committed
fix: strip colors from dashboard log lines
1 parent 4f1c237 commit 26a3234

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Diff for: plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/Live.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ansiRegex from "ansi-regex"
1919
import stripAnsi from "strip-ansi"
2020
import type { TextProps } from "ink"
2121

22+
import stripColors from "../stripColors.js"
2223
import type Options from "../options.js"
2324
import type { Tail } from "../tailf.js"
2425
import type HistoryConfig from "../history.js"
@@ -80,7 +81,7 @@ export default class Live {
8081
tail.stream.on("data", (data) => {
8182
if (data) {
8283
if (tail.kind === "logs") {
83-
this.pushLineAndPublish(data, cb)
84+
this.pushLineAndPublish(stripColors(data), cb)
8485
}
8586

8687
const line = stripAnsi(data)
@@ -174,7 +175,7 @@ export default class Live {
174175
const rec = {
175176
timestamp,
176177
stateRank: rankFor[metric],
177-
line: key,
178+
line: stripColors(key),
178179
}
179180

180181
const already = this.lookup[rec.line]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2023 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** Strip any color coding from `line`, but leave 33 (yellow) as this is used for worker id prefix */
18+
export default function stripColors(line: string): string {
19+
// eslint-disable-next-line no-control-regex
20+
return line.replace(/(\x1b\[)([^m]+)m/g, (_, p1, p2) => p1 + p2.replace(/3[12456]/g, "") + "m")
21+
}

0 commit comments

Comments
 (0)