1- import { PasswordInput } from '@inkjs/ui' ;
21import { Box , Text , useInput } from 'ink' ;
32import { useAtom } from 'jotai' ;
43import { EventEmitter } from 'node:events' ;
@@ -29,43 +28,16 @@ export function ProgressDisplay(props: { emitter: EventEmitter }) {
2928 const { emitter } = props ;
3029 const [ progress ] = useAtom ( store . progressState ) ;
3130 const [ isVerbose , setIsVerbose ] = useState ( false ) ;
32- const [ isEnteringPassword , setIsEnteringPassword ] = useState ( false ) ;
33- const [ passwordError , setPasswordError ] = useState ( false ) ;
34- const [ passwordAttempts , setPasswordAttempts ] = useState ( 0 ) ;
3531 const [ passwordSaved , setPasswordSaved ] = useState ( false ) ;
36- const [ passwordInputKey , setPasswordInputKey ] = useState ( 0 ) ;
3732
3833 const isApplyOrDestroy = progress ?. name === ProcessName . APPLY || progress ?. name === ProcessName . DESTROY ;
3934
4035 useLayoutEffect ( ( ) => {
41- const onResult = ( { success } : { success : boolean } ) => {
42- if ( success ) {
43- setPasswordSaved ( true ) ;
44- setIsEnteringPassword ( false ) ;
45- setPasswordError ( false ) ;
46- setPasswordAttempts ( 0 ) ;
47- } else {
48- setPasswordAttempts ( ( prev ) => {
49- const next = prev + 1 ;
50- if ( next >= 3 ) {
51- setIsEnteringPassword ( false ) ;
52- setPasswordError ( false ) ;
53- return 0 ;
54- }
55- setPasswordError ( true ) ;
56- setPasswordInputKey ( ( k ) => k + 1 ) ;
57- return next ;
58- } ) ;
59- }
60- } ;
61-
6236 const onPreSupplied = ( ) => setPasswordSaved ( true ) ;
6337
64- emitter . on ( RenderEvent . SUDO_PASSWORD_RESULT , onResult ) ;
6538 emitter . on ( RenderEvent . SUDO_PASSWORD_PRE_SUPPLIED , onPreSupplied ) ;
6639
6740 return ( ) => {
68- emitter . off ( RenderEvent . SUDO_PASSWORD_RESULT , onResult ) ;
6941 emitter . off ( RenderEvent . SUDO_PASSWORD_PRE_SUPPLIED , onPreSupplied ) ;
7042 } ;
7143 } , [ ] ) ;
@@ -77,10 +49,7 @@ export function ProgressDisplay(props: { emitter: EventEmitter }) {
7749 emitter . emit ( RenderEvent . TOGGLE_VERBOSITY ) ;
7850 }
7951 if ( input === 'p' && ! passwordSaved ) {
80- setIsEnteringPassword ( ( prev ) => ! prev ) ;
81- setPasswordError ( false ) ;
82- setPasswordAttempts ( 0 ) ;
83- setPasswordInputKey ( ( k ) => k + 1 ) ;
52+ emitter . emit ( RenderEvent . SUDO_PASSWORD_TOGGLE ) ;
8453 }
8554 } ) ;
8655
@@ -96,33 +65,15 @@ export function ProgressDisplay(props: { emitter: EventEmitter }) {
9665 ? < Spinner label = { label } type = "dots" />
9766 : < Text > < Text color = 'greenBright' > ✔</ Text > { label } </ Text >
9867 }
99-
100- { ! isEnteringPassword && (
101- < Box flexDirection = "column" marginLeft = { 2 } >
102- < SubProgressDisplay subProgresses = { subProgresses } />
103- </ Box >
104- ) }
105-
106- { isEnteringPassword && (
107- < Box flexDirection = "column" marginTop = { 1 } >
108- < Text color = { passwordError ? 'red' : 'cyan' } > { '─' . repeat ( 40 ) } </ Text >
109- < Box >
110- < Text > Password: </ Text >
111- < PasswordInput key = { passwordInputKey } onSubmit = { ( pw ) => emitter . emit ( RenderEvent . SUDO_PASSWORD_SUBMITTED , pw ) } />
112- </ Box >
113- { passwordError && (
114- < Text color = "red" > { ` Incorrect password, try again (${ passwordAttempts } /3)` } </ Text >
115- ) }
116- < Text color = { passwordError ? 'red' : 'cyan' } > { '─' . repeat ( 40 ) } </ Text >
117- </ Box >
118- ) }
119-
68+ < Box flexDirection = "column" marginLeft = { 2 } >
69+ < SubProgressDisplay subProgresses = { subProgresses } />
70+ </ Box >
12071 { isApplyOrDestroy && (
121- < Box flexDirection = "column" >
72+ < Box flexDirection = "row" gap = { 2 } >
12273 < Text dimColor > { isVerbose ? '[v] Hide verbose logs' : '[v] Show verbose logs' } </ Text >
12374 { passwordSaved
12475 ? < Text color = "green" > ✓ sudo password</ Text >
125- : < Text dimColor > { isEnteringPassword ? ' [p] Cancel' : '[p] Enter sudo password' } </ Text >
76+ : < Text dimColor > [p] Enter sudo password</ Text >
12677 }
12778 </ Box >
12879 ) }
0 commit comments