Add basic terminal color support

Also added a little command to test color support. This will come in
handy!
This commit is contained in:
Andreas Renberg (IQAndreas) 2014-12-13 01:14:18 -06:00
parent 973a06aa75
commit 7767f3e52b
2 changed files with 27 additions and 0 deletions

View File

@ -119,6 +119,9 @@ func (c *Client) handleShell(channel ssh.Channel) {
if isCmd {
// TODO: Factor this out.
switch parts[0] {
case "/test-colors": // Shh, this command is a secret!
c.Write(ColorString("32", "Lorem ipsum dolor sit amet,"))
c.Write("consectetur " + ColorString("31;1", "adipiscing") + " elit.")
case "/exit":
channel.Close()
case "/help":

24
colors.go Normal file
View File

@ -0,0 +1,24 @@
package main
import (
"math/rand"
"time"
)
const RESET string = "\033[0m"
const BOLD string = "\033[1m"
const DIM string = "\033[2m"
const UNDERLINE string = "\033[4m"
const BLINK string = "\033[5m"
const INVERT string = "\033[7m"
var colors = []string { "31", "32", "33", "34", "35", "36", "37", "91", "92", "93", "94", "95", "96", "97" }
func RandomColor() string {
rand.Seed(time.Now().UTC().UnixNano())
return colors[rand.Intn(len(colors))]
}
func ColorString(format string, msg string) string {
return BOLD + "\033[" + format + "m" + msg + RESET
}