Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Restore closed tab #960

Closed
AClerbois opened this issue May 23, 2019 · 8 comments · Fixed by #11471
Closed

Feature Request - Restore closed tab #960

AClerbois opened this issue May 23, 2019 · 8 comments · Fixed by #11471
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@AClerbois
Copy link

Hello,

I'd suggest a restore tag feature like in internet browser. For example, you close a tab and press [CTRL] + [SHIFT] + [T] and that will restore the latest tab closed.

May be without the context in the first step but with the latest path.

P.S. : Thank you for your awesome project,, I'm very excited to use the final preview version with the new font.

@AClerbois AClerbois added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label May 23, 2019
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels May 23, 2019
@zadjii-msft
Copy link
Member

So tracking the most recently closed tab wouldn't be that hard. We could keep a stack of profiles as we close them, and just pop from that stack when we want to reopen one. That's not too hard.

What is hard is restoring state. Even restoring the path of the executable that was running might be incredibly tricky - can we get the cwd of an arbitrary executable? What if the executable was ssh, which in some directory in a remote machine? We certainly wouldn't be able to restore that connection. What if the path no longer exists? If we CreateProcess a process in a directory that doesn't exist, what happens? Do we just default to the profile's default? What if your cmd.exe profile was running powershell, and powershell had changed to some other directory? We can't restore the process tree, and because this is Windows, there isn't the concept of a "foreground" process attached to a conpty, so we'd have to default to using the state from the executable at the root of the process tree.

Just some thoughts off the top of my head. I'm sure @malxau actually has a lot more on this if I remember my email inbox correctly.

I want to make sure that this issue specifically tracks "restoring the last closed tab's profile" and not "restore it's state" because the former is easy and the latter is hard. We should probably have more discussion of the latter in a new issue, #961.


Actually now that I've typed #961 up, I had an idea. This might have to be something that the user opts in to, but we could theoretically just keep the TermControls from the N most recently closed tabs panes alive in the stack, and when the user reopens the tab, we just put the control back into the tab pane. I'm suggesting this is opt-in, since we'd be keeping some number of controls alive, including all the processes attached to them. This would definitely seem like a memory leak, unless the user has opted in to this behavior, and the user would almost certainly

  1. need to know this was happening
  2. have a way to manually shut these saved instances down

@zadjii-msft zadjii-msft added Area-Settings Issues related to settings and customizability, for console or terminal Area-User Interface Issues pertaining to the user interface of the Console or Terminal Product-Terminal The new Windows Terminal. labels May 23, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 23, 2019
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone May 23, 2019
@DHowett-MSFT DHowett-MSFT removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label May 23, 2019
@desmondkung
Copy link

I don't think restoring state is a good idea, especially from a security perspective. If I'm a bad actor and try to run terminal that restores state, it's like opening a box of surprises, which might make my work easier.

@Rosefield
Copy link
Contributor

Rosefield commented Oct 8, 2021

In light of the changes for #766 the version of this which is just re-opening the profile should be relatively easy

  • When closing a pane call Pane::GetTerminalArgsForPane
    NewTerminalArgs Pane::GetTerminalArgsForPane() const

    on the closed pane and add that to a stack of recently closed panes
  • To restore the recently closed pane either make a new tab using those new terminal args, or make an automatic split on the currently focused pane using those new terminal args.
  • To save/restore multiple panes you can call Pane::BuildStartupActions to get the list of actions to restore that tree of panes, and depending on if you are making a new tab or just attaching to the current pane you prepend a new tab / split pane command like the logic in TerminalTab::BuildStartupActions.
    std::vector<ActionAndArgs> TerminalTab::BuildStartupActions() const
    {
    // Give initial ids (0 for the child created with this tab,
    // 1 for the child after the first split.
    auto state = _rootPane->BuildStartupActions(0, 1);
    {
    ActionAndArgs newTabAction{};
    newTabAction.Action(ShortcutAction::NewTab);
    NewTabArgs newTabArgs{ state.firstPane->GetTerminalArgsForPane() };
    newTabAction.Args(newTabArgs);
    state.args.emplace(state.args.begin(), std::move(newTabAction));
    }

    The history stack could just be a std::vector<std::vector<ActionAndArgs>> and restoring would then just be popping and executing a list of actions.

@zadjii-msft
Copy link
Member

The implementation I had considered was simply hanging on to the last N TermControls when they get closed, to allow someone to fully restore that many panes. That way, if someone accidentally closed a long running command, then the whole command would come back with it.

Now, that of course had the downside that closing a pane wouldn't necessarily terminate the process in it. So your way is probably good even in addition to the active command restore

@ghost ghost added the In-PR This issue has a related PR label Oct 9, 2021
@zadjii-msft zadjii-msft modified the milestones: Terminal Backlog, Backlog Jan 4, 2022
@ghost ghost closed this as completed in #11471 Jan 11, 2022
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Jan 11, 2022
ghost pushed a commit that referenced this issue Jan 11, 2022
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request
Add an action to restore the last closed pane or tab. When all you have is restoring last sessions everything looks like a `std::vector<ActionAndArgs>`.

<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> 
## References
#9800 

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Partially closes #960 
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
* [x] Schema updated.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
- Keep a buffer of panes/tabs that were closed recently in the form of a list
  of actions to remake it.
- To restore the pane or tab just run the list of actions.
- This (deliberately) does not restore the exact visual state as focus could
  have changed / new panes might have been created in the mean time. Mostly
  this means that restoring a pane will just attach to the currently focused
  pane instead of whatever its old neighbor was.
- Buffer is limited to 100 entries which might as well be "infinite" by most reasonable 
  standards, but prevents complaints about there being memory leaks in long running 
  instances.
- The action name could be potentially changed, but it felt unwieldy as "restoreLastClosedPaneOrTab".
- This does not handle restoring the actual running contents of a pane.

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
@DHowett
Copy link
Member

DHowett commented Jan 11, 2022

When we market this feature, we should be very clear on what it does. If I recall correctly:

This does not restore the application running in the closed tab. The restore action restores a facsimilie of the closed session, but the application that was running in it doesn't keep running.

@ghost
Copy link

ghost commented Feb 3, 2022

🎉This issue was addressed in #11471, which has now been successfully released as Windows Terminal Preview v1.13.10336.0.:tada:

Handy links:

@tJKkeZQoZlcssuXjVjNerQ
Copy link

tJKkeZQoZlcssuXjVjNerQ commented Mar 14, 2022

🎉Este problema se solucionó en #11471, que ahora se ha publicado correctamente como .Windows Terminal Preview v1.13.10336.0🎉

Enlaces prácticos:

Aun existe un loop al iniciar el terminal. ocurre despues de guardar los cambios del terminal y poner el perfil que inicie como administrador y al abrirlo de nuevo. queda abriendo y cerrando el proceso pero nunca lo muestra.

@swinder0161
Copy link

The problem with this is the tab position is not restored, if tab closed is first one, the restored tab is the last one.
the position should also be restored

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants