v0.8.0 wasm client added, cli client and makefile updated
This commit is contained in:
13
cmd/chess-client-cli/exit_native.go
Normal file
13
cmd/chess-client-cli/exit_native.go
Normal file
@ -0,0 +1,13 @@
|
||||
// FILE: lixenwraith/chess/cmd/chess-client-cli/exit_native.go
|
||||
//go:build !js && !wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"chess/internal/client/display"
|
||||
)
|
||||
|
||||
func handleExit() (restart bool) {
|
||||
display.Println(display.Cyan, "Goodbye!")
|
||||
return false
|
||||
}
|
||||
19
cmd/chess-client-cli/exit_wasm.go
Normal file
19
cmd/chess-client-cli/exit_wasm.go
Normal file
@ -0,0 +1,19 @@
|
||||
// FILE: lixenwraith/chess/cmd/chess-client-cli/exit_wasm.go
|
||||
//go:build js && wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"chess/internal/client/display"
|
||||
)
|
||||
|
||||
func handleExit() (restart bool) {
|
||||
display.Println(display.Cyan, "Goodbye!")
|
||||
|
||||
display.Println(display.Yellow, "\n━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||
display.Println(display.Yellow, "Session ended.")
|
||||
display.Println(display.Yellow, "Restarting the client.")
|
||||
display.Println(display.Yellow, "━━━━━━━━━━━━━━━━━━━━━━━━\n")
|
||||
|
||||
return true
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
// FILE: lixenwraith/chess/cmd/chess-client/main.go
|
||||
// Package main implements an interactive debugging client for the chess server API.
|
||||
// FILE: lixenwraith/chess/cmd/chess-client-cli/main.go
|
||||
// Package main implements an interactive cli debugging client for the chess server API.
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -15,6 +15,21 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
for {
|
||||
if !runClient() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runClient() (restart bool) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
display.Println(display.Red, "Client crashed: %v", r)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
|
||||
s := &session.Session{
|
||||
APIBaseURL: "http://localhost:8080",
|
||||
Client: api.New("http://localhost:8080"),
|
||||
@ -51,8 +66,7 @@ func main() {
|
||||
|
||||
// Check for exit commands
|
||||
if line == "exit" || line == "quit" || line == "x" {
|
||||
display.Println(display.Cyan, "Goodbye!")
|
||||
break
|
||||
return handleExit()
|
||||
}
|
||||
|
||||
// Check for verbose flag
|
||||
@ -65,6 +79,8 @@ func main() {
|
||||
|
||||
registry.Execute(line)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func buildPrompt(s *session.Session) string {
|
||||
Reference in New Issue
Block a user