fix(tunnel): Fixes the delayed display logic to correctly handle microsecond-level delays.

- Adjust the delayed formatting function to prioritize checking if the delay is 0 to avoid displaying errors.
- When the delay is less than 1 millisecond, it is displayed in microseconds to improve the precision of the expression.
feat (constants): Shorten heart rate intervals and timeouts to improve response speed.
- Adjust HeartbeatInterval from 5 seconds to 2 seconds
- Adjust HeartbeatTimeout from 15 seconds to 6 seconds
- Improve the sensitivity of heartbeat detection between the client and the server
This commit is contained in:
Gouryella
2025-12-10 16:25:45 +08:00
parent f6f2c6fd5b
commit b3c8fc3f41
2 changed files with 11 additions and 6 deletions

View File

@@ -158,13 +158,13 @@ func RenderRetrying(interval time.Duration) string {
// formatLatency formats latency with color
func formatLatency(d time.Duration) string {
ms := d.Milliseconds()
var style lipgloss.Style
if ms == 0 {
if d == 0 {
return mutedStyle.Render("measuring...")
}
ms := d.Milliseconds()
var style lipgloss.Style
switch {
case ms < 50:
style = lipgloss.NewStyle().Foreground(latencyFastColor)
@@ -176,6 +176,11 @@ func formatLatency(d time.Duration) string {
style = lipgloss.NewStyle().Foreground(latencyRedColor)
}
if ms == 0 {
us := d.Microseconds()
return style.Render(fmt.Sprintf("%dµs", us))
}
return style.Render(fmt.Sprintf("%dms", ms))
}