Terminal: Enable Terminal to persist / restore instance settings

Created on 14 May 2019  路  14Comments  路  Source: microsoft/terminal

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__

Area-Settings Area-User Interface Issue-Feature Product-Terminal

Most helpful comment

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 :)

All 14 comments

  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.

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

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.

The thing that makes me hate YAML is that the spec doesn鈥檛 support tabs.

I personally prefer HOCON over YAML and JSON.

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

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).

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

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:

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 You know you can use the initialPosition to set a launch position for the Terminal window, right?

@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.

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 :)

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

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.

Also remember position if opened on another virtual desktop.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghvanderweg picture ghvanderweg  路  3Comments

mdtauk picture mdtauk  路  3Comments

NickITGuy picture NickITGuy  路  3Comments

mdtauk picture mdtauk  路  3Comments

warpdesign picture warpdesign  路  3Comments