diff --git a/go.mod b/go.mod index 36260cd..3317dd2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.0 require ( github.com/atotto/clipboard v0.1.4 - github.com/charmbracelet/bubbletea v1.2.3 + github.com/charmbracelet/bubbletea v1.2.4 github.com/spf13/cobra v1.8.1 github.com/tobischo/gokeepasslib/v3 v3.6.0 golang.org/x/term v0.26.0 diff --git a/go.sum b/go.sum index d974bee..a277379 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= -github.com/charmbracelet/bubbletea v1.2.3 h1:d9MdMsANIYZB5pE1KkRqaUV6GfsiWm+/9z4fTuGVm9I= -github.com/charmbracelet/bubbletea v1.2.3/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM= +github.com/charmbracelet/bubbletea v1.2.4 h1:KN8aCViA0eps9SCOThb2/XPIlea3ANJLUkv3KnQRNCE= +github.com/charmbracelet/bubbletea v1.2.4/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM= github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo= github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM= diff --git a/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go b/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go index aa8524b..369f27f 100644 --- a/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go +++ b/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go @@ -36,6 +36,7 @@ type standardRenderer struct { lastRender string lastRenderedLines []string linesRendered int + altLinesRendered int useANSICompressor bool once sync.Once @@ -57,9 +58,6 @@ type standardRenderer struct { // lines explicitly set not to render ignoreLines map[int]struct{} - - // lines rendered before entering alt screen mode - linesRenderedBeforeAltScreen int } // newRenderer creates a new renderer. Normally you'll want to initialize it @@ -173,7 +171,9 @@ func (r *standardRenderer) flush() { buf := &bytes.Buffer{} // Moving to the beginning of the section, that we rendered. - if r.linesRendered > 1 { + if r.altScreenActive { + buf.WriteString(ansi.HomeCursorPosition) + } else if r.linesRendered > 1 { buf.WriteString(ansi.CursorUp(r.linesRendered - 1)) } @@ -258,12 +258,21 @@ func (r *standardRenderer) flush() { } } + lastLinesRendered := r.linesRendered + if r.altScreenActive { + lastLinesRendered = r.altLinesRendered + } + // Clearing left over content from last render. - if r.linesRendered > len(newLines) { + if lastLinesRendered > len(newLines) { buf.WriteString(ansi.EraseScreenBelow) } - r.linesRendered = len(newLines) + if r.altScreenActive { + r.altLinesRendered = len(newLines) + } else { + r.linesRendered = len(newLines) + } // Make sure the cursor is at the start of the last line to keep rendering // behavior consistent. @@ -271,7 +280,7 @@ func (r *standardRenderer) flush() { // This case fixes a bug in macOS terminal. In other terminals the // other case seems to do the job regardless of whether or not we're // using the full terminal window. - buf.WriteString(ansi.SetCursorPosition(0, r.linesRendered)) + buf.WriteString(ansi.SetCursorPosition(0, len(newLines))) } else { buf.WriteString(ansi.CursorLeft(r.width)) } @@ -337,10 +346,6 @@ func (r *standardRenderer) enterAltScreen() { r.altScreenActive = true r.execute(ansi.EnableAltScreenBuffer) - // Save the current line count before entering the alternate screen mode. - // This allows us to compare and adjust the cursor position when exiting the alternate screen. - r.linesRenderedBeforeAltScreen = r.linesRendered - // Ensure that the terminal is cleared, even when it doesn't support // alt screen (or alt screen support is disabled, like GNU screen by // default). @@ -359,6 +364,9 @@ func (r *standardRenderer) enterAltScreen() { r.execute(ansi.ShowCursor) } + // Entering the alt screen resets the lines rendered count. + r.altLinesRendered = 0 + r.repaint() } @@ -373,18 +381,6 @@ func (r *standardRenderer) exitAltScreen() { r.altScreenActive = false r.execute(ansi.DisableAltScreenBuffer) - // Adjust cursor and screen - if r.linesRendered < r.linesRenderedBeforeAltScreen { - // If fewer lines were rendered in the alternate screen, move the cursor up - // to align with the previous normal screen position and clear any remaining lines. - r.execute(ansi.CursorUp(r.linesRenderedBeforeAltScreen - r.linesRendered)) - r.execute(ansi.EraseScreenBelow) - } else if r.linesRendered > r.linesRenderedBeforeAltScreen && r.linesRenderedBeforeAltScreen > 0 { - // If more lines were rendered in the alternate screen, move the cursor down - // to align with the new position. - r.execute(ansi.CursorDown(r.linesRendered - r.linesRenderedBeforeAltScreen)) - } - // cmd.exe and other terminals keep separate cursor states for the AltScreen // and the main buffer. We have to explicitly reset the cursor visibility // whenever we exit AltScreen. diff --git a/vendor/modules.txt b/vendor/modules.txt index eb80165..525dbed 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,7 +4,7 @@ github.com/atotto/clipboard # github.com/aymanbagabas/go-osc52/v2 v2.0.1 ## explicit; go 1.16 github.com/aymanbagabas/go-osc52/v2 -# github.com/charmbracelet/bubbletea v1.2.3 +# github.com/charmbracelet/bubbletea v1.2.4 ## explicit; go 1.18 github.com/charmbracelet/bubbletea # github.com/charmbracelet/lipgloss v1.0.0