aboutsummaryrefslogtreecommitdiff
path: root/internal/chat/logs.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/chat/logs.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/chat/logs.go b/internal/chat/logs.go
new file mode 100644
index 0000000..09d60fe
--- /dev/null
+++ b/internal/chat/logs.go
@@ -0,0 +1,44 @@
+package chat
+
+import "time"
+
+type Logs struct {
+ entries [20]LogEntry
+ start int
+}
+
+func (l *Logs) Append(le LogEntry) {
+ l.entries[l.start] = le
+ l.start++
+ if l.start == len(l.entries) {
+ l.start = 0
+ }
+}
+
+func (l *Logs) Get() []LogEntry {
+ result := make([]LogEntry, 0, len(l.entries))
+ for i := l.start; i < len(l.entries); i++ {
+ result = append(result, l.entries[i])
+ }
+ for i := 0; i < l.start; i++ {
+ result = append(result, l.entries[i])
+ }
+
+ return result
+}
+
+type LogEntry struct {
+ Username string
+ Time time.Time
+ Message string
+ Type LogEntryType
+}
+
+type LogEntryType int
+
+const (
+ TypeNone LogEntryType = iota
+ TypeJoined
+ TypeLeft
+ TypeMessage
+)