Skip to content

Commit 2b13ca7

Browse files
committed
[feature] Show the last 5 commands in referee client
1 parent e07c49a commit 2b13ca7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cmd/ssl-ref-client/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/RoboCup-SSL/ssl-game-controller/pkg/refproto"
88
"github.com/golang/protobuf/proto"
99
"log"
10+
"math"
1011
"net"
1112
"time"
1213
)
@@ -16,6 +17,8 @@ const maxDatagramSize = 8192
1617
var refereeAddress = flag.String("address", "224.5.23.1:10003", "The multicast address of ssl-game-controller, default: 224.5.23.1:10003")
1718
var fullScreen = flag.Bool("fullScreen", false, "Print the formatted message to the console, clearing the screen during print")
1819

20+
var history []refproto.Referee_Command
21+
1922
func main() {
2023
flag.Parse()
2124

@@ -49,10 +52,26 @@ func main() {
4952
log.Println("Could not unmarshal referee message")
5053
continue
5154
}
55+
if len(history) == 0 || *refMsg.Command != history[len(history)-1] {
56+
history = append(history, *refMsg.Command)
57+
}
5258

5359
if *fullScreen {
5460
// clear screen, move cursor to upper left corner
5561
fmt.Print("\033[H\033[2J")
62+
63+
// print last commands
64+
fmt.Print("Last commands: ")
65+
n := int(math.Min(float64(len(history)), 5.0))
66+
for i := 0; i < n; i++ {
67+
fmt.Print(history[len(history)-1-i])
68+
if i != n-1 {
69+
fmt.Print(",")
70+
}
71+
}
72+
fmt.Println()
73+
fmt.Println()
74+
5675
// print message formatted with line breaks
5776
fmt.Print(proto.MarshalTextString(&refMsg))
5877
} else {

0 commit comments

Comments
 (0)