From 43a7bdab7262c015b50e3e673e80389f9514f9ca Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 13 Apr 2019 00:51:58 +0300 Subject: [PATCH] Add better stringification for UI message types for debugging --- ui/message-view.go | 2 +- ui/messages/base.go | 15 +++++++++++++++ ui/messages/html/base.go | 2 +- ui/messages/html/container.go | 5 +++-- ui/messages/htmlmessage.go | 10 ++++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ui/message-view.go b/ui/message-view.go index 2211503..1d9519e 100644 --- a/ui/message-view.go +++ b/ui/message-view.go @@ -197,7 +197,7 @@ func (view *MessageView) replaceBuffer(original messages.UIMessage, new messages } if start == -1 { - debug.Print("Called replaceBuffer() with message that was not in the buffer:", original.ID()) + debug.Print("Called replaceBuffer() with message that was not in the buffer:", original) debug.PrintStack() view.appendBuffer(new) return diff --git a/ui/messages/base.go b/ui/messages/base.go index c3ee1f0..cb9b371 100644 --- a/ui/messages/base.go +++ b/ui/messages/base.go @@ -18,6 +18,7 @@ package messages import ( "encoding/json" + "fmt" "time" "maunium.net/go/gomuks/config" @@ -286,3 +287,17 @@ func (msg *BaseMessage) DrawReply(screen mauview.Screen) mauview.Screen { msg.ReplyTo.Draw(replyScreen) return mauview.NewProxyScreen(screen, 0, replyHeight+2, width, height-replyHeight-2) } + +func (msg *BaseMessage) String() string { + return fmt.Sprintf(`&messages.BaseMessage{ + ID="%s", TxnID="%s", + Type="%s", Timestamp=%s, + Sender={ID="%s", Name="%s", Color=#%X}, + IsService=%t, IsHighlight=%t, +}`, + msg.MsgID, msg.MsgTxnID, + msg.MsgType, msg.MsgTimestamp.String(), + msg.MsgSenderID, msg.MsgSender, msg.MsgSenderColor.Hex(), + msg.MsgIsService, msg.MsgIsHighlight, + ) +} diff --git a/ui/messages/html/base.go b/ui/messages/html/base.go index 8014dc0..75cbd0c 100644 --- a/ui/messages/html/base.go +++ b/ui/messages/html/base.go @@ -78,7 +78,7 @@ func (be *BaseEntity) PlainText() string { // String returns a textual representation of this BaseEntity struct. func (be *BaseEntity) String() string { - return fmt.Sprintf(`&html.BaseEntity{Tag="%s", Style=%d, Block=%t, startX=%d, height=%d},`, + return fmt.Sprintf(`&html.BaseEntity{Tag="%s", Style=%d, Block=%t, startX=%d, height=%d}`, be.Tag, be.Style, be.Block, be.startX, be.height) } diff --git a/ui/messages/html/container.go b/ui/messages/html/container.go index b17bc1f..c1cf865 100644 --- a/ui/messages/html/container.go +++ b/ui/messages/html/container.go @@ -84,12 +84,13 @@ func (ce *ContainerEntity) String() string { return fmt.Sprintf(`&html.ContainerEntity{Base=%s, Indent=%d, Children=[]}`, ce.BaseEntity, ce.Indent) } var buf strings.Builder - _, _ = fmt.Fprintf(&buf, `&html.ContainerEntity{Base=%s, Indent=%d, Children=[`, ce.BaseEntity, ce.Indent) + _, _ = fmt.Fprintf(&buf, `&html.ContainerEntity{Base=%s, + Indent=%d, Children=[`, ce.BaseEntity, ce.Indent) for _, child := range ce.Children { buf.WriteString("\n ") buf.WriteString(strings.Join(strings.Split(strings.TrimRight(child.String(), "\n"), "\n"), "\n ")) } - buf.WriteString("\n]}\n,") + buf.WriteString("\n]},") return buf.String() } diff --git a/ui/messages/htmlmessage.go b/ui/messages/htmlmessage.go index 9ee1eab..9777303 100644 --- a/ui/messages/htmlmessage.go +++ b/ui/messages/htmlmessage.go @@ -17,6 +17,9 @@ package messages import ( + "fmt" + "strings" + "maunium.net/go/mautrix" "maunium.net/go/mauview" "maunium.net/go/tcell" @@ -98,3 +101,10 @@ func (hw *HTMLMessage) PlainText() string { func (hw *HTMLMessage) NotificationContent() string { return hw.Root.PlainText() } + +func (hw *HTMLMessage) String() string { + return fmt.Sprintf("&messages.HTMLMessage{\n" + + " Base=%s,\n" + + " Root=||\n%s\n" + + "}", strings.ReplaceAll(hw.BaseMessage.String(), "\n", "\n "), hw.Root.String()) +}