gomuks/ui/types/meta.go

72 lines
2.3 KiB
Go
Raw Normal View History

2018-03-20 12:01:59 +01:00
// gomuks - A terminal Matrix client written in Go.
// Copyright (C) 2018 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package types
import (
"github.com/gdamore/tcell"
)
2018-03-22 22:40:26 +01:00
// MessageMeta is an interface to get the metadata of a message.
//
// See BasicMeta for a simple implementation and documentation of methods.
2018-03-20 12:01:59 +01:00
type MessageMeta interface {
GetSender() string
GetSenderColor() tcell.Color
GetTextColor() tcell.Color
GetTimestampColor() tcell.Color
GetTimestamp() string
GetDate() string
}
2018-03-22 22:40:26 +01:00
// BasicMeta is a simple variable store implementation of MessageMeta.
2018-03-20 12:01:59 +01:00
type BasicMeta struct {
Sender, Timestamp, Date string
SenderColor, TextColor, TimestampColor tcell.Color
}
2018-03-22 22:40:26 +01:00
// GetSender gets the string that should be displayed as the sender of this message.
2018-03-20 12:01:59 +01:00
func (meta *BasicMeta) GetSender() string {
return meta.Sender
}
2018-03-22 22:40:26 +01:00
// GetSenderColor returns the color the name of the sender should be shown in.
2018-03-20 12:01:59 +01:00
func (meta *BasicMeta) GetSenderColor() tcell.Color {
return meta.SenderColor
}
2018-03-22 22:40:26 +01:00
// GetTimestamp returns the formatted time when the message was sent.
2018-03-20 12:01:59 +01:00
func (meta *BasicMeta) GetTimestamp() string {
return meta.Timestamp
}
2018-03-22 22:40:26 +01:00
// GetDate returns the formatted date when the message was sent.
2018-03-20 12:01:59 +01:00
func (meta *BasicMeta) GetDate() string {
return meta.Date
}
2018-03-22 22:40:26 +01:00
// GetTextColor returns the color the actual content of the message should be shown in.
2018-03-20 12:01:59 +01:00
func (meta *BasicMeta) GetTextColor() tcell.Color {
return meta.TextColor
}
2018-03-22 22:40:26 +01:00
// GetTimestampColor returns the color the timestamp should be shown in.
//
// This usually does not apply to the date, as it is rendered separately from the message.
2018-03-20 12:01:59 +01:00
func (meta *BasicMeta) GetTimestampColor() tcell.Color {
return meta.TimestampColor
}