Most elements in cordless are now themeable
MODIFY
config/theme.go
config/theme.go
@@ -15,6 +15,12 @@ import (
// applied to tview.Styles
type Theme struct {
*tview.Theme
+ BlockedUserColor tcell.Color
+ InfoMessageColor tcell.Color
+ BotColor tcell.Color
+ MessageTimeColor tcell.Color
+ DefaultUserColor tcell.Color
+ LinkColor tcell.Color
AttentionColor tcell.Color
ErrorColor tcell.Color
RandomUserColors []tcell.Color
@@ -45,6 +51,12 @@ func createDefaultTheme() *Theme {
InverseTextColor: tcell.ColorBlue,
ContrastSecondaryTextColor: tcell.ColorDarkCyan,
},
+ BlockedUserColor: tcell.ColorGray,
+ InfoMessageColor: tcell.ColorGray,
+ BotColor: tcell.NewRGBColor(0x94, 0x96, 0xfc),
+ MessageTimeColor: tcell.ColorGray,
+ LinkColor: tcell.ColorDarkCyan,
+ DefaultUserColor: tcell.NewRGBColor(0x44, 0xe5, 0x44),
AttentionColor: tcell.ColorOrange,
ErrorColor: tcell.ColorRed,
RandomUserColors: []tcell.Color{

MODIFY
discordutil/users.go
discordutil/users.go
@@ -12,7 +12,6 @@ import (
var (
botPrefix = tview.Escape("[BOT]")
- botColor = "#9496fc"
//global state that persist during a session.
userColorCache = make(map[string]string)
@@ -24,7 +23,7 @@ var (
// a new color will be a generated and cached.
func GetUserColor(user *discordgo.User) string {
if user.Bot {
- return botColor
+ return tviewutil.ColorToHex(config.GetTheme().BotColor)
}
color, ok := userColorCache[user.ID]
@@ -40,7 +39,7 @@ func GetUserColor(user *discordgo.User) string {
func getRandomColorString() string {
randColorLength := len(config.GetTheme().RandomUserColors)
if randColorLength == 0 {
- return "[#44e544]"
+ return "[" + tviewutil.ColorToHex(config.GetTheme().DefaultUserColor) + "]"
} else if randColorLength == 1 {
return tviewutil.ColorToHex(config.GetTheme().RandomUserColors[0])
}

MODIFY
discordutil/users_test.go
discordutil/users_test.go
@@ -4,6 +4,9 @@ import (
"reflect"
"testing"
+ "github.com/Bios-Marcel/cordless/ui/tviewutil"
+
+ "github.com/Bios-Marcel/cordless/config"
"github.com/Bios-Marcel/discordgo"
)
@@ -37,7 +40,7 @@ func TestGetUserColor(t *testing.T) {
ID: "1398541219874",
Bot: true,
},
- want: botColor,
+ want: tviewutil.ColorToHex(config.GetTheme().BotColor),
},
{
name: "Verify that a new ID doesn't get the same color as a specific previous ID.",

MODIFY
tools/theme/theme.go
tools/theme/theme.go
@@ -25,6 +25,12 @@ func main() {
InverseTextColor: tcell.NewRGBColor(104, 142, 196),
ContrastSecondaryTextColor: tcell.NewRGBColor(104, 142, 196),
},
+ BlockedUserColor: tcell.ColorGray,
+ InfoMessageColor: tcell.ColorGray,
+ BotColor: tcell.NewRGBColor(0x94, 0x96, 0xfc),
+ MessageTimeColor: tcell.ColorGray,
+ LinkColor: tcell.ColorDarkCyan,
+ DefaultUserColor: tcell.NewRGBColor(0x44, 0xe5, 0x44),
AttentionColor: tcell.ColorOrange,
ErrorColor: tcell.ColorRed,
RandomUserColors: []tcell.Color{

MODIFY
ui/chatview.go
ui/chatview.go
@@ -29,7 +29,6 @@ import (
)
var (
- linkColor = "[#efec1c]"
codeBlockRegex = regexp.MustCompile("(?sm)(^|.)?(\x60\x60\x60(.*?)?\n(.+?)\x60\x60\x60)($|.)")
colorRegex = regexp.MustCompile("\\[#.{6}\\]")
channelMentionRegex = regexp.MustCompile(`<#\d*>`)
@@ -176,7 +175,7 @@ func NewChatView(state *discordgo.State, ownUserID string) *ChatView {
SetRegions(true).
SetWordWrap(true).
SetBorder(true).
- SetTitleColor(tcell.ColorGreen)
+ SetTitleColor(config.GetTheme().InverseTextColor)
return &chatView
}
@@ -382,34 +381,34 @@ func (chatView *ChatView) formatMessageAuthor(message *discordgo.Message) string
return "[" + discordutil.GetUserColor(message.Author) + "]" + messageAuthor
}
- return "[#44e544]" + messageAuthor
+ return "[" + tviewutil.ColorToHex(config.GetTheme().DefaultUserColor) + "]" + messageAuthor
}
func (chatView *ChatView) formatMessageText(message *discordgo.Message) string {
if message.Type == discordgo.MessageTypeDefault {
return chatView.formatDefaultMessageText(message)
} else if message.Type == discordgo.MessageTypeGuildMemberJoin {
- return "[gray]joined the server."
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]joined the server."
} else if message.Type == discordgo.MessageTypeCall {
- return "[gray]has started a call."
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]has started a call."
} else if message.Type == discordgo.MessageTypeChannelIconChange {
- return "[gray]changed the channel icon."
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]changed the channel icon."
} else if message.Type == discordgo.MessageTypeChannelNameChange {
- return "[gray]changed the channel name to " + message.Content + "."
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]changed the channel name to " + message.Content + "."
} else if message.Type == discordgo.MessageTypeChannelPinnedMessage {
- return "[gray]pinned a message."
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]pinned a message."
} else if message.Type == discordgo.MessageTypeRecipientAdd {
- return "[gray]added " + message.Mentions[0].Username + " to the group."
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]added " + message.Mentions[0].Username + " to the group."
} else if message.Type == discordgo.MessageTypeRecipientRemove {
- return "[gray]removed " + message.Mentions[0].Username + " from the group."
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]removed " + message.Mentions[0].Username + " from the group."
} else if message.Type == discordgo.MessageTypeChannelFollowAdd {
- return "[gray]has added '" + message.Content + "' to this channel"
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]has added '" + message.Content + "' to this channel"
}
//TODO Support boost messages; Would be handy to see what they look like first.
//Might happen when there are unsupported types.
- return "[gray]message couldn't be rendered."
+ return "[" + tviewutil.ColorToHex(config.GetTheme().InfoMessageColor) + "]message couldn't be rendered."
}
func (chatView *ChatView) formatDefaultMessageText(message *discordgo.Message) string {
@@ -425,12 +424,12 @@ func (chatView *ChatView) formatDefaultMessageText(message *discordgo.Message) s
return data
}
- return linkColor + "@" + role.Name + "[" + tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor) + "]"
+ return "[" + tviewutil.ColorToHex(config.GetTheme().LinkColor) + "]@" + role.Name + "[" + tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor) + "]"
})
- messageText = strings.NewReplacer(
- "@everyone", linkColor+"@everyone["+tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor)+"]",
- "@here", linkColor+"@here["+tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor)+"]",
+ messageText = strings.NewReplacer("@everyone", "["+tviewutil.ColorToHex(config.GetTheme().LinkColor)+"]@everyone["+
+ tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor)+"]", "@here",
+ "["+tviewutil.ColorToHex(config.GetTheme().LinkColor)+"]@here["+tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor)+"]",
).Replace(messageText)
for _, user := range message.Mentions {
@@ -448,9 +447,9 @@ func (chatView *ChatView) formatDefaultMessageText(message *discordgo.Message) s
var color string
if chatView.state.User.ID == user.ID {
- color = "[#ef9826]"
+ color = "[" + tviewutil.ColorToHex(config.GetTheme().AttentionColor) + "]"
} else {
- color = linkColor
+ color = "[" + tviewutil.ColorToHex(config.GetTheme().LinkColor) + "]"
}
replacement := color + "@" + userName + "[" + tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor) + "]"
@@ -468,7 +467,7 @@ func (chatView *ChatView) formatDefaultMessageText(message *discordgo.Message) s
return data
}
- return linkColor + "#" + channel.Name + "[" + tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor) + "]"
+ return "[" + tviewutil.ColorToHex(config.GetTheme().LinkColor) + "]#" + channel.Name + "[" + tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor) + "]"
})
// FIXME Needs improvement, as it wastes space and breaks things
@@ -655,7 +654,7 @@ func (chatView *ChatView) messagePartsToColouredString(timestamp discordgo.Times
timeCellText = times.TimeToLocalString(&time)
}
- return fmt.Sprintf("[gray]%s %s ["+tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor)+"]%s[\"\"][\"\"]", timeCellText, author, message)
+ return fmt.Sprintf("["+tviewutil.ColorToHex(config.GetTheme().MessageTimeColor)+"]%s %s ["+tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor)+"]%s[\"\"][\"\"]", timeCellText, author, message)
}
func parseBoldAndUnderline(messageText string) string {

Most elements in cordless are now themeable