Skip to content

Commit

Permalink
Fixed bug with alternative screen buffer and cursor save/restore
Browse files Browse the repository at this point in the history
  • Loading branch information
null93 committed Jun 20, 2024
1 parent 116a43d commit bbfaa55
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

# Directories
/dist
/private
26 changes: 0 additions & 26 deletions cmd/aws-knox/test.go

This file was deleted.

4 changes: 4 additions & 0 deletions pkg/ansi/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ func AlternativeBuffer() {
func NormalBuffer() {
fmt.Fprint(Writer, "\033[?1049l")
}

func MoveCursorUp(n int) {
fmt.Fprintf(Writer, "\033[%dA", n)
}
7 changes: 2 additions & 5 deletions sdk/picker/picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ func (p *picker) filter() {
}

func (p *picker) render() {
ansi.SaveCursor()
defer ansi.RestoreCursor()
ansi.ClearDown()
lightGray := color.ToForeground(LightGrayColor).Decorator()
darkGray := color.ToForeground(DarkGrayColor).Decorator()
Expand Down Expand Up @@ -165,14 +163,13 @@ func (p *picker) render() {
color.ResetStyle,
)
DefaultStyle.Printfln("")
ansi.MoveCursorUp(7 + len(p.filtered))
}

func (p *picker) Pick() *option {
ansi.AlternativeBuffer()
ansi.HideCursor()
defer ansi.ShowCursor()
defer ansi.ClearDown()
defer ansi.NormalBuffer()
defer ansi.ShowCursor()
p.render()
keyboard.Listen(func(key keys.Key) (stop bool, err error) {
if key.Code == keys.CtrlC || key.Code == keys.Escape {
Expand Down

0 comments on commit bbfaa55

Please sign in to comment.