mirror of
https://github.com/onyx-and-iris/q3rcon.git
synced 2026-03-03 01:19:16 +00:00
remove colour codes from output strings
This commit is contained in:
parent
abb33742aa
commit
6c8a63b09c
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -188,7 +189,7 @@ func runCommands(client *q3rcon.Rcon, commands []string) {
|
|||||||
log.Error(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Print(resp)
|
fmt.Print(removeColourCodes(resp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +207,7 @@ func interactiveMode(client *q3rcon.Rcon, input io.Reader) error {
|
|||||||
log.Error(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("%s>> ", resp)
|
fmt.Printf("%s>> ", removeColourCodes(resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
if scanner.Err() != nil {
|
if scanner.Err() != nil {
|
||||||
@ -214,3 +215,10 @@ func interactiveMode(client *q3rcon.Rcon, input io.Reader) error {
|
|||||||
}
|
}
|
||||||
return nil
|
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, "")
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user