@@ -8,10 +8,10 @@ import { SvelteMap } from 'svelte/reactivity';
88import NoLogIcon from ' /@/component/icons/NoLogIcon.svelte' ;
99import { detectJsonLogs } from ' /@/component/terminal/json-colorizer' ;
1010import {
11- ansi256Colours ,
12- colorizeJSON ,
13- colorizeLogLevel ,
14- colourizedANSIContainerName ,
11+ ansi256Colours ,
12+ colorizeJSON ,
13+ colorizeLogLevel ,
14+ colourizedANSIContainerName ,
1515} from ' /@/component/terminal/terminal-colors' ;
1616import TerminalWindow from ' /@/component/terminal/TerminalWindow.svelte' ;
1717import { Streams } from ' /@/stream/streams' ;
@@ -40,21 +40,19 @@ const streams = getContext<Streams>(Streams);
4040const prefixColourMap = new SvelteMap <string , string >();
4141
4242const 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+ */
115113const setupPrefixColours = (): void => {
116114 object .spec ?.containers .forEach ((container , index ) => {
117115 const colour = ansi256Colours [index % ansi256Colours .length ];
0 commit comments