-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableutil.go
102 lines (95 loc) · 3.03 KB
/
tableutil.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package tui
import (
util2 "github.com/aldernero/timebox/pkg/util"
"github.com/evertras/bubble-table/table"
"time"
)
const (
columnKeyBox = "box"
columnKeyMin = "min"
columnKeyMax = "max"
columnKeyUse = "use"
columnKeyStart = "start"
columnKeyEnd = "end"
columnKeyDur = "dur"
columnWidthBox = 24
columnWidthTime = 20
columnWidthDur = 12
)
func makeBoxSummaryRow(box string, min, max, use time.Duration) table.Row {
return table.NewRow(table.RowData{
columnKeyBox: box,
columnKeyMin: min,
columnKeyMax: max,
columnKeyUse: util2.DurationParser(use),
})
}
func makeTimelineRow(box string, start time.Time, end time.Time) table.Row {
return table.NewRow(table.RowData{
columnKeyBox: box,
columnKeyStart: start.Format(time.DateTime),
columnKeyEnd: end.Format(time.DateTime),
columnKeyDur: util2.DurationParser(end.Sub(start)),
})
}
func makeBoxSummaryTable(tb util2.TimeBox, p util2.Period) table.Model {
boxes := tb.Boxes
var rows []table.Row
timespan := util2.PeriodSoFar(p, time.January)
for _, val := range tb.Names {
box := boxes[val]
minTime, maxTime := box.ScaledTimes(p)
spans := tb.GetSpansForBox(val, timespan)
usedTime := spans.Duration()
rows = append(rows, makeBoxSummaryRow(val, minTime, maxTime, usedTime))
}
return table.New([]table.Column{
table.NewFlexColumn(columnKeyBox, "Box", 2),
table.NewFlexColumn(columnKeyMin, "Min", 1),
table.NewFlexColumn(columnKeyMax, "Max", 1),
table.NewFlexColumn(columnKeyUse, "Used", 1),
}).WithRows(rows).
BorderRounded().
WithBaseStyle(TableStyle).
WithTargetWidth(UIWidth).
WithPageSize(SummaryPageSize).
Focused(true)
}
func makeBoxViewTable(tb util2.TimeBox, boxName string, p util2.Period) table.Model {
var rows []table.Row
timespan := util2.PeriodSoFar(p, time.January)
spans := tb.GetSpansForBox(boxName, timespan)
for _, val := range spans.Spans {
rows = append(rows, makeTimelineRow(boxName, val.Start, val.End))
}
return table.New([]table.Column{
table.NewFlexColumn(columnKeyBox, "Box", 2),
table.NewColumn(columnKeyStart, "Start", columnWidthTime),
table.NewColumn(columnKeyEnd, "End", columnWidthTime),
table.NewFlexColumn(columnKeyDur, "Duration", 1),
}).WithRows(rows).
BorderRounded().
WithBaseStyle(TableStyle).
WithTargetWidth(UIWidth).
WithPageSize(SummaryPageSize).
Focused(true)
}
func makeTimelineTable(tb util2.TimeBox, p util2.Period) table.Model {
var rows []table.Row
timespan := util2.PeriodSoFar(p, time.January)
spans := tb.GetSpansForTimespan(timespan)
for _, val := range spans.Spans {
rows = append(rows, makeTimelineRow(val.Box, val.Start, val.End))
}
return table.New([]table.Column{
table.NewFlexColumn(columnKeyBox, "Box", columnWidthBox),
table.NewFlexColumn(columnKeyStart, "Start", columnWidthDur),
table.NewFlexColumn(columnKeyEnd, "End", columnWidthDur),
table.NewFlexColumn(columnKeyDur, "Duration", columnWidthDur),
}).WithRows(rows).
BorderRounded().
WithBaseStyle(TableStyle).
WithTargetWidth(UIWidth).
WithPageSize(SummaryPageSize).
Focused(true)
}