Skip to content

Commit 421ee7a

Browse files
committed
Use real terminal cursor in prompts
Instead of faking our own. Fixes: #465
1 parent 8b665b7 commit 421ee7a

3 files changed

Lines changed: 9 additions & 16 deletions

File tree

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/rivo/uniseg v0.4.7
2121
github.com/sirupsen/logrus v1.9.4
2222
github.com/ulikunitz/xz v0.5.16
23-
github.com/walles/twin v0.9.3
23+
github.com/walles/twin v0.9.4
2424
golang.org/x/term v0.45.0
2525
gotest.tools/v3 v3.5.2
2626
)

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
4141
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4242
github.com/ulikunitz/xz v0.5.16 h1:ld6NyySjx5lowVKwJvMRLnW5nxKX/xnpSiFYZ/Lxur0=
4343
github.com/ulikunitz/xz v0.5.16/go.mod h1:H9Rt/W6/Qj27PGauhQc6nfCDy7vHpzsOThBSaYDoEhw=
44-
github.com/walles/twin v0.9.3 h1:nCH0PEfJ+mm+hf40RsPF/bWIyR+1rXk6AyzypGZUKXY=
45-
github.com/walles/twin v0.9.3/go.mod h1:3iGyRE6bnLVsQuIPMyW2i1YXe6e9VDjGHcAGOHi/mcA=
44+
github.com/walles/twin v0.9.4 h1:v9GCxlCDJ0exTRZRGkq7ok2tgaHNwGoEthiQ0e4sj/g=
45+
github.com/walles/twin v0.9.4/go.mod h1:3iGyRE6bnLVsQuIPMyW2i1YXe6e9VDjGHcAGOHi/mcA=
4646
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
4747
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
4848
golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0=

‎internal/inputbox.go‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type InputBox struct {
3131
onTextChanged InputBoxOnTextChanged
3232
}
3333

34-
// draw renders the input box at the bottom line of the screen, showing a
35-
// simple prompt and the current text with a reverse attribute cursor.
34+
// draw renders the input box at the bottom line of the screen, showing a simple
35+
// prompt and the current text, with the cursor placed at the insertion point.
3636
func (b *InputBox) draw(screen twin.Screen, keys_help string, prompt string) {
3737
width, height := screen.Size()
3838
pos := 0
@@ -59,18 +59,11 @@ func (b *InputBox) draw(screen twin.Screen, keys_help string, prompt string) {
5959
pos += screen.SetCell(pos, height-1, twin.StyledRune{Rune: ch, Style: twin.StyleDefault})
6060
}
6161

62-
// If cursor is on a rune, invert that rune. If cursor is at the end,
63-
// show an inverted blank cell.
64-
if b.cursorPos < len(textRunes) {
65-
pos += screen.SetCell(pos, height-1, twin.StyledRune{Rune: textRunes[b.cursorPos], Style: twin.StyleDefault.WithAttr(twin.AttrReverse)})
62+
screen.ShowCursor(pos, height-1)
6663

67-
// Draw right side after the cursor rune
68-
for i := b.cursorPos + 1; i < len(textRunes); i++ {
69-
pos += screen.SetCell(pos, height-1, twin.StyledRune{Rune: textRunes[i], Style: twin.StyleDefault})
70-
}
71-
} else {
72-
// Cursor at end -> reverse blank
73-
pos += screen.SetCell(pos, height-1, twin.StyledRune{Rune: ' ', Style: twin.StyleDefault.WithAttr(twin.AttrReverse)})
64+
// Draw right side (cursor position and after)
65+
for i := b.cursorPos; i < len(textRunes); i++ {
66+
pos += screen.SetCell(pos, height-1, twin.StyledRune{Rune: textRunes[i], Style: twin.StyleDefault})
7467
}
7568

7669
afterTextPos := pos

0 commit comments

Comments
 (0)