Skip to content

Commit a5aba3f

Browse files
committed
Prettier fighting with pnpm:format and implement another rabbit comment that makes enough sense to me...
Signed-off-by: Adameska <[email protected]>
1 parent d60cbcd commit a5aba3f

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

packages/webview/src/component/pods/PodLogs.svelte

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { SvelteMap } from 'svelte/reactivity';
88
import NoLogIcon from '/@/component/icons/NoLogIcon.svelte';
99
import { detectJsonLogs } from '/@/component/terminal/json-colorizer';
1010
import {
11-
ansi256Colours,
12-
colorizeJSON,
13-
colorizeLogLevel,
14-
colourizedANSIContainerName,
11+
ansi256Colours,
12+
colorizeJSON,
13+
colorizeLogLevel,
14+
colourizedANSIContainerName,
1515
} from '/@/component/terminal/terminal-colors';
1616
import TerminalWindow from '/@/component/terminal/TerminalWindow.svelte';
1717
import { Streams } from '/@/stream/streams';
@@ -40,21 +40,19 @@ const streams = getContext<Streams>(Streams);
4040
const prefixColourMap = new SvelteMap<string, string>();
4141
4242
const addLogPrefix = (lines: string[], prefix: string, prefixLength: number): void => {
43-
if (prefix) {
44-
let padding = '';
45-
if (prefixLength > 0) {
46-
//make prefix fit into prefixLength by adding spaces
47-
padding = ' '.repeat(prefixLength - prefix.length);
48-
}
43+
if (!prefix || (lines?.length ?? 0) == 0) {
44+
return;
45+
}
4946
50-
const colouredName = prefixColourMap.get(prefix);
47+
const safePadding = Math.max(0, prefixLength - prefix.length);
48+
const padding = safePadding > 0 ? ' '.repeat(safePadding) : '';
49+
const mappedPrefix = prefixColourMap.get(prefix) ?? prefix;
5150
52-
lines.forEach((line, index) => {
53-
if (index < lines.length - 1 || line.length > 0) {
54-
lines[index] = `${padding}${colouredName}|${line}`;
55-
}
56-
});
57-
}
51+
lines.forEach((line, index) => {
52+
if (index < lines.length - 1 || line.length > 0) {
53+
lines[index] = `${padding}${mappedPrefix}|${line}`;
54+
}
55+
});
5856
};
5957
6058
/**
@@ -109,9 +107,9 @@ const calculatePrefixLength = (): number => {
109107
};
110108
111109
/**
112-
+ * Sets up ANSI color mappings for container name prefixes in multi-container pods.
113-
+ * Cycles through available colors using modulo when there are more containers than colors.
114-
*/
110+
+ * Sets up ANSI color mappings for container name prefixes in multi-container pods.
111+
+ * Cycles through available colors using modulo when there are more containers than colors.
112+
*/
115113
const setupPrefixColours = (): void => {
116114
object.spec?.containers.forEach((container, index) => {
117115
const colour = ansi256Colours[index % ansi256Colours.length];

0 commit comments

Comments
 (0)