terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Enable Terminal to persist / restore instance settings

Open zadjii-msft opened this issue 7 years ago • 57 comments

Let the user set a global setting to have the terminal re-open with whatever profiles were last open.

Thoughts:

  • what happens when a user has two windows open, closes one with 3 tabs, then opens a new window? Should it open the 3 tabs? Or should it start a fresh, single tabbed window?
  • how do we persist the last session?
  • Do we only persist the last tabs open when the last terminal window is closed?
  • Do we add a "quit terminal" option that closes all open windows, and persists all their open profiles?

THIS IS NOT A DISCUSSION OF PRESERVING WINDOW CONTENT, ONLY OPEN WINDOW PROFILES

This also includes restoring things like previous window positions.

zadjii-msft avatar May 14 '19 12:05 zadjii-msft

  1. Will this also restore split pane configurations?
  2. Will this restore the current directory (CWD/PWD) of each tab (as opposed to just the configured starting directory)?

IMO:

what happens when a user has two windows open, closes one with 3 tabs, then opens a new window? Should it open the 3 tabs? Or should it start a fresh, single tabbed window?

Open a fresh window. If you later add support for window history, they could use a "Recently closed windows" menu to restore the window with the same set of tabs.

how do we persist the last session? Do we only persist the last tabs open when the last terminal window is closed?

That would be the simplest solution probably, but it might not be ideal if the application is improperly shut down. An alternative would be to continuously track open windows, tabs, panes, and working directories as changes are made, and persist those changes immediately (or on a timer).

Do we add a "quit terminal" option that closes all open windows, and persists all their open profiles?

Firefox and Chrome have an "Exit" option, which closes all windows. When you start the application again, the windows are restored.

In general, I think that it would be great if Windows Terminal mimicked the behaviour of browsers.

glen-84 avatar May 21 '19 21:05 glen-84

I know this is just about tabs and pane arrangements, but why not restore the buffer with all the previous output strings in place?

mdtauk avatar May 21 '19 21:05 mdtauk

I was thinking, if the state is stored in a human-readable format, it could also be hand-edited by users, and generated/modified by an external script or programme.

A made-up example:

{
    "version": "0.2.0",
    "state": {
        "windows": [
            {
                "maximized": false,
                "positionX": 500,
                "positionY": 200,
                "width": 1000,
                "height": 2000,
                "tabs": [
                    {
                        "title": "Project X",
                        "panes": [
                            {
                                "profile": "EF3E32A7-5FF6-42B4-B6E2-96CD7D033F00",
                                "directory": "C:/...",
                                // position/dimensions
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

(As usual, I wish that people would move away from JSON and instead use something more suited to configuration files, like YAML.)


@mdtauk,

I know this is just about tabs and pane arrangements, but why not restore the buffer with all the previous output strings in place?

To limit the scope of the feature and get it released sooner. The format that I show above could easily be extended at a later stage.

glen-84 avatar May 22 '19 07:05 glen-84

The thing that makes me hate YAML is that the spec doesn’t support tabs.

I personally prefer HOCON over YAML and JSON.

The former because of tabs, and the latter because of comments.

ExE-Boss avatar May 22 '19 11:05 ExE-Boss

what happens when a user has two windows open, closes one with 3 tabs, then opens a new window? Should it open the 3 tabs? Or should it start a fresh, single tabbed window?

Use the browser behavior. It works and it is familiar. Also, would be nice to detach/reatach tabs (as Chrome).

how do we persist the last session?

It would be nice to persist everything (including history) of each tab. It would be amazing to have up arrow history persisted as well. You can use all my %USERPROFILE% space for that =)

Do we only persist the last tabs open when the last terminal window is closed?

As in a browser, when a tab is closed, its state remains (so I can reopen closed tabs with Ctrl+Shift+T). This would be awesome. Perhaps some settings to limit the number of persisted sessions?

Do we add a "quit terminal" option that closes all open windows, and persists all their open profiles?

As in a browser, [X] closes all tabs (I can reopen them with Ctrl+Shift+T - it will restore entire windows if needed).

JCKodel avatar Jun 22 '19 05:06 JCKodel

Updated title to better describe the ask, which also came-up in this Twitter thread: https://twitter.com/stanzillaz/status/1176675911275556866

bitcrazed avatar Sep 25 '19 19:09 bitcrazed

Renaming it again because it really seems to pertain to saving info about specific instances of specific profiles. We can quibble about session/profile/instance later. :smile:

DHowett-MSFT avatar Sep 26 '19 21:09 DHowett-MSFT

Still feeling this pain every time I re-open. I don't even mind it not remembering size, since I set that in my config. I just really hate it not remembering position, because on my system, every time it opens, the top-left corner is about 30px to the right/down from the last time it opened, so it shifts little by little until something resets it back to the top-left and the cycle repeats. That is endlessly annoying.

Would love even a minimal interim on window size being remembered quicker, even if this larger feature is still being worked out. Please!? :)

getify avatar May 24 '20 17:05 getify

@getify You know you can use the initialPosition to set a launch position for the Terminal window, right?

zadjii-msft avatar May 26 '20 17:05 zadjii-msft

@zadjii-msft No, I was not aware of that. Maybe it was added after the last time I had looked at the docs.

Just tried it, and with some fiddling it seems fine for now as an interim. I use a left-side taskbar, so it was a little annoying that the "X" position isn't "available desktop coordinates" but "absolute screen position". I figured out with some trial and error that 93 was the right magic number for my current setup.

getify avatar May 26 '20 17:05 getify

I found some workaround for this, which works for me and maybe will be helpful for others. I created cmd file with the following command: wt.exe -p PowerShell -d "D:\Projects" ; split-pane -p PowerShell -d "D:\Projects\foo" ; split-pane -H -p PowerShell -d "D:\Projects\bar" ; -p cmd -d "D:\Projects" ; -p Ubuntu ; focus-tab -t 0 which opens the tabs and panes I need to have opened.

also in settings.json I added the position and size:

  "initialPosition": "-1760, 20",
  "initialRows": 46,
  "initialCols": 170,

with x: -1760 I open terminal on my left monitor :)

smykhailov avatar May 27 '20 11:05 smykhailov

When restoring 'last position', please remember to handle which monitor (assuming more than one) the position refers to.

mws-rmain avatar Jun 15 '20 11:06 mws-rmain

Do not only remember the last monitor that was used, but also remember the last position used on other monitors.

When I have the Terminal open on my big monitor and disconnect my notebook, it will appear on my notebook's screen, of course. Now, it would be great if Terminal remembered the last position used when it was open on my big monitor's and my notebook's screens. Then, when I would re-connect my big monitor, the Terminal should appear on my big monitor, at the last position on that screen. If I disconnect my big monitor again, the Terminal should come back to the last position on my notebook's screen.

That is, the application should store the last monitor used and a table mapping each monitor to the position and dimensions the Terminal occupied on that monitor.

igorakkerman avatar Jul 03 '20 20:07 igorakkerman

Also remember position if opened on another virtual desktop.

radutomy avatar Aug 17 '20 13:08 radutomy

Do not only remember the last monitor that was used, but also remember the last position used on other monitors.

When I have the Terminal open on my big monitor and disconnect my notebook, it will appear on my notebook screen, of course. Now, it would be great if Terminal remembered the last position used when it was open on my big monitor's and my notebook's screens. Then, when I would re-connect my big monitor, the Terminal should appear on my big monitor, at the last position on that screen. If I disconnect my big monitor again, the Terminal should come back to the last position on my notebook's screen.

That is, the application should store the last monitor used and a table mapping each monitor to the position and dimensions the Terminal occupied on that monitor.

^ This would be great. But would rather have basic functionality than wait extra time for macOS tricks.

@glen-84 Pretty much nailed behavior with his comment about "do as browsers do". It keeps things fairly simple, and those are patterns that, while fairly powerful, anyone who uses a computer is familiar with.

clounie avatar Dec 09 '20 16:12 clounie

As described in #8989, if the state can be persisted to file as suggested in https://github.com/microsoft/terminal/issues/766#issuecomment-494689538 then a desirable feature would be to be able to invoke a new terminal instance and supply that particular configuration as the startup state (via argument). That would help alleviate some of the ambiguity around what to do in the case of multiple open instances.

NeilMacMullen avatar Feb 01 '21 15:02 NeilMacMullen

Let the user set a global setting to have the terminal re-open with whatever profiles were last open.

Thoughts:

  • what happens when a user has two windows open, closes one with 3 tabs, then opens a new window? Should it open the 3 tabs? Or should it start a fresh, single tabbed window?
  • how do we persist the last session?
  • Do we only persist the last tabs open when the last terminal window is closed?
  • Do we add a "quit terminal" option that closes all open windows, and persists all their open profiles?

THIS IS NOT A DISCUSSION OF PRESERVING WINDOW CONTENT, ONLY OPEN WINDOW PROFILES

@zadjii-msft

You should have this restore just like a browser, i.e., either restore last window closed, or if they select "Exit" command, restore all windows. What would be really awesome would be to save command history in each tab so you can just up arrow to bring back recent commands. That will make this indispensable.

Thank you.

brantPTS avatar Feb 02 '21 15:02 brantPTS

What would be really awesome would be to save command history in each tab so you can just up arrow to bring back recent commands.

FYI this has been discussed to death elsewhere in this repo - it's not the terminal's responsibility to remember what the last commands entered were. Most modern shells (e.g. pwsh, bash, zsh) will already do this. cmd can't do this, because cmd has never done that, and cmd is in maintenance-only mode.

The rest though - I'm on board with all that ☺️

zadjii-msft avatar Feb 02 '21 16:02 zadjii-msft

hey @zadjii-msft (sorry if you're not back from your vacay) this issue doesn't sound like remembering the size and position of a Terminal window to many users, including myself. The discussion below it and the closed issues do make it look like it, but not everyone will have the time and patience to do that. Mind updating the issue to say something about it independent of there being an option to restore the last session? :)

Poopooracoocoo avatar Feb 15 '21 02:02 Poopooracoocoo

Okay, sure. I'll update the OP. To clarify:

  • #766 (This issue) is tracking restoring the relative window state across terminal launches. This includes (but is not limited to) window positions, the open tab/pane structure, and what profiles were in those tab/panes. It is not tracking restoring buffer state.
  • #961 is specifically related to trying to restore the buffer content of these tabs/panes. This is substantially harder than just restoring the window state, because the buffer has quite a bit more state in it. It is not tracking connection state (commandline history, environment variables, open processes)
  • #960 is about just "restoring previously opened tabs/panes". This is like when you close a tab in a browser, then hit Ctrl+shift+t to just pop it back into existence. This does not include across reboots - it mainly deals with tab/panes closed in the current instance.
  • There's not an issue tracking restoring connection/shell/process state, because that's generally impossible. (case in point: https://github.com/microsoft/terminal/issues/961#issuecomment-495506932, et. al in that thread.)
  • #9188 is "restoring the window state while it is running, but after an external monitor is disconnected and re-connected?"

zadjii-msft avatar Feb 16 '21 15:02 zadjii-msft