@@ -4,15 +4,17 @@ import (
4
4
"fmt"
5
5
6
6
tea "github.com/charmbracelet/bubbletea"
7
+ "github.com/initia-labs/weave/styles"
7
8
)
8
9
9
10
type TextInput struct {
10
- Text string
11
- Cursor int // Cursor position within the text
11
+ Text string
12
+ Cursor int // Cursor position within the text
13
+ Placeholder string
12
14
}
13
15
14
16
func NewTextInput () TextInput {
15
- return TextInput {Text : "" , Cursor : 0 }
17
+ return TextInput {Text : "" , Cursor : 0 , Placeholder : "<todo: Jennie revisit placeholder>" }
16
18
}
17
19
18
20
func (ti TextInput ) Update (msg tea.Msg ) (TextInput , tea.Cmd , bool ) {
@@ -46,20 +48,19 @@ func (ti TextInput) Update(msg tea.Msg) (TextInput, tea.Cmd, bool) {
46
48
47
49
func (ti TextInput ) View () string {
48
50
var beforeCursor , cursorChar , afterCursor string
49
-
50
- if ti .Cursor < len (ti .Text ) {
51
+ if len (ti .Text ) == 0 {
52
+ return styles .Text (ti .Placeholder , styles .Gray ) + styles .Cursor (" " ) + "\n \n Press Enter to submit, or Ctrl+c to quit."
53
+ } else if ti .Cursor < len (ti .Text ) {
51
54
// Cursor is within the text
52
- beforeCursor = ti .Text [:ti .Cursor ]
53
- cursorChar = ti .Text [ti .Cursor : ti .Cursor + 1 ] // Character at the cursor
54
- afterCursor = ti .Text [ti .Cursor + 1 :] // Text after the cursor
55
+ beforeCursor = styles . Text ( ti .Text [:ti .Cursor ], styles . White )
56
+ cursorChar = styles . Cursor ( ti .Text [ti .Cursor : ti .Cursor + 1 ])
57
+ afterCursor = styles . Text ( ti .Text [ti .Cursor + 1 :], styles . White )
55
58
} else {
56
59
// Cursor is at the end of the text
57
- beforeCursor = ti .Text
58
- cursorChar = " " // Use a space to represent the cursor at the end
59
- afterCursor = "" // No text after the cursor
60
+ beforeCursor = styles .Text (ti .Text , styles .White )
61
+ cursorChar = styles .Cursor (" " )
60
62
}
61
63
62
- // Render the text with the cursor
63
- // Use reverse video for the cursor character to highlight it
64
- return fmt .Sprintf ("%s\x1b [7m%s\x1b [0m%s\n \n Press Enter to submit, or Ctrl+c to quit." , beforeCursor , cursorChar , afterCursor )
64
+ // Compose the full view string
65
+ return fmt .Sprintf ("%s%s%s\n \n Press Enter to submit, or Ctrl+c to quit." , beforeCursor , cursorChar , afterCursor )
65
66
}
0 commit comments