From bbfaa5599ea83787ed5e27298de4f8bccd7e57df Mon Sep 17 00:00:00 2001 From: Rafael Grigorian Date: Wed, 19 Jun 2024 22:52:56 -0500 Subject: [PATCH] Fixed bug with alternative screen buffer and cursor save/restore --- .gitignore | 1 + cmd/aws-knox/test.go | 26 -------------------------- pkg/ansi/ansi.go | 4 ++++ sdk/picker/picker.go | 7 ++----- 4 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 cmd/aws-knox/test.go diff --git a/.gitignore b/.gitignore index 12bc8a0..9d59dfb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ # Directories /dist +/private diff --git a/cmd/aws-knox/test.go b/cmd/aws-knox/test.go deleted file mode 100644 index fbd1ea6..0000000 --- a/cmd/aws-knox/test.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/null93/aws-knox/sdk/credentials" -) - -func main() { - sessions, _ := credentials.GetSessions() - for _, session := range sessions { - fmt.Println("Session Name: ", session.Name) - fmt.Println("Region: ", session.Region) - fmt.Println("Start URL: ", session.StartUrl) - fmt.Println("Scopes: ", session.Scopes) - fmt.Println("Client Credentials:", session.ClientCredentials != nil) - fmt.Println("Client Token: ", session.ClientToken != nil) - fmt.Println() - } - session := sessions.FindByName("staging-sso") - fmt.Println(session.Name) - fmt.Println(session.ClientToken.ExpiresAt) - fmt.Println(session.ClientToken.IsExpired()) - fmt.Println(time.Now().UTC()) -} diff --git a/pkg/ansi/ansi.go b/pkg/ansi/ansi.go index 297f937..9c85bd2 100644 --- a/pkg/ansi/ansi.go +++ b/pkg/ansi/ansi.go @@ -41,3 +41,7 @@ func AlternativeBuffer() { func NormalBuffer() { fmt.Fprint(Writer, "\033[?1049l") } + +func MoveCursorUp(n int) { + fmt.Fprintf(Writer, "\033[%dA", n) +} diff --git a/sdk/picker/picker.go b/sdk/picker/picker.go index bff0162..9a45ade 100644 --- a/sdk/picker/picker.go +++ b/sdk/picker/picker.go @@ -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() @@ -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 {