@@ -23,7 +23,7 @@ export const TerminalTabs = memo(() => {
2323 const terminalToggledByShortcut = useRef ( false ) ;
2424
2525 const [ activeTerminal , setActiveTerminal ] = useState ( 0 ) ;
26- const [ terminalCount , setTerminalCount ] = useState ( 1 ) ;
26+ const [ terminalCount , setTerminalCount ] = useState ( 0 ) ;
2727
2828 const addTerminal = ( ) => {
2929 if ( terminalCount < MAX_TERMINALS ) {
@@ -32,6 +32,48 @@ export const TerminalTabs = memo(() => {
3232 }
3333 } ;
3434
35+ const closeTerminal = ( index : number ) => {
36+ if ( index === 0 ) {
37+ return ;
38+ } // Can't close bolt terminal
39+
40+ const terminalRef = terminalRefs . current [ index ] ;
41+
42+ if ( terminalRef ?. getTerminal ) {
43+ const terminal = terminalRef . getTerminal ( ) ;
44+
45+ if ( terminal ) {
46+ workbenchStore . detachTerminal ( terminal ) ;
47+ }
48+ }
49+
50+ // Remove the terminal from refs
51+ terminalRefs . current . splice ( index , 1 ) ;
52+
53+ // Adjust terminal count and active terminal
54+ setTerminalCount ( terminalCount - 1 ) ;
55+
56+ if ( activeTerminal === index ) {
57+ setActiveTerminal ( Math . max ( 0 , index - 1 ) ) ;
58+ } else if ( activeTerminal > index ) {
59+ setActiveTerminal ( activeTerminal - 1 ) ;
60+ }
61+ } ;
62+
63+ useEffect ( ( ) => {
64+ return ( ) => {
65+ terminalRefs . current . forEach ( ( ref , index ) => {
66+ if ( index > 0 && ref ?. getTerminal ) {
67+ const terminal = ref . getTerminal ( ) ;
68+
69+ if ( terminal ) {
70+ workbenchStore . detachTerminal ( terminal ) ;
71+ }
72+ }
73+ } ) ;
74+ } ;
75+ } , [ ] ) ;
76+
3577 useEffect ( ( ) => {
3678 const { current : terminal } = terminalPanelRef ;
3779
@@ -125,6 +167,15 @@ export const TerminalTabs = memo(() => {
125167 >
126168 < div className = "i-ph:terminal-window-duotone text-lg" />
127169 Terminal { terminalCount > 1 && index }
170+ < button
171+ className = "bg-transparent text-bolt-elements-textTertiary hover:text-bolt-elements-textPrimary hover:bg-transparent rounded"
172+ onClick = { ( e ) => {
173+ e . stopPropagation ( ) ;
174+ closeTerminal ( index ) ;
175+ } }
176+ >
177+ < div className = "i-ph:x text-xs" />
178+ </ button >
128179 </ button >
129180 </ React . Fragment >
130181 ) }
0 commit comments