aboutsummaryrefslogtreecommitdiff
path: root/ui/messages
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-04-13 00:51:58 +0300
committerTulir Asokan <tulir@maunium.net>2019-04-13 00:51:58 +0300
commit43a7bdab7262c015b50e3e673e80389f9514f9ca (patch)
tree0efd957e49ebe6c6350a3b9067e3068b24b2448c /ui/messages
parentabd21affc42ad65968c946c3bbd6c63eba342981 (diff)
Add better stringification for UI message types for debugging
Diffstat (limited to 'ui/messages')
-rw-r--r--ui/messages/base.go15
-rw-r--r--ui/messages/html/base.go2
-rw-r--r--ui/messages/html/container.go5
-rw-r--r--ui/messages/htmlmessage.go10
4 files changed, 29 insertions, 3 deletions
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())
+}