1- import { TextAttributes } from '@opentui/core'
1+ import { TextAttributes , type BorderCharacters } from '@opentui/core'
22import React , { type ReactNode } from 'react'
33
4+ const borderCharsWithoutVertical : BorderCharacters = {
5+ topLeft : '┌' ,
6+ topRight : '┐' ,
7+ bottomLeft : '└' ,
8+ bottomRight : '┘' ,
9+ horizontal : '─' ,
10+ vertical : ' ' ,
11+ topT : ' ' ,
12+ bottomT : ' ' ,
13+ leftT : ' ' ,
14+ rightT : ' ' ,
15+ cross : ' ' ,
16+ }
17+
418import type { ChatTheme } from '../utils/theme-system'
519
620interface BranchItemProps {
@@ -26,9 +40,19 @@ export const BranchItem = ({
2640 theme,
2741 onToggle,
2842} : BranchItemProps ) => {
29- const indentPrefix = branchChar ? branchChar . replace ( / ./ g, ' ' ) : ''
3043 const cornerColor = theme . agentPrefix
3144
45+ const toggleBackground = isStreaming
46+ ? theme . agentToggleHeaderBg
47+ : isCollapsed
48+ ? theme . agentResponseCount
49+ : theme . agentPrefix
50+ const toggleTextColor =
51+ ( isStreaming ? theme . agentToggleHeaderText : theme . agentToggleText ) ??
52+ theme . agentToggleText
53+ const statusSymbol = isStreaming ? '●' : ' '
54+ const toggleLabel = `${ isCollapsed ? '▸' : '▾' } ${ statusSymbol } `
55+
3256 const isTextRenderable = ( value : ReactNode ) : boolean => {
3357 if (
3458 value === null ||
@@ -116,34 +140,32 @@ export const BranchItem = ({
116140 }
117141
118142 return (
119- < box style = { { flexDirection : 'row' , flexShrink : 0 } } >
120- < text wrap = { false } > { indentPrefix } </ text >
121- < box
122- style = { {
123- flexDirection : 'column' ,
124- gap : 0 ,
125- flexShrink : 1 ,
126- flexGrow : 1 ,
127- } }
128- >
143+ < box
144+ style = { {
145+ flexDirection : 'column' ,
146+ gap : 0 ,
147+ flexShrink : 0 ,
148+ marginTop : 1 ,
149+ marginBottom : 1 ,
150+ } }
151+ >
152+ < box style = { { flexDirection : 'column' , gap : 0 } } >
129153 < box
130154 style = { {
131155 flexDirection : 'row' ,
132156 alignSelf : 'flex-start' ,
133- backgroundColor : isCollapsed
134- ? theme . agentResponseCount
135- : theme . agentPrefix ,
157+ backgroundColor : toggleBackground ,
136158 paddingLeft : 1 ,
137159 paddingRight : 1 ,
138160 } }
139161 onMouseDown = { onToggle }
140162 >
141163 < text wrap >
142- < span fg = { theme . agentToggleText } >
143- { isCollapsed ? '▸ ' : '▾ ' }
164+ < span fg = { toggleTextColor } >
165+ { toggleLabel }
144166 </ span >
145167 < span
146- fg = { theme . agentToggleText }
168+ fg = { toggleTextColor }
147169 attributes = { TextAttributes . BOLD }
148170 >
149171 { name }
@@ -172,57 +194,21 @@ export const BranchItem = ({
172194 </ text >
173195 ) }
174196 { ! isCollapsed && content && (
175- < box style = { { flexDirection : 'column' , gap : 0 } } >
176- < box
177- style = { {
178- flexDirection : 'row' ,
179- justifyContent : 'space-between' ,
180- } }
181- >
182- < text wrap = { false } fg = { cornerColor } >
183- ┌
184- </ text >
185- < text wrap = { false } fg = { cornerColor } >
186- ┐
187- </ text >
188- </ box >
189- < box
190- style = { {
191- flexDirection : 'row' ,
192- alignItems : 'stretch' ,
193- } }
194- >
195- < text wrap = { false } fg = { cornerColor } >
196- │
197- </ text >
198- < box
199- style = { {
200- flexDirection : 'column' ,
201- gap : 0 ,
202- flexGrow : 1 ,
203- marginLeft : 1 ,
204- marginRight : 1 ,
205- } }
206- >
207- { renderExpandedContent ( content ) }
208- </ box >
209- < text wrap = { false } fg = { cornerColor } >
210- │
211- </ text >
212- </ box >
213- < box
214- style = { {
215- flexDirection : 'row' ,
216- justifyContent : 'space-between' ,
217- } }
218- >
219- < text wrap = { false } fg = { cornerColor } >
220- └
221- </ text >
222- < text wrap = { false } fg = { cornerColor } >
223- ┘
224- </ text >
225- </ box >
197+ < box
198+ border
199+ borderStyle = "single"
200+ borderColor = { cornerColor }
201+ customBorderChars = { borderCharsWithoutVertical }
202+ style = { {
203+ flexDirection : 'column' ,
204+ gap : 0 ,
205+ paddingLeft : 1 ,
206+ paddingRight : 1 ,
207+ paddingTop : 0 ,
208+ paddingBottom : 0 ,
209+ } }
210+ >
211+ { renderExpandedContent ( content ) }
226212 </ box >
227213 ) }
228214 </ box >
0 commit comments