mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-14 08:07:16 +03:00
Add basic terminal color support
Also added a little command to test color support. This will come in handy!
This commit is contained in:
parent
973a06aa75
commit
7767f3e52b
@ -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
24
colors.go
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user