@@ -18,7 +18,7 @@ import (
1818
1919var (
2020 ipPortPattern = regexp .MustCompile (
21- `(?:\[(?:[0-9a-fA-F:.]+)\]|(?:\d{1,3}\.){3}\d{1,3})(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?` ,
21+ `(?:\[(?:[0-9a-fA-F:.]+(?:%[a-zA-Z0-9_.-]+)? )\]|(?:\d{1,3}\.){3}\d{1,3})(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?` ,
2222 )
2323 domainPattern = regexp .MustCompile (
2424 `\b(?:[a-zA-Z0-9-]{1,63}\.)+(?:com|net|org|io|co|uk|ru|de|edu|gov|info|biz|dev|app|ai|tv)(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?\b` ,
@@ -167,7 +167,7 @@ func colorizeHTTP(
167167 if body && len (* reqBodySaved ) > 0 {
168168 b := colorizeBody (reqBodySaved , nocolor )
169169 if b != "" {
170- sb .WriteString ("\n " )
170+ sb .WriteString ("\033 [K \ n " )
171171 fmt .Fprintf (& sb , "%s " , colorizeTimestamp (time .Now (), nocolor ))
172172 sb .WriteString (id )
173173 sb .WriteString (colors .RedBgDark (" req_body: " ).String ())
@@ -177,13 +177,14 @@ func colorizeHTTP(
177177 if body && len (* respBodySaved ) > 0 {
178178 b := colorizeBody (respBodySaved , nocolor )
179179 if b != "" {
180- sb .WriteString ("\n " )
180+ sb .WriteString ("\033 [K \ n " )
181181 fmt .Fprintf (& sb , "%s " , colorizeTimestamp (time .Now (), nocolor ))
182182 sb .WriteString (id )
183183 sb .WriteString (colors .RedBgDark (" resp_body: " ).String ())
184184 sb .WriteString (b )
185185 }
186186 }
187+ sb .WriteString ("\033 [K" )
187188 }
188189 return sb .String ()
189190}
@@ -241,7 +242,7 @@ func colorizeTLS(req *layers.TLSClientHello, resp *layers.TLSServerHello, id str
241242 sb .WriteString (colors .BlueBg (fmt .Sprintf (" ALPN: %v" , req .ALPN )).String ())
242243 }
243244 sb .WriteString (colors .MagentaBg (" → " ).String ())
244- sb .WriteString ("\n " )
245+ sb .WriteString ("\033 [K \ n " )
245246 fmt .Fprintf (& sb , "%s " , colorizeTimestamp (time .Now (), nocolor ))
246247 sb .WriteString (id )
247248 sb .WriteString (colors .LightBlue (fmt .Sprintf (" %s " , resp .TypeDesc )).Bold ())
@@ -260,6 +261,7 @@ func colorizeTLS(req *layers.TLSClientHello, resp *layers.TLSServerHello, id str
260261 if resp .ExtensionLength > 0 {
261262 sb .WriteString (colors .BeigeBg (fmt .Sprintf (" ExtLen: %d" , resp .ExtensionLength )).String ())
262263 }
264+ sb .WriteString ("\033 [K" )
263265 }
264266 return sb .String ()
265267}
@@ -335,7 +337,7 @@ func colorizeDNS(req, resp *layers.DNSMessage, id string, nocolor bool) string {
335337 for _ , rec := range req .AdditionalRRs {
336338 sb .WriteString (colorizeRData (rec ))
337339 }
338- sb .WriteString ("\n " )
340+ sb .WriteString ("\033 [K \ n " )
339341 fmt .Fprintf (& sb , "%s " , colorizeTimestamp (time .Now (), nocolor ))
340342 sb .WriteString (id )
341343 sb .WriteString (colors .Blue (fmt .Sprintf (" DNS %s (%s)" , resp .Flags .OPCodeDesc , resp .Flags .QRDesc )).Bold ())
@@ -352,6 +354,7 @@ func colorizeDNS(req, resp *layers.DNSMessage, id string, nocolor bool) string {
352354 for _ , rec := range resp .AdditionalRRs {
353355 sb .WriteString (colorizeRData (rec ))
354356 }
357+ sb .WriteString ("\033 [K" )
355358 }
356359 return sb .String ()
357360}
@@ -457,12 +460,13 @@ func colorizeConnections(srcRemote, srcLocal, dstRemote, dstLocal net.Addr, id s
457460 sb .WriteString (colors .Green (fmt .Sprintf (" Src: %s→ %s" , srcRemote , srcLocal )).String ())
458461 sb .WriteString (colors .Magenta (" → " ).String ())
459462 sb .WriteString (colors .Blue (fmt .Sprintf ("Dst: %s→ %s" , dstLocal , dstRemote )).String ())
460- sb .WriteString ("\n " )
463+ sb .WriteString ("\033 [K \ n " )
461464 fmt .Fprintf (& sb , "%s " , colorizeTimestamp (time .Now (), nocolor ))
462465 sb .WriteString (id )
463466 sb .WriteString (colors .Gray (fmt .Sprintf (" %s " , r .Method )).String ())
464467 sb .WriteString (colors .YellowBg (fmt .Sprintf ("%s " , r .Host )).String ())
465468 sb .WriteString (colors .BlueBg (fmt .Sprintf ("%s " , r .Proto )).String ())
469+ sb .WriteString ("\033 [K" )
466470 }
467471 return sb .String ()
468472}
@@ -489,6 +493,7 @@ func colorizeConnectionsTransparent(
489493 sb .WriteString (colors .Magenta (" → " ).String ())
490494 sb .WriteString (colors .Blue (fmt .Sprintf ("Dst: %s→ %s " , dstLocal , dstRemote )).String ())
491495 sb .WriteString (colors .BeigeBg (fmt .Sprintf ("Orig Dst: %s" , dst )).String ())
496+ sb .WriteString ("\033 [K" )
492497 }
493498 return sb .String ()
494499}
0 commit comments