mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-26 13:11:53 +08:00
perf: 优化进度条
This commit is contained in:
+16
-4
@@ -81,8 +81,8 @@ func formatLogMessage(entry *LogEntry) string {
|
||||
return fmt.Sprintf("[%s] [%s] %s", timeStr, entry.Level, entry.Content)
|
||||
}
|
||||
|
||||
// 修改 printLog 函数
|
||||
func printLog(entry *LogEntry) {
|
||||
// 先检查日志级别
|
||||
if LogLevel != LogLevelAll &&
|
||||
entry.Level != LogLevel &&
|
||||
!(LogLevel == LogLevelInfo && (entry.Level == LogLevelInfo || entry.Level == LogLevelSuccess)) {
|
||||
@@ -92,11 +92,15 @@ func printLog(entry *LogEntry) {
|
||||
OutputMutex.Lock()
|
||||
defer OutputMutex.Unlock()
|
||||
|
||||
// 确保清除当前进度条
|
||||
if ProgressBar != nil {
|
||||
ProgressBar.Clear()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
// 打印日志
|
||||
logMsg := formatLogMessage(entry)
|
||||
// 只在输出到终端时处理进度条
|
||||
if !NoColor {
|
||||
// 清除当前行
|
||||
fmt.Print("\033[2K\r")
|
||||
if colorAttr, ok := logColors[entry.Level]; ok {
|
||||
color.New(colorAttr).Println(logMsg)
|
||||
} else {
|
||||
@@ -105,6 +109,14 @@ func printLog(entry *LogEntry) {
|
||||
} else {
|
||||
fmt.Println(logMsg)
|
||||
}
|
||||
|
||||
// 确保日志完全输出
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
// 重新渲染进度条
|
||||
if ProgressBar != nil {
|
||||
ProgressBar.RenderBlank()
|
||||
}
|
||||
}
|
||||
|
||||
func LogError(errMsg string) {
|
||||
|
||||
Reference in New Issue
Block a user