@@ -45,6 +45,20 @@ export const useExitHandler = ({
4545 setupExitMessageHandler ( )
4646 } , [ ] )
4747
48+ const exitNow = useCallback ( ( ) => {
49+ if ( exitWarningTimeoutRef . current ) {
50+ clearTimeout ( exitWarningTimeoutRef . current )
51+ exitWarningTimeoutRef . current = null
52+ }
53+
54+ try {
55+ process . stdout . write ( '\nGoodbye! Exiting...\n' )
56+ } catch {
57+ // Ignore stdout write errors during shutdown
58+ }
59+ process . exit ( 0 )
60+ } , [ ] )
61+
4862 const handleCtrlC = useCallback ( ( ) => {
4963 if ( inputValue ) {
5064 setInputValue ( { text : '' , cursorPosition : 0 , lastEditDueToNav : false } )
@@ -60,41 +74,22 @@ export const useExitHandler = ({
6074 return true
6175 }
6276
63- const exitNow = ( ) => {
64- try {
65- process . stdout . write ( '\nGoodbye! Exiting...\n' )
66- } catch {
67- // Ignore stdout write errors during shutdown
68- }
69- process . exit ( 0 )
70- }
71-
72- if ( exitWarningTimeoutRef . current ) {
73- clearTimeout ( exitWarningTimeoutRef . current )
74- exitWarningTimeoutRef . current = null
75- }
76-
7777 const flushed = flushAnalytics ( )
7878 if ( flushed && typeof ( flushed as Promise < void > ) . finally === 'function' ) {
7979 ; ( flushed as Promise < void > ) . finally ( exitNow )
8080 } else {
8181 exitNow ( )
8282 }
8383 return true
84- } , [ inputValue , setInputValue , nextCtrlCWillExit ] )
84+ } , [ exitNow , inputValue , setInputValue , nextCtrlCWillExit ] )
8585
8686 useEffect ( ( ) => {
8787 const handleSigint = ( ) => {
88- if ( exitWarningTimeoutRef . current ) {
89- clearTimeout ( exitWarningTimeoutRef . current )
90- exitWarningTimeoutRef . current = null
91- }
92-
9388 const flushed = flushAnalytics ( )
9489 if ( flushed && typeof ( flushed as Promise < void > ) . finally === 'function' ) {
95- ; ( flushed as Promise < void > ) . finally ( ( ) => process . exit ( 0 ) )
90+ ; ( flushed as Promise < void > ) . finally ( exitNow )
9691 } else {
97- process . exit ( 0 )
92+ exitNow ( )
9893 }
9994 }
10095
0 commit comments