v0.7.1 client readline removed for cross-platform compatibility with wasm, client logic fix fixes and refactor
This commit is contained in:
@ -22,23 +22,23 @@ func RenderBoard(asciiBoard string) {
|
||||
switch {
|
||||
case char >= 'a' && char <= 'h' && isRankLine:
|
||||
// File letters - Cyan
|
||||
fmt.Printf("%s%c%s", Cyan, char, Reset)
|
||||
Print(Cyan, "%c", char)
|
||||
case char >= 'A' && char <= 'Z':
|
||||
// White pieces - Blue
|
||||
fmt.Printf("%s%c%s", Blue, char, Reset)
|
||||
Print(Blue, "%c", char)
|
||||
case char >= 'a' && char <= 'z' && !isRankLine:
|
||||
// Black pieces - Red
|
||||
fmt.Printf("%s%c%s", Red, char, Reset)
|
||||
Print(Red, "%c", char)
|
||||
case char == '.':
|
||||
// Empty squares
|
||||
fmt.Printf(".")
|
||||
Print(White, ".")
|
||||
case char >= '1' && char <= '8':
|
||||
// Rank numbers - Cyan
|
||||
fmt.Printf("%s%c%s", Cyan, char, Reset)
|
||||
Print(Cyan, "%c", char)
|
||||
case char == ' ':
|
||||
fmt.Printf(" ")
|
||||
Print(Reset, " ")
|
||||
default:
|
||||
fmt.Printf("%c", char)
|
||||
Print(Reset, "%c", char)
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
// FILE: lixenwraith/chess/internal/client/display/colors.go
|
||||
package display
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Terminal color codes
|
||||
const (
|
||||
Reset = "\033[0m"
|
||||
@ -13,6 +18,35 @@ const (
|
||||
White = "\033[37m"
|
||||
)
|
||||
|
||||
// C wraps text with color and reset codes
|
||||
func C(color, text string) string {
|
||||
return color + text + Reset
|
||||
}
|
||||
|
||||
// Print outputs colored text immediately
|
||||
func Print(color, format string, args ...any) {
|
||||
fmt.Printf(C(color, format), args...)
|
||||
}
|
||||
|
||||
// Println outputs colored text with newline
|
||||
func Println(color, format string, args ...any) {
|
||||
fmt.Println(C(color, fmt.Sprintf(format, args...)))
|
||||
}
|
||||
|
||||
// Build creates a multi-colored string
|
||||
type Builder struct {
|
||||
parts []string
|
||||
}
|
||||
|
||||
func (b *Builder) Add(color, text string) *Builder {
|
||||
b.parts = append(b.parts, C(color, text))
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *Builder) String() string {
|
||||
return strings.Join(b.parts, "")
|
||||
}
|
||||
|
||||
// Prompt returns a colored prompt string
|
||||
func Prompt(text string) string {
|
||||
return Yellow + text + Yellow + " > " + Reset
|
||||
|
||||
@ -7,10 +7,10 @@ import (
|
||||
)
|
||||
|
||||
// PrettyPrintJSON prints formatted JSON
|
||||
func PrettyPrintJSON(v interface{}) {
|
||||
func PrettyPrintJSON(v any) {
|
||||
data, err := json.MarshalIndent(v, "", " ")
|
||||
if err != nil {
|
||||
fmt.Printf("%sError formatting JSON: %s%s\n", Red, err.Error(), Reset)
|
||||
Print(Red, "Error formatting JSON: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println(string(data))
|
||||
|
||||
Reference in New Issue
Block a user