Allow for 256 different colors for username colors

I have heard this should be fairly well supported, so I'm hoping these
colors will all show up nicely for everyone.
This commit is contained in:
Andreas Renberg (IQAndreas) 2014-12-13 06:38:52 -06:00
parent 46d00b3e55
commit 6d8d533bed
2 changed files with 7 additions and 1 deletions

View File

@ -51,7 +51,7 @@ func NewClient(server *Server, conn *ssh.ServerConn) *Client {
Server: server,
Conn: conn,
Name: conn.User(),
Color: RandomColor(),
Color: RandomColor256(),
Msg: make(chan string, MSG_BUFFER),
ready: make(chan struct{}, 1),
}

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"strings"
"math/rand"
"time"
@ -16,6 +17,11 @@ const INVERT string = "\033[7m"
var colors = []string { "31", "32", "33", "34", "35", "36", "37", "91", "92", "93", "94", "95", "96", "97" }
func RandomColor256() string {
rand.Seed(time.Now().UTC().UnixNano())
return fmt.Sprintf("38;05;%d", rand.Intn(256))
}
func RandomColor() string {
rand.Seed(time.Now().UTC().UnixNano())
return colors[rand.Intn(len(colors))]