@@ -3,11 +3,17 @@ import {
33 Text ,
44 useInput
55} from 'ink' ;
6- import React , { useState } from 'react' ;
6+ import pluralize from 'pluralize' ;
7+ import React , {
8+ useMemo ,
9+ useState
10+ } from 'react' ;
711
812import type { Settings } from '../../types/Settings' ;
913import type { WidgetItem } from '../../types/Widget' ;
1014
15+ import { ConfirmDialog } from './ConfirmDialog' ;
16+
1117interface LineSelectorProps {
1218 lines : WidgetItem [ ] [ ] ;
1319 onAppend : ( ) => void ;
@@ -32,6 +38,12 @@ const LineSelector: React.FC<LineSelectorProps> = ({
3238 settings
3339} ) => {
3440 const [ selectedIndex , setSelectedIndex ] = useState ( initialSelection ) ;
41+ const [ showDeleteDialog , setShowDeleteDialog ] = useState ( false ) ;
42+
43+ const selectedLine = useMemo (
44+ ( ) => lines [ selectedIndex ] ,
45+ [ lines , selectedIndex ]
46+ ) ;
3547
3648 // Check if powerline theme is managing colors
3749 const powerlineEnabled = settings ? settings . powerline . enabled : false ;
@@ -44,7 +56,11 @@ const LineSelector: React.FC<LineSelectorProps> = ({
4456
4557 // Handle keyboard input
4658 useInput ( ( input , key ) => {
47- // If theme-managed and blocking is enabled, any key goes back
59+ if ( showDeleteDialog ) {
60+ return ;
61+ }
62+
63+ // If theme-managed and blocking is enabled, any key goes back
4864 if ( isThemeManaged ) {
4965 onBack ( ) ;
5066 return ;
@@ -56,8 +72,7 @@ const LineSelector: React.FC<LineSelectorProps> = ({
5672 setSelectedIndex ( lines . length ) ;
5773 return ;
5874 case 'd' :
59- onDelete ( selectedIndex ) ;
60- setSelectedIndex ( Math . max ( 0 , selectedIndex - 1 ) ) ;
75+ setShowDeleteDialog ( true ) ;
6176 return ;
6277 }
6378
@@ -109,35 +124,95 @@ const LineSelector: React.FC<LineSelectorProps> = ({
109124 ) ;
110125 }
111126
112- return (
113- < Box flexDirection = 'column' >
114- < Text bold > { title ?? 'Select Line to Edit' } </ Text >
115- < Text dimColor >
116- Choose which status line to configure (up to 3 lines supported)
117- </ Text >
118- < Text dimColor >
119- (i) to append new line, (d) to delete line, ESC to go back
120- </ Text >
121- < Box marginTop = { 1 } flexDirection = 'column' >
122- { lines . map ( ( line , index ) => (
123- < Box key = { index } >
124- < Text color = { selectedIndex === index ? 'green' : undefined } >
125- { selectedIndex === index ? '▶ ' : ' ' }
126- ☰ Line
127- { index + 1 }
128- { line . length > 0 ? ` (${ line . length } widgets)` : ' (empty)' }
127+ if ( showDeleteDialog && selectedLine ) {
128+ const suffix
129+ = selectedLine . length > 0
130+ ? pluralize ( 'widget' , selectedLine . length , true )
131+ : 'empty' ;
132+
133+ return (
134+ < Box flexDirection = 'column' >
135+ < Box flexDirection = 'column' gap = { 1 } >
136+ < Text bold >
137+ < Text >
138+ < Text >
139+ ☰ Line
140+ { selectedIndex + 1 }
141+ </ Text >
142+ < Text dimColor >
143+ (
144+ { suffix }
145+ )
146+ </ Text >
129147 </ Text >
130- </ Box >
131- ) ) }
148+ </ Text >
149+ < Text bold > Are you sure you want to delete line?</ Text >
150+ </ Box >
132151
133152 < Box marginTop = { 1 } >
134- < Text color = { selectedIndex === lines . length ? 'green' : undefined } >
135- { selectedIndex === lines . length ? '▶ ' : ' ' }
136- ← Back
137- </ Text >
153+ < ConfirmDialog
154+ inline = { true }
155+ onConfirm = { ( ) => {
156+ onDelete ( selectedIndex ) ;
157+ setSelectedIndex ( Math . max ( 0 , selectedIndex - 1 ) ) ;
158+ setShowDeleteDialog ( false ) ;
159+ } }
160+ onCancel = { ( ) => {
161+ setShowDeleteDialog ( false ) ;
162+ } }
163+ />
164+ </ Box >
165+ </ Box >
166+ ) ;
167+ }
168+
169+ return (
170+ < >
171+ < Box flexDirection = 'column' >
172+ < Text bold > { title ?? 'Select Line to Edit' } </ Text >
173+ < Text dimColor >
174+ Choose which status line to configure (up to 3 lines supported)
175+ </ Text >
176+ < Text dimColor >
177+ (i) to append new line, (d) to delete line, ESC to go back
178+ </ Text >
179+
180+ < Box marginTop = { 1 } flexDirection = 'column' >
181+ { lines . map ( ( line , index ) => {
182+ const isSelected = selectedIndex === index ;
183+ const suffix = line . length
184+ ? pluralize ( 'widget' , line . length , true )
185+ : 'empty' ;
186+
187+ return (
188+ < Box key = { index } >
189+ < Text color = { isSelected ? 'green' : undefined } >
190+ < Text > { isSelected ? '▶ ' : ' ' } </ Text >
191+ < Text >
192+ < Text >
193+ ☰ Line
194+ { index + 1 }
195+ </ Text >
196+ < Text dimColor = { ! isSelected } >
197+ (
198+ { suffix }
199+ )
200+ </ Text >
201+ </ Text >
202+ </ Text >
203+ </ Box >
204+ ) ;
205+ } ) }
206+
207+ < Box marginTop = { 1 } >
208+ < Text color = { selectedIndex === lines . length ? 'green' : undefined } >
209+ { selectedIndex === lines . length ? '▶ ' : ' ' }
210+ ← Back
211+ </ Text >
212+ </ Box >
138213 </ Box >
139214 </ Box >
140- </ Box >
215+ </ >
141216 ) ;
142217} ;
143218
0 commit comments