@@ -20,14 +20,17 @@ import (
2020)
2121
2222func tui (ctx context.Context , agent * agent.Agent , conv * conversation.Conversation ) error {
23+ ctx , cancel := context .WithCancel (ctx )
24+ defer cancel ()
25+
2326 app := tview .NewApplication ()
2427
2528 conversationView := tview .NewTextView ().
2629 SetDynamicColors (true ).
2730 SetWordWrap (true ).
2831 SetChangedFunc (func () {
2932 app .Draw ()
30- })
33+ }). ScrollToEnd ()
3134
3235 isFirstInput := len (conv .Messages ) == 0
3336 if isFirstInput {
@@ -36,14 +39,19 @@ func tui(ctx context.Context, agent *agent.Agent, conv *conversation.Conversatio
3639 } else {
3740 displayConversationHistory (conversationView , conv )
3841 }
39-
4042 relPath := displayRelativePath ()
4143
4244 questionInput := tview .NewTextArea ()
4345 questionInput .SetTitle ("[blue::]Enter to send (ESC to focus conversation)" ).
4446 SetTitleAlign (tview .AlignLeft ).
4547 SetBorder (true ).
4648 SetDrawFunc (renderRelativePath (relPath ))
49+ questionInput .SetFocusFunc (func () {
50+ questionInput .SetBorderColor (tcell .ColorGreen )
51+ })
52+ questionInput .SetBlurFunc (func () {
53+ questionInput .SetBorderColor (tcell .ColorWhite )
54+ })
4755
4856 spinnerView := tview .NewTextView ().
4957 SetDynamicColors (true ).
@@ -94,6 +102,8 @@ func tui(ctx context.Context, agent *agent.Agent, conv *conversation.Conversatio
94102 defer ticker .Stop ()
95103 for {
96104 select {
105+ case <- ctx .Done ():
106+ return
97107 case stop := <- spinCh :
98108 if stop {
99109 // Clear the spinner text to hide it from the UI when the agent finishes processing
@@ -151,7 +161,11 @@ func tui(ctx context.Context, agent *agent.Agent, conv *conversation.Conversatio
151161 return event
152162 })
153163
154- return app .SetRoot (mainLayout , true ).SetFocus (questionInput ).Run ()
164+ if err := app .SetRoot (mainLayout , true ).EnableMouse (true ).SetFocus (questionInput ).Run (); err != nil {
165+ panic (err )
166+ }
167+
168+ return nil
155169}
156170
157171func formatMessage (msg * message.Message ) string {
0 commit comments