-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.go
61 lines (50 loc) · 1.14 KB
/
list.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
package minigo
type List struct {
mntl *Minitel
orderedKeys []string
items map[string]string
refCol int
refRow int
maxRow int
brk int
}
func NewList(mntl *Minitel, row, col, maxRow, brk int) *List {
return &List{
mntl: mntl,
items: make(map[string]string),
orderedKeys: make([]string, 0),
refRow: row,
refCol: col,
maxRow: maxRow,
brk: brk,
}
}
func (l *List) AppendItem(key, value string) {
l.orderedKeys = append(l.orderedKeys, key)
l.items[key] = value
}
func (l *List) Display() {
line := l.refRow
l.mntl.MoveAt(l.refRow, l.refCol)
colAlign := 0
for _, key := range l.orderedKeys {
value := l.items[key]
l.mntl.Attributes(FondBlanc, CaractereNoir)
l.mntl.Print(" ")
l.mntl.Print(key)
l.mntl.Attributes(FondNormal, CaractereBlanc)
l.mntl.Print(" ")
l.mntl.Right(1)
l.mntl.Attributes(FondNormal)
l.mntl.Print(value)
line += l.brk
if line >= l.maxRow && colAlign == 0 {
line = l.refRow
colAlign = 20
l.mntl.MoveAt(l.refRow, l.refCol+colAlign)
} else {
l.mntl.Return(l.brk)
l.mntl.Right(l.refCol + colAlign)
}
}
}