mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-07-20 20:44:30 +02:00
Colorize /name output with selected theme (#249)
* command.go: colorizing names according to theme (#205) * Adding safety check for nil and mono * Refactoring coloring into a function
This commit is contained in:
parent
80a5879f04
commit
206a9073f0
@ -173,9 +173,25 @@ func InitCommands(c *Commands) {
|
|||||||
Prefix: "/names",
|
Prefix: "/names",
|
||||||
Help: "List users who are connected.",
|
Help: "List users who are connected.",
|
||||||
Handler: func(room *Room, msg message.CommandMsg) error {
|
Handler: func(room *Room, msg message.CommandMsg) error {
|
||||||
// TODO: colorize
|
theme := msg.From().Config().Theme
|
||||||
names := room.NamesPrefix("")
|
|
||||||
body := fmt.Sprintf("%d connected: %s", len(names), strings.Join(names, ", "))
|
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()))
|
room.Send(message.NewSystemMsg(body, msg.From()))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user