Improve /list

This commit is contained in:
Andrey Petrov 2014-12-11 22:10:06 -08:00
parent 6b765e7a6c
commit b646abffb8
4 changed files with 10 additions and 4 deletions

View File

@ -8,7 +8,7 @@ Coming real soon.
* [x] Welcome message.
* [x] set term width properly
* [x] client map rather than list
* [ ] backfill chat history
* [x] backfill chat history
* [ ] tab completion
* [ ] /kick
* [x] /help
@ -16,4 +16,4 @@ Coming real soon.
* [x] /list
* [x] /nick
* [ ] pubkey fingerprint
* [ ] truncate usernames
* [x] truncate usernames

View File

@ -124,7 +124,8 @@ func (c *Client) handleShell(channel ssh.Channel) {
c.Msg <- fmt.Sprintf("-> Missing $NAME from: /whois $NAME\r\n")
}
case "/list":
c.Msg <- fmt.Sprintf("-> Connected: %s\r\n", strings.Join(c.Server.List(nil), ","))
names := c.Server.List(nil)
c.Msg <- fmt.Sprintf("-> %d connected: %s\r\n", len(names), strings.Join(names, ","))
default:
c.Msg <- fmt.Sprintf("-> Invalid command: %s\r\n", line)
}

View File

@ -1,3 +1,4 @@
// TODO: Split this out into its own module, it's kinda neat.
package main
type History struct {

View File

@ -57,8 +57,12 @@ func NewServer(privateKey []byte) (*Server, error) {
return &server, nil
}
func (s *Server) Len() int {
return len(s.clients)
}
func (s *Server) Broadcast(msg string, except *Client) {
logger.Debugf("Broadcast to %d: %s", len(s.clients), strings.TrimRight(msg, "\r\n"))
logger.Debugf("Broadcast to %d: %s", s.Len(), strings.TrimRight(msg, "\r\n"))
s.history.Add(msg)
for _, client := range s.clients {