-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus_line.go
59 lines (50 loc) · 1.4 KB
/
status_line.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
package main
import (
"fmt"
"strings"
"time"
)
type StatusLine struct {
ExecutionTime float64
TotalBuffers int
TotalRows int
}
func NewStatusLine(explainPlan ExplainPlan) StatusLine {
return StatusLine{
ExecutionTime: explainPlan.executionTime,
TotalBuffers: explainPlan.TotalBuffers(),
TotalRows: explainPlan.TotalRows(),
}
}
func (s StatusLine) View(m Model) string {
styles := m.ctx.StatusStyles
if m.ctx.Width < 30 {
return ""
}
var buf strings.Builder
buf.WriteString(styles.AltNormal.Render(" "))
buf.WriteString(styles.Normal.Render(""))
buf.WriteString(styles.Normal.Render(" Time:"))
buf.WriteString(styles.Value.Render(" %.3fms "))
buf.WriteString(styles.AltNormal.Render(""))
buf.WriteString(styles.Normal.Render(""))
buf.WriteString(styles.Normal.Render(" Buffers:"))
buf.WriteString(styles.Value.Render(" %s "))
buf.WriteString(styles.AltNormal.Render(""))
buf.WriteString(styles.Normal.Render(""))
buf.WriteString(styles.Normal.Render(" Rows:"))
buf.WriteString(styles.Value.Render(" %s "))
buf.WriteString(styles.AltNormal.Render(" "))
var executionTime float64
if m.loading {
executionTime = float64(int64(m.stopwatch.Elapsed() / time.Millisecond))
} else {
executionTime = s.ExecutionTime
}
result := fmt.Sprintf(buf.String(),
executionTime,
formatUnderscores(s.TotalBuffers),
formatUnderscores(s.TotalRows),
)
return result
}