Skip to content

Colorize /name output with selected theme#249

Merged
shazow merged 3 commits intoshazow:masterfrom
ste5e99:color-names
Oct 4, 2017
Merged

Colorize /name output with selected theme#249
shazow merged 3 commits intoshazow:masterfrom
ste5e99:color-names

Conversation

@ste5e99
Copy link
Copy Markdown
Contributor

@ste5e99 ste5e99 commented Oct 4, 2017

In reference to #205.

/names output is now colored with the user's current theme. The upside is that it makes /names more appealing. The downside is clients that don't support ANSI escape codes might see a lot of garbage output instead of simple names. I'm not sure how to work around that issue itself.

How /names looks with the available themes:
colornames_example

I can add a check that skips the coloring if the selected theme is mono. That way a user can at least avoid getting garbage output from /names when they have no ANSI support.

body := fmt.Sprintf("%d connected: %s", len(names), strings.Join(names, ", "))
names := room.Members.ListPrefix("")
colNames := make([]string, len(names))
theme := msg.From().Config().Theme
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thiiiink it's possible for Theme to be nil.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a check for nil and write an early exit.

room.Send(message.NewSystemMsg(body, msg.From()))
return nil
}

Copy link
Copy Markdown
Owner

@shazow shazow Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the sake of avoiding subtly different duplicate code, what about something like:

colorize := func(u User) string {
    return theme.ColorName(u)
}
if (theme == nil ... etc) {
    colorize = func(u User) string {
        return u.Name
    }
}

Copy link
Copy Markdown
Owner

@shazow shazow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍮

@shazow shazow merged commit 206a907 into shazow:master Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants