Skip to content

Commit 7cf0e7d

Browse files
unasukec-bata
andcommitted
Use escape sequence in prepareArea
Add SaveCursorPosition and RestoreCurcorPosition to output interface and use it in prepareArea Fix #70 Co-authored-by: Masashi Shibata <[email protected]>
1 parent 82a9122 commit 7cf0e7d

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

output.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ type ConsoleWriter interface {
146146
ScrollDown()
147147
// ScrollUp scroll display up one line.
148148
ScrollUp()
149+
// SaveCursorPosition saves current cursor position.
150+
SaveCursorPosition()
151+
// RestoreCursorPosition restores cursor position.
152+
RestoreCursorPosition()
149153

150154
/* Title */
151155

output_vt100.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ func (w *VT100Writer) ScrollUp() {
174174
w.WriteRaw([]byte{0x1b, 'M'})
175175
}
176176

177+
// SaveCursorPosition saves current cursor position.
178+
func (w *VT100Writer) SaveCursorPosition() {
179+
w.WriteRaw([]byte{0x1b, '[', 's'})
180+
}
181+
182+
// RestoreCursorPosition restores cursor position.
183+
func (w *VT100Writer) RestoreCursorPosition() {
184+
w.WriteRaw([]byte{0x1b, '[', 'u'})
185+
}
186+
177187
/* Title */
178188

179189
// SetTitle sets a title of terminal window.

render.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ func (r *Render) TearDown() {
6969
}
7070

7171
func (r *Render) prepareArea(lines int) {
72+
r.out.SaveCursorPosition()
73+
7274
for i := 0; i < lines; i++ {
73-
r.out.ScrollDown()
74-
}
75-
for i := 0; i < lines; i++ {
76-
r.out.ScrollUp()
75+
r.out.WriteStr("\n")
7776
}
77+
r.out.RestoreCursorPosition()
7878
}
7979

8080
// UpdateWinSize called when window size is changed.

0 commit comments

Comments
 (0)