From 6b33882c0c7b0a7f587e14fad5a8f8d9ac389d03 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 18 Feb 2026 10:42:04 +0000 Subject: [PATCH] remove colour codes from output strings --- cmd/q3rcon/main.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/q3rcon/main.go b/cmd/q3rcon/main.go index 9c39bf8..88d52fe 100644 --- a/cmd/q3rcon/main.go +++ b/cmd/q3rcon/main.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "os" + "regexp" "runtime/debug" "strings" "time" @@ -188,7 +189,7 @@ func runCommands(client *q3rcon.Rcon, commands []string) { log.Error(err) continue } - fmt.Print(resp) + fmt.Print(removeColourCodes(resp)) } } @@ -206,7 +207,7 @@ func interactiveMode(client *q3rcon.Rcon, input io.Reader) error { log.Error(err) continue } - fmt.Printf("%s>> ", resp) + fmt.Printf("%s>> ", removeColourCodes(resp)) } if scanner.Err() != nil { @@ -214,3 +215,10 @@ func interactiveMode(client *q3rcon.Rcon, input io.Reader) error { } return nil } + +var colourCodeRegex = regexp.MustCompile(`\^[0-9]`) + +// removeColourCodes removes '\^[0-9]' colour codes from the input string. +func removeColourCodes(s string) string { + return colourCodeRegex.ReplaceAllString(s, "") +}