mirror of
https://github.com/patriceckhart/zot.git
synced 2026-06-26 13:26:33 +02:00
Fix login dialog cursor alignment
This commit is contained in:
parent
917da8c414
commit
ea58887bfa
2 changed files with 30 additions and 1 deletions
|
|
@ -490,7 +490,11 @@ func (d *loginDialog) CursorPos(width int) (row, col int) {
|
|||
wrapW = 20
|
||||
}
|
||||
urlLines := len(tui.WrapANSILine(d.url, wrapW))
|
||||
baseOffset := 1 /*frameHeader*/ + 1 /*hint*/ + urlLines + 1 /*blank*/ + 1 /*prompt*/
|
||||
// interactive.redraw wraps dialog output with padDialogFrame, which
|
||||
// injects a blank row after the frame header. Count that row here so
|
||||
// the real terminal cursor lands on the editor input instead of the
|
||||
// prompt above it.
|
||||
baseOffset := 1 /*frameHeader*/ + 1 /*padDialogFrame blank*/ + 1 /*hint*/ + urlLines + 1 /*blank*/ + 1 /*prompt*/
|
||||
return baseOffset + eRow, eCol
|
||||
}
|
||||
|
||||
|
|
|
|||
25
packages/agent/modes/login_dialog_test.go
Normal file
25
packages/agent/modes/login_dialog_test.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package modes
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/patriceckhart/zot/packages/tui"
|
||||
)
|
||||
|
||||
func TestLoginDialogCursorPosMatchesPaddedInputRow(t *testing.T) {
|
||||
d := newLoginDialog()
|
||||
d.Open(t.TempDir())
|
||||
d.method = "oauth"
|
||||
d.provider = "anthropic"
|
||||
d.ShowWaiting("https://example.com/oauth/authorize?code_challenge=abc&state=xyz")
|
||||
|
||||
lines := padDialogFrame(d.Render(tui.Theme{}, 80))
|
||||
row, _ := d.CursorPos(80)
|
||||
if row < 0 || row >= len(lines) {
|
||||
t.Fatalf("CursorPos row = %d outside rendered lines %d", row, len(lines))
|
||||
}
|
||||
if got := stripANSIBytes(lines[row]); !strings.Contains(got, "▌") {
|
||||
t.Fatalf("CursorPos row %d = %q; want editor input row", row, got)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue