🐞 Terminal State is not saved when switching tabs
Description
When you switch tabs on status bar, and then go back to the terminal, it will be refreshed.
To Reproduce
- Expand the status bar to see the terminal.
- Enter a command in the terminal
- Select a different tab in the status bar
- Select the terminal tab
Expected behavior
The terminal should keep its state and should not be a fresh screen when you select the tab again.
Version information
CodeEdit: 0.0.1 build 7 macOS: 13.1
Additional context
https://user-images.githubusercontent.com/25121427/211723143-e6d8f7c1-17ea-4131-9e60-b79d021b0313.mov
Might be related to #917 and @Code-DJ's PR #984
I've looked into this and it seems that it's a SwiftTerm bug.
@iggy890 what exactly brings you to this conclusion?
@lukepistrol That's because whenever the tabs are switched the updateNSView() function is fired it saves the terminal state. But SwiftTerm doesn't save the state, if you want to I could create an issue and tag the developer.
@iggy890 SwiftTerm is not supposed to save anything. The problem lies in somewhere in our implementation because at some point the SwiftTerm view gets deallocated (released from memory) and then reallocated while the saved state is not applied for some reason. Nothing to do with SwiftTerm.
Yeah I am going to take a look at this and see why the saved state does not get added to the new view, I have done some experimenting and I think I can find a solution.
On the latest release (0.0.2-alpha.27) this cannot be reproduced anyway. Can someone please double-check?
https://user-images.githubusercontent.com/9460130/223475428-bb2d9fbe-9650-4e8d-b4ff-e7990dc6fd89.mov
My terminal still does not save
@lukepistrol what is your terminal type? maybe a specific type of terminal does not save?
@bombardier200 ZSH
@lukepistrol This issue also happens with me and my terminal type is ZSH
@luah5 What do you mean by the tabs are the same?
Seems to me there's two problems.
UtilityAreaTerminalView.swift:247
.onAppear(perform: initializeTerminals)
is reinitializing terminals every time the view loads and should be changed to something like
.onAppear { if model.terminals.isEmpty { initializeTerminals() } }
With this change, any terminal views you have open will be restored with env variables intact, but, seemingly unrelatedly, the buffer will be reset to a fresh prompt without previous commands and output, like pressing ⌘K. I investigated this for an embarrassingly long time and don't understand why that's happening.