-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.go
89 lines (62 loc) · 1.77 KB
/
view.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
package main
import (
"fmt"
)
func (g grid) View() string {
returnString := ""
modeString := ""
fileString := ""
if g.cursor.editMode {
modeString = "EDIT "
}
if g.saved {
fileString = g.filename + " (saved)"
} else {
fileString = g.filename + " (unsaved)"
}
referenced := g.fetchReferencedCells(g.cursor.vector.getCellContent(&g, false))
// Status Bar ////
returnString += fmt.Sprintf("\n%-34s %s\n",
modeString + " " + g.cursor.toString() + " " + g.cursor.getCellContent(&g, false),
fileString,
)
// find the min of the viewport size and the grid size
rowsToRender := g.viewport.offset.row + g.viewport.size.row
colsToRender := g.viewport.offset.col + g.viewport.size.col
// Header ////
returnString += "\n" + fmt.Sprintf("%-*s", firstColWidth, " ")
for col := g.viewport.offset.col; col < colsToRender; col++ {
width := g.widestCellInCol(col)
if col == g.cursor.vector.col {
returnString += ThSelected.Render(padStringToCenter(columnToLetters(col), width))
} else {
returnString += ThDeselected.Render(padStringToCenter(columnToLetters(col), width))
}
}
// Rows ////
for row := g.viewport.offset.row; row < rowsToRender; row++ {
returnString += "\n"
if row == g.cursor.vector.row {
returnString += TrSelected.Render(fmt.Sprintf("%d", row))
} else {
returnString += TrDeselected.Render(fmt.Sprintf("%d", row))
}
// Columns ////
for col := g.viewport.offset.col; col < colsToRender; col++ {
// cell
v := vector{col: col, row: row}
cell := g.cells[v]
_, isRef := referenced[v]
if isRef {
returnString += cell.render(&g, v, true)
} else {
returnString += cell.render(&g, v, false)
}
}
}
returnString += "\n\nhelp ⌃h\n"
if showHelp {
returnString += helpText
}
return returnString
}