From 6d8d533bed6935411ce700b52ee3a0b3fbd2f20f Mon Sep 17 00:00:00 2001 From: "Andreas Renberg (IQAndreas)" Date: Sat, 13 Dec 2014 06:38:52 -0600 Subject: [PATCH] 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. --- client.go | 2 +- colors.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 804db32..7e256ee 100644 --- a/client.go +++ b/client.go @@ -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), } diff --git a/colors.go b/colors.go index d086444..c5e83df 100644 --- a/colors.go +++ b/colors.go @@ -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))]