on main help sign in
feat(tui): editor: change textarea placeholder based on CoderAgent state (#263)
334dafcAyman Bagabas
internal/tui/components/chat/editor/editor.go+44−10
@@ -2,6 +2,7 @@ package editor
2
2
3import (
3import (
4 "fmt"
4 "fmt"
5+ "math/rand"
5 "net/http"
6 "net/http"
6 "os"
7 "os"
7 "os/exec"
8 "os/exec"
@@ -48,14 +49,16 @@ type FileCompletionItem struct {
48}
49}
49
50
50type editorCmp struct {
51type editorCmp struct {
51− width int
52+ width int
52− height int
53+ height int
53− x, y int
54+ x, y int
54− app *app.App
55+ app *app.App
55− session session.Session
56+ session session.Session
56− textarea textarea.Model
57+ textarea textarea.Model
57− attachments []message.Attachment
58+ attachments []message.Attachment
58− deleteMode bool
59+ deleteMode bool
60+ readyPlaceholder string
61+ workingPlaceholder string
59
62
60 keyMap EditorKeyMap
63 keyMap EditorKeyMap
61
64
@@ -157,6 +160,10 @@ func (m *editorCmp) send() tea.Cmd {
157 if value == "" {
160 if value == "" {
158 return nil
161 return nil
159 }
162 }
163+
164+ // Change the placeholder when sending a new message.
165+ m.randomizePlaceholders()
166+
160 return tea.Batch(
167 return tea.Batch(
161 util.CmdHandler(chat.SendMsg{
168 util.CmdHandler(chat.SendMsg{
162 Text: value,
169 Text: value,
@@ -379,8 +386,31 @@ func (m *editorCmp) Cursor() *tea.Cursor {
379 return cursor
386 return cursor
380}
387}
381
388
389+var readyPlaceholders = [...]string{
390+ "Ready!",
391+ "Ready...",
392+ "Ready?",
393+}
394+
395+var workingPlaceholders = [...]string{
396+ "Working!",
397+ "Working...",
398+ "Working?",
399+}
400+
401+func (m *editorCmp) randomizePlaceholders() {
402+ m.workingPlaceholder = workingPlaceholders[rand.Intn(len(workingPlaceholders))]
403+ m.readyPlaceholder = readyPlaceholders[rand.Intn(len(readyPlaceholders))]
404+}
405+
382func (m *editorCmp) View() string {
406func (m *editorCmp) View() string {
383 t := styles.CurrentTheme()
407 t := styles.CurrentTheme()
408+ // Update placeholder
409+ if m.app.CoderAgent.IsBusy() {
410+ m.textarea.Placeholder = m.workingPlaceholder
411+ } else {
412+ m.textarea.Placeholder = m.readyPlaceholder
413+ }
384 if len(m.attachments) == 0 {
414 if len(m.attachments) == 0 {
385 content := t.S().Base.Padding(1).Render(
415 content := t.S().Base.Padding(1).Render(
386 m.textarea.View(),
416 m.textarea.View(),
@@ -510,14 +540,18 @@ func New(app *app.App) Editor {
510 })
540 })
511 ta.ShowLineNumbers = false
541 ta.ShowLineNumbers = false
512 ta.CharLimit = -1
542 ta.CharLimit = -1
513− ta.Placeholder = "Tell me more about this project..."
514 ta.SetVirtualCursor(false)
543 ta.SetVirtualCursor(false)
515 ta.Focus()
544 ta.Focus()
516
545
517− return &editorCmp{
546+ e := &editorCmp{
518 // TODO: remove the app instance from here
547 // TODO: remove the app instance from here
519 app: app,
548 app: app,
520 textarea: ta,
549 textarea: ta,
521 keyMap: DefaultEditorKeyMap(),
550 keyMap: DefaultEditorKeyMap(),
522 }
551 }
552+
553+ e.randomizePlaceholders()
554+ e.textarea.Placeholder = e.readyPlaceholder
555+
556+ return e
523}
557}
internal/tui/page/chat/chat.go+1
@@ -254,6 +254,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
254 p.chat = u.(chat.MessageListCmp)
254 p.chat = u.(chat.MessageListCmp)
255 cmds = append(cmds, cmd)
255 cmds = append(cmds, cmd)
256 }
256 }
257+
257 return p, tea.Batch(cmds...)
258 return p, tea.Batch(cmds...)
258
259
259 case pubsub.Event[history.File], sidebar.SessionFilesMsg:
260 case pubsub.Event[history.File], sidebar.SessionFilesMsg: