From ee67c1446cbb3c446d59d4ebd9657a25bf0b702d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 10 Apr 2018 16:07:16 +0300 Subject: Convert message buffer to use custom colorable strings --- ui/messages/meta.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'ui/messages/meta.go') diff --git a/ui/messages/meta.go b/ui/messages/meta.go index 8cb6c1b..3f9c9ab 100644 --- a/ui/messages/meta.go +++ b/ui/messages/meta.go @@ -17,13 +17,16 @@ package messages import ( + "time" + "github.com/gdamore/tcell" "maunium.net/go/gomuks/interface" ) // BasicMeta is a simple variable store implementation of MessageMeta. type BasicMeta struct { - BSender, BTimestamp, BDate string + BSender string + BTimestamp time.Time BSenderColor, BTextColor, BTimestampColor tcell.Color } @@ -37,14 +40,19 @@ func (meta *BasicMeta) SenderColor() tcell.Color { return meta.BSenderColor } -// Timestamp returns the formatted time when the message was sent. -func (meta *BasicMeta) Timestamp() string { +// Timestamp returns the full time when the message was sent. +func (meta *BasicMeta) Timestamp() time.Time { return meta.BTimestamp } -// Date returns the formatted date when the message was sent. -func (meta *BasicMeta) Date() string { - return meta.BDate +// FormatTime returns the formatted time when the message was sent. +func (meta *BasicMeta) FormatTime() string { + return meta.BTimestamp.Format(TimeFormat) +} + +// FormatDate returns the formatted date when the message was sent. +func (meta *BasicMeta) FormatDate() string { + return meta.BTimestamp.Format(DateFormat) } // TextColor returns the color the actual content of the message should be shown in. @@ -63,7 +71,6 @@ func (meta *BasicMeta) TimestampColor() tcell.Color { func (meta *BasicMeta) CopyFrom(from ifc.MessageMeta) { meta.BSender = from.Sender() meta.BTimestamp = from.Timestamp() - meta.BDate = from.Date() meta.BSenderColor = from.SenderColor() meta.BTextColor = from.TextColor() meta.BTimestampColor = from.TimestampColor() -- cgit v1.2.3