@@ -2,20 +2,26 @@ import { createMemo, createSignal } from "solid-js"
22import { useLocal } from "@tui/context/local"
33import { DialogSelect } from "@tui/ui/dialog-select"
44import { useDialog } from "@tui/ui/dialog"
5+ import { useTerminalDimensions } from "@opentui/solid"
56import { Keybind } from "@/util/keybind"
7+ import { Locale } from "@/util/locale"
68import { DialogAgentDetails } from "./dialog-agent-details"
79
8- export function DialogAgent ( props : { initialAgent ?: string } ) {
10+ export function DialogAgent ( props : { focusedAgent ?: string } ) {
911 const local = useLocal ( )
1012 const dialog = useDialog ( )
13+ const dimensions = useTerminalDimensions ( )
1114
12- const [ selectedAgentName , setSelectedAgentName ] = createSignal ( props . initialAgent ?? local . agent . current ( ) . name )
15+ const [ selectedAgentName , setSelectedAgentName ] = createSignal ( props . focusedAgent ?? local . agent . current ( ) . name )
1316
14- const selectedAgentHasPrompt = createMemo ( ( ) => {
17+ const selectedAgentHasDescription = createMemo ( ( ) => {
1518 const agent = local . agent . list ( ) . find ( ( a ) => a . name === selectedAgentName ( ) )
1619 return agent && ! agent . builtIn && ! ! agent . description
1720 } )
1821
22+ // Dialog width is min(60, terminalWidth - 2), minus ~10 for padding
23+ const availableWidth = createMemo ( ( ) => Math . min ( 60 , dimensions ( ) . width - 2 ) - 10 )
24+
1925 const options = createMemo ( ( ) =>
2026 local . agent . list ( ) . map ( ( item ) => {
2127 let description : string | undefined
@@ -28,12 +34,18 @@ export function DialogAgent(props: { initialAgent?: string }) {
2834 description = item . description
2935 }
3036
31- description = description ? description . length > 35 ? description . slice ( 0 , 32 ) + "..." : description : undefined
37+ // Truncate description based on available space after title
38+ const maxDescLen = availableWidth ( ) - item . name . length - 1
39+ if ( description && maxDescLen > 3 ) {
40+ description = Locale . truncate ( description , maxDescLen )
41+ } else if ( description && maxDescLen <= 3 ) {
42+ description = undefined
43+ }
3244
3345 return {
3446 value : item . name ,
3547 title : item . name ,
36- description
48+ description,
3749 }
3850 } ) ,
3951 )
@@ -42,7 +54,7 @@ export function DialogAgent(props: { initialAgent?: string }) {
4254 < DialogSelect
4355 title = "Select agent"
4456 current = { local . agent . current ( ) . name }
45- defaultSelected = { props . initialAgent }
57+ defaultSelected = { props . focusedAgent }
4658 options = { options ( ) }
4759 onMove = { ( option ) => setSelectedAgentName ( option . value ) }
4860 onSelect = { ( option ) => {
@@ -54,7 +66,7 @@ export function DialogAgent(props: { initialAgent?: string }) {
5466 keybind : Keybind . parse ( "ctrl+e" ) [ 0 ] ,
5567 title : "show details" ,
5668 get disabled ( ) {
57- return ! selectedAgentHasPrompt ( )
69+ return ! selectedAgentHasDescription ( )
5870 } ,
5971 onTrigger : ( option ) => {
6072 dialog . replace ( ( ) => < DialogAgentDetails agentName = { option . value } /> )
0 commit comments