Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 94f3f40

Browse filesBrowse files
committed
fix: enhance terminal timestamp
1 parent 05050b6 commit 94f3f40
Copy full SHA for 94f3f40

1 file changed

+8-2Lines changed: 8 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/logger.ts‎

Copy file name to clipboardExpand all lines: src/logger.ts
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class Logger {
104104
private fancy: boolean // Whether to use fancy terminal output
105105
private tagFormat: TagFormat
106106
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
108108
private activeProgressBar: { // State for the active progress bar
109109
total: number
110110
current: number
@@ -809,6 +809,9 @@ export class Logger {
809809
private formatConsoleMessage(parts: { timestamp: string, icon?: string, tag?: string, message: string, level?: LogLevel, showTimestamp?: boolean }): string {
810810
const { timestamp, icon = '', tag = '', message, level, showTimestamp = true } = parts
811811

812+
// Helper function to strip ANSI codes
813+
const stripAnsi = (str: string) => str.replace(this.ANSI_PATTERN, '')
814+
812815
// If fancy mode is disabled, return a simple format
813816
if (!this.fancy) {
814817
const components = []
@@ -850,7 +853,10 @@ export class Logger {
850853
}
851854

852855
// 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+
854860
return `${mainPart.trim()}${' '.repeat(padding)}${timestamp}`
855861
}
856862

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.