mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-07-20 20:44:30 +02:00
Added /colors command to toggle coloring.
This commit is contained in:
parent
21bf1ad147
commit
c88c30391d
23
client.go
23
client.go
@ -59,6 +59,7 @@ type Client struct {
|
||||
silencedUntil time.Time
|
||||
lastTX time.Time
|
||||
beepMe bool
|
||||
colorMe bool
|
||||
}
|
||||
|
||||
func NewClient(server *Server, conn *ssh.ServerConn) *Client {
|
||||
@ -70,6 +71,7 @@ func NewClient(server *Server, conn *ssh.ServerConn) *Client {
|
||||
Msg: make(chan string, MSG_BUFFER),
|
||||
ready: make(chan struct{}, 1),
|
||||
lastTX: time.Now(),
|
||||
colorMe: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +84,9 @@ func (c *Client) SysMsg(msg string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func (c *Client) Write(msg string) {
|
||||
if(!c.colorMe) {
|
||||
msg = DeColorString(msg)
|
||||
}
|
||||
c.term.Write([]byte(msg + "\r\n"))
|
||||
}
|
||||
|
||||
@ -129,7 +134,15 @@ func (c *Client) Resize(width int, height int) error {
|
||||
|
||||
func (c *Client) Rename(name string) {
|
||||
c.Name = name
|
||||
c.term.SetPrompt(fmt.Sprintf("[%s] ", c.ColoredName()))
|
||||
var prompt string
|
||||
|
||||
if(c.colorMe) {
|
||||
prompt = c.ColoredName()
|
||||
} else {
|
||||
prompt = c.Name
|
||||
}
|
||||
|
||||
c.term.SetPrompt(fmt.Sprintf("[%s] ", prompt))
|
||||
}
|
||||
|
||||
func (c *Client) Fingerprint() string {
|
||||
@ -324,6 +337,14 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
||||
c.Server.SetMotd(c, newmotd)
|
||||
c.Server.MotdBroadcast(c)
|
||||
}
|
||||
case "/color":
|
||||
c.colorMe = !c.colorMe
|
||||
c.Rename(c.Name)
|
||||
if c.colorMe {
|
||||
c.SysMsg("Turned on color chat")
|
||||
} else {
|
||||
c.SysMsg("Turned off color chat")
|
||||
}
|
||||
|
||||
default:
|
||||
c.SysMsg("Invalid command: %s", line)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"math/rand"
|
||||
"time"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const RESET string = "\033[0m"
|
||||
@ -16,6 +17,12 @@ 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" }
|
||||
var r *regexp.Regexp = regexp.MustCompile("\033\\[[\\d;]+m")
|
||||
|
||||
func DeColorString(s string) string {
|
||||
s = r.ReplaceAllString(s, "")
|
||||
return s
|
||||
}
|
||||
|
||||
func RandomColor256() string {
|
||||
return fmt.Sprintf("38;05;%d", rand.Intn(256))
|
||||
@ -38,4 +45,4 @@ func RandomColorInit() {
|
||||
// This is not HTML where you can just do a </style> to resume your previous formatting!
|
||||
func ContinuousFormat(format string, str string) string {
|
||||
return SYSTEM_MESSAGE_FORMAT + strings.Replace(str, RESET, format, -1) + RESET
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user