From 815190be147e575f12211c468f8121e5c60e6337 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 16 Apr 2020 19:27:35 +0300 Subject: Update stuff and move pushrules to mautrix-go --- ui/widget/color.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'ui/widget/color.go') diff --git a/ui/widget/color.go b/ui/widget/color.go index edb966c..5a8d001 100644 --- a/ui/widget/color.go +++ b/ui/widget/color.go @@ -21,6 +21,8 @@ import ( "hash/fnv" "maunium.net/go/tcell" + + "maunium.net/go/mautrix/id" ) var colorNames = []string{ @@ -201,8 +203,17 @@ func GetHashColorName(s string) string { // GetHashColor gets the tcell Color value for the given string. // // GetHashColor calls GetHashColorName() and gets the Color value from the tcell.ColorNames map. -func GetHashColor(s string) tcell.Color { - return tcell.ColorNames[GetHashColorName(s)] +func GetHashColor(val interface{}) tcell.Color { + switch str := val.(type) { + case string: + return tcell.ColorNames[GetHashColorName(str)] + case *string: + return tcell.ColorNames[GetHashColorName(*str)] + case id.UserID: + return tcell.ColorNames[GetHashColorName(string(str))] + default: + return tcell.ColorNames["red"] + } } // AddColor adds tview color tags to the given string. -- cgit v1.2.3