forked from wildeyedskies/stmp
-
Notifications
You must be signed in to change notification settings - Fork 6
/
page_log.go
46 lines (33 loc) · 798 Bytes
/
page_log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2023 The STMPS Authors
// SPDX-License-Identifier: GPL-3.0-only
package main
import (
"time"
"github.com/rivo/tview"
)
type LogPage struct {
Root *tview.Flex
logList *tview.List
// external refs
ui *Ui
}
func (ui *Ui) createLogPage() *LogPage {
logPage := LogPage{
ui: ui,
}
logPage.logList = tview.NewList().ShowSecondaryText(false)
logPage.Root = tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(logPage.logList, 0, 1, true)
return &logPage
}
func (l *LogPage) Print(line string) {
l.ui.app.QueueUpdateDraw(func() {
line := time.Now().Local().Format("(15:04:05) ") + line
l.logList.InsertItem(0, line, "", 0, nil)
// Make sure the log list doesn't grow infinitely
for l.logList.GetItemCount() > 100 {
l.logList.RemoveItem(-1)
}
})
}