Skip to content

Commit

Permalink
Colorize /name output with selected theme (#249)
Browse files Browse the repository at this point in the history
* command.go: colorizing names according to theme (#205)

* Adding safety check for nil and mono

* Refactoring coloring into a function
  • Loading branch information
sleibrock authored and shazow committed Oct 4, 2017
1 parent 80a5879 commit 206a907
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions chat/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,25 @@ func InitCommands(c *Commands) {
Prefix: "/names",
Help: "List users who are connected.",
Handler: func(room *Room, msg message.CommandMsg) error {
// TODO: colorize
names := room.NamesPrefix("")
body := fmt.Sprintf("%d connected: %s", len(names), strings.Join(names, ", "))
theme := msg.From().Config().Theme

colorize := func(u *message.User) string {
return theme.ColorName(u)
}

if theme == nil {
colorize = func(u *message.User) string {
return u.Name()
}
}

names := room.Members.ListPrefix("")
colNames := make([]string, len(names))
for i, uname := range names {
colNames[i] = colorize(uname.Value().(*Member).User)
}

body := fmt.Sprintf("%d connected: %s", len(colNames), strings.Join(colNames, ", "))
room.Send(message.NewSystemMsg(body, msg.From()))
return nil
},
Expand Down

0 comments on commit 206a907

Please sign in to comment.