@@ -104,7 +104,7 @@ export class Logger {
104
104
private fancy : boolean // Whether to use fancy terminal output
105
105
private tagFormat : TagFormat
106
106
private timestampPosition : 'left' | 'right'
107
- private readonly ANSI_PATTERN = / \x1B \[ \d + m / g
107
+ private readonly ANSI_PATTERN = / \u001B \[ . * ? m / g // Use Unicode escape for ANSI sequence
108
108
private activeProgressBar : { // State for the active progress bar
109
109
total : number
110
110
current : number
@@ -809,6 +809,9 @@ export class Logger {
809
809
private formatConsoleMessage ( parts : { timestamp : string , icon ?: string , tag ?: string , message : string , level ?: LogLevel , showTimestamp ?: boolean } ) : string {
810
810
const { timestamp, icon = '' , tag = '' , message, level, showTimestamp = true } = parts
811
811
812
+ // Helper function to strip ANSI codes
813
+ const stripAnsi = ( str : string ) => str . replace ( this . ANSI_PATTERN , '' )
814
+
812
815
// If fancy mode is disabled, return a simple format
813
816
if ( ! this . fancy ) {
814
817
const components = [ ]
@@ -850,7 +853,10 @@ export class Logger {
850
853
}
851
854
852
855
// Calculate padding needed to push timestamp to far right
853
- const padding = Math . max ( 1 , terminalWidth - mainPart . length - timestamp . length )
856
+ const visibleMainPartLength = stripAnsi ( mainPart ) . trim ( ) . length
857
+ const visibleTimestampLength = stripAnsi ( timestamp ) . length
858
+ const padding = Math . max ( 1 , terminalWidth - 2 - visibleMainPartLength - visibleTimestampLength ) // Re-apply -2 for right padding
859
+
854
860
return `${ mainPart . trim ( ) } ${ ' ' . repeat ( padding ) } ${ timestamp } `
855
861
}
856
862
0 commit comments