mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-09 03:42:25 +03:00
Color usernames with colors
(at least next to their messages)
This commit is contained in:
parent
7767f3e52b
commit
1b73035495
@ -35,6 +35,7 @@ type Client struct {
|
|||||||
Conn *ssh.ServerConn
|
Conn *ssh.ServerConn
|
||||||
Msg chan string
|
Msg chan string
|
||||||
Name string
|
Name string
|
||||||
|
Color string
|
||||||
Op bool
|
Op bool
|
||||||
ready chan struct{}
|
ready chan struct{}
|
||||||
term *terminal.Terminal
|
term *terminal.Terminal
|
||||||
@ -48,6 +49,7 @@ func NewClient(server *Server, conn *ssh.ServerConn) *Client {
|
|||||||
Server: server,
|
Server: server,
|
||||||
Conn: conn,
|
Conn: conn,
|
||||||
Name: conn.User(),
|
Name: conn.User(),
|
||||||
|
Color: RandomColor(),
|
||||||
Msg: make(chan string, MSG_BUFFER),
|
Msg: make(chan string, MSG_BUFFER),
|
||||||
ready: make(chan struct{}, 1),
|
ready: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
@ -83,7 +85,7 @@ func (c *Client) Resize(width int, height int) error {
|
|||||||
|
|
||||||
func (c *Client) Rename(name string) {
|
func (c *Client) Rename(name string) {
|
||||||
c.Name = name
|
c.Name = name
|
||||||
c.term.SetPrompt(fmt.Sprintf("[%s] ", name))
|
c.term.SetPrompt(fmt.Sprintf("[%s] ", ColorString(c.Color, c.Name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Fingerprint() string {
|
func (c *Client) Fingerprint() string {
|
||||||
@ -222,7 +224,7 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := fmt.Sprintf("%s: %s", c.Name, line)
|
msg := fmt.Sprintf("%s: %s", ColorString(c.Color, c.Name), line)
|
||||||
if c.IsSilenced() || len(msg) > 1000 {
|
if c.IsSilenced() || len(msg) > 1000 {
|
||||||
c.Msg <- fmt.Sprintf("-> Message rejected.")
|
c.Msg <- fmt.Sprintf("-> Message rejected.")
|
||||||
continue
|
continue
|
||||||
@ -233,7 +235,7 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) handleChannels(channels <-chan ssh.NewChannel) {
|
func (c *Client) handleChannels(channels <-chan ssh.NewChannel) {
|
||||||
prompt := fmt.Sprintf("[%s] ", c.Name)
|
prompt := fmt.Sprintf("[%s] ", ColorString(c.Color, c.Name))
|
||||||
|
|
||||||
hasShell := false
|
hasShell := false
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user