Skip to content

Commit bbfaa55

Browse files
committed
Fixed bug with alternative screen buffer and cursor save/restore
1 parent 116a43d commit bbfaa55

File tree

4 files changed

+7
-31
lines changed

4 files changed

+7
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
# Directories
55
/dist
6+
/private

cmd/aws-knox/test.go

-26
This file was deleted.

pkg/ansi/ansi.go

+4
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ func AlternativeBuffer() {
4141
func NormalBuffer() {
4242
fmt.Fprint(Writer, "\033[?1049l")
4343
}
44+
45+
func MoveCursorUp(n int) {
46+
fmt.Fprintf(Writer, "\033[%dA", n)
47+
}

sdk/picker/picker.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ func (p *picker) filter() {
114114
}
115115

116116
func (p *picker) render() {
117-
ansi.SaveCursor()
118-
defer ansi.RestoreCursor()
119117
ansi.ClearDown()
120118
lightGray := color.ToForeground(LightGrayColor).Decorator()
121119
darkGray := color.ToForeground(DarkGrayColor).Decorator()
@@ -165,14 +163,13 @@ func (p *picker) render() {
165163
color.ResetStyle,
166164
)
167165
DefaultStyle.Printfln("")
166+
ansi.MoveCursorUp(7 + len(p.filtered))
168167
}
169168

170169
func (p *picker) Pick() *option {
171-
ansi.AlternativeBuffer()
172170
ansi.HideCursor()
173-
defer ansi.ShowCursor()
174171
defer ansi.ClearDown()
175-
defer ansi.NormalBuffer()
172+
defer ansi.ShowCursor()
176173
p.render()
177174
keyboard.Listen(func(key keys.Key) (stop bool, err error) {
178175
if key.Code == keys.CtrlC || key.Code == keys.Escape {

0 commit comments

Comments
 (0)