forked from kungfusheep/glyph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.go
More file actions
124 lines (107 loc) · 2.84 KB
/
display.go
File metadata and controls
124 lines (107 loc) · 2.84 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package glyph
import "strings"
// Display helpers for common UI patterns.
// LeaderStr creates a dot-leader string: "LABEL...........VALUE"
// Width is the total width including label and value.
// Deprecated: Use the Leader component for pointer binding support.
func LeaderStr(label, value string, width int) string {
dots := width - len(label) - len(value)
if dots < 1 {
dots = 1
}
return label + strings.Repeat(".", dots) + value
}
// LeaderDash creates a dash-leader string: "LABEL-----------VALUE"
func LeaderDash(label, value string, width int) string {
dashes := width - len(label) - len(value)
if dashes < 1 {
dashes = 1
}
return label + strings.Repeat("-", dashes) + value
}
// LED returns a single LED indicator: ● (on) or ○ (off)
func LED(on bool) string {
if on {
return "●"
}
return "○"
}
// LEDs returns multiple LED indicators: ●●○○
func LEDs(states ...bool) string {
var b strings.Builder
for _, on := range states {
if on {
b.WriteRune('●')
} else {
b.WriteRune('○')
}
}
return b.String()
}
// LEDsBracket returns bracketed LED indicators: [●●○○]
func LEDsBracket(states ...bool) string {
return "[" + LEDs(states...) + "]"
}
// Bar returns a segmented bar: ▮▮▮▯▯
func Bar(filled, total int) string {
var b strings.Builder
for i := range total {
if i < filled {
b.WriteRune('▮')
} else {
b.WriteRune('▯')
}
}
return b.String()
}
// BarBracket returns a bracketed bar: [▮▮▮▯▯]
func BarBracket(filled, total int) string {
return "[" + Bar(filled, total) + "]"
}
// Meter returns an analog-style meter: ├──●──────┤
func Meter(value, max, width int) string {
if width < 3 {
width = 3
}
inner := width - 2 // Account for ├ and ┤
pos := 0
if max > 0 {
pos = (value * (inner - 1)) / max
}
if pos >= inner {
pos = inner - 1
}
if pos < 0 {
pos = 0
}
var b strings.Builder
b.WriteRune('├')
for i := range inner {
if i == pos {
b.WriteRune('●')
} else {
b.WriteRune('─')
}
}
b.WriteRune('┤')
return b.String()
}
// DrawPanel draws a bordered panel with title and returns the interior region.
// Title appears in the top border: ┌─ TITLE ─────┐
func (b *Buffer) DrawPanel(x, y, w, h int, title string, style Style) *Region {
b.DrawBorder(x, y, w, h, BorderSingle, style)
if title != "" {
titleStr := string(BorderSingle.Horizontal) + " " + title + " "
b.WriteString(x+1, y, titleStr, style)
}
return b.Region(x+1, y+1, w-2, h-2)
}
// DrawPanelEx draws a panel with custom border style.
func (b *Buffer) DrawPanelEx(x, y, w, h int, title string, border BorderStyle, style Style) *Region {
b.DrawBorder(x, y, w, h, border, style)
if title != "" {
titleStr := string(border.Horizontal) + " " + title + " "
b.WriteString(x+1, y, titleStr, style)
}
return b.Region(x+1, y+1, w-2, h-2)
}