Due to VSCode limitations you can't detect the active panel tab. As a result if you click on a panel tab or close it, you may need an additional click to show the terminal again.