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
|
package tui
import (
"fmt"
"strings"
)
func (a *App) setupInitialScreen(width, termHeight int) {
if a.inlineHeight > 0 {
a.setupInlineScreen(width, termHeight)
return
}
a.terminal.EnterAltScreen()
a.buffer = NewBuffer(width, termHeight)
a.needsFullRedraw = true
}
func (a *App) setupInlineScreen(width, termHeight int) {
if a.inlineHeight > termHeight {
a.inlineHeight = termHeight
}
if a.inlineHeight < 0 {
a.inlineHeight = 0
}
a.reserveInlineRegion()
a.inlineStartRow = max(termHeight-a.inlineHeight, 0)
a.inlineSession = newInlineSession(a.terminal)
a.buffer = NewBuffer(width, a.inlineHeight)
a.applyInlineStartupPolicy(termHeight)
a.needsFullRedraw = true
}
func (a *App) reserveInlineRegion() {
if a.inlineHeight < 1 {
return
}
_, _ = a.terminal.WriteDirect([]byte(strings.Repeat("\r\n", a.inlineHeight)))
_, _ = a.terminal.WriteDirect(fmt.Appendf(nil, "\033[%dA", a.inlineHeight))
}
func (a *App) applyInlineStartupPolicy(termHeight int) {
historyCapacity := a.inlineStartRow
switch a.inlineStartupMode {
case InlineStartupFreshViewport:
a.clearVisibleViewport()
a.inlineLayout = newInlineLayoutState(historyCapacity)
case InlineStartupSoftReset:
a.softResetVisibleViewport(termHeight)
a.inlineLayout = newInlineLayoutState(historyCapacity)
case InlineStartupPreserveVisible:
fallthrough
default:
a.inlineLayout = newInlineLayoutState(historyCapacity)
a.inlineLayout.invalidate(historyCapacity)
}
}
func (a *App) clearVisibleViewport() {
a.terminal.SetCursor(0, 0)
a.terminal.ClearToEnd()
}
func (a *App) softResetVisibleViewport(termHeight int) {
if termHeight < 1 {
return
}
a.terminal.SetCursor(0, termHeight-1)
_, _ = a.terminal.WriteDirect([]byte(strings.Repeat("\r\n", termHeight)))
}
|