From fa8147f07aed32614d97cf062ae1d6773cb7d1f9 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 20 Feb 2020 22:11:09 +0200 Subject: Add background color for reactions --- go.mod | 2 +- go.sum | 2 ++ ui/messages/base.go | 24 ++++++++++-------------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 4c56796..78cea34 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,6 @@ require ( gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 gopkg.in/yaml.v2 v2.2.8 maunium.net/go/mautrix v0.1.0-alpha.3.0.20200220001222-8dc3dd5d538d - maunium.net/go/mauview v0.0.0-20200219222453-b984e20438e6 + maunium.net/go/mauview v0.0.0-20200220201003-92b19f8819b4 maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09 ) diff --git a/go.sum b/go.sum index c6fb4a5..a13fd38 100644 --- a/go.sum +++ b/go.sum @@ -90,5 +90,7 @@ maunium.net/go/mauview v0.0.0-20200219201346-81706f13fc83 h1:KdMJGXJw9Z/uBzg+19h maunium.net/go/mauview v0.0.0-20200219201346-81706f13fc83/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg= maunium.net/go/mauview v0.0.0-20200219222453-b984e20438e6 h1:yYs5rsnDQrZie4eeWlcgdw4QSO0eFCiAoA8aiiE+yok= maunium.net/go/mauview v0.0.0-20200219222453-b984e20438e6/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg= +maunium.net/go/mauview v0.0.0-20200220201003-92b19f8819b4 h1:60G4iPYhO5Z4qkcniM+xPBeXNmuyD1tqXzj8ryeEdWY= +maunium.net/go/mauview v0.0.0-20200220201003-92b19f8819b4/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg= maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09 h1:hu+R+0nodoZPS19WGyYiw/d63+/NQS/R3Duw3d9HqAU= maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09/go.mod h1:Ru7KmI5AU7xHUx6hGltgJvknrS+8jlGGMKK15pZuc9k= diff --git a/ui/messages/base.go b/ui/messages/base.go index 4dba9de..d8ebc9a 100644 --- a/ui/messages/base.go +++ b/ui/messages/base.go @@ -49,7 +49,7 @@ type ReactionItem struct { } func (ri ReactionItem) String() string { - return fmt.Sprintf("%d %s", ri.Count, ri.Key) + return fmt.Sprintf("%d×%s", ri.Count, ri.Key) } type ReactionSlice []ReactionItem @@ -83,8 +83,6 @@ type UIMessage struct { ReplyTo *UIMessage Reactions ReactionSlice Renderer MessageRenderer - - reactionBuffer string } const DateFormat = "January _2, 2006" @@ -305,7 +303,15 @@ func (msg *UIMessage) DrawReactions(screen mauview.Screen) { } width, height := screen.Size() screen = mauview.NewProxyScreen(screen, 0, height-1, width, 1) - mauview.Print(screen, msg.reactionBuffer, 0, 0, width, mauview.AlignLeft, mauview.Styles.PrimaryTextColor) + + x := 0 + for _, reaction := range msg.Reactions { + _, drawn := mauview.PrintWithStyle(screen, reaction.String(), x, 0, width - x, mauview.AlignLeft, tcell.StyleDefault.Foreground(mauview.Styles.PrimaryTextColor).Background(tcell.ColorDarkGreen)) + x += drawn + 1 + if x >= width { + break + } + } } func (msg *UIMessage) Draw(screen mauview.Screen) { @@ -329,19 +335,9 @@ func (msg *UIMessage) CalculateReplyBuffer(preferences config.UserPreferences, w msg.ReplyTo.CalculateBuffer(preferences, width-1) } -func (msg *UIMessage) CalculateReactionBuffer() { - var text strings.Builder - for _, reaction := range msg.Reactions { - text.WriteString(reaction.String()) - text.WriteRune(' ') - } - msg.reactionBuffer = text.String() -} - func (msg *UIMessage) CalculateBuffer(preferences config.UserPreferences, width int) { msg.Renderer.CalculateBuffer(preferences, width, msg) msg.CalculateReplyBuffer(preferences, width) - msg.CalculateReactionBuffer() } func (msg *UIMessage) DrawReply(screen mauview.Screen) mauview.Screen { -- cgit v1.2.3