Skip to content

Commit 8ba8f35

Browse files
authored
Add Cascading User + Default Settings (#2515)
This PR represents the start of the work on Cascading User + default settings, #754. Cascading settings will be done in two parts: * [ ] Layered Default+User settings (this PR) * [ ] Dynamic Profile Generation (#2603). Until _both_ are done, _neither are going in. The dynamic profiles PR will target this PR when it's ready, but will go in as a separate commit into master. This PR covers adding one primary feature: the settings are now in two separate files: * a static `defaults.json` that ships with the package (the "default settings") * a `profiles.json` with the user's customizations (the "user settings) User settings are _layered_ upon the settings in the defaults settings. ## References Other things that might be related here: * #1378 - This seems like it's definitely fixed. The default keybindings are _much_ cleaner, and without the save-on-load behavior, the user's keybindings will be left in a good state * #1398 - This might have honestly been solved by #2475 ## PR Checklist * [x] Closes #754 * [x] Closes #1378 * [x] Closes #2566 * [x] I work here * [x] Tests added/passed * [x] Requires documentation to be updated - it **ABSOLUTELY DOES** ## Detailed Description of the Pull Request / Additional comments 1. We start by taking all of the `FromJson` functions in Profile, ColorScheme, Globals, etc, and converting them to `LayerJson` methods. These are effectively the same, with the change that instead of building a new object, they are simply layering the values on top of `this` object. 2. Next, we add tests for layering properties like that. 3. Now, we add a `defaults.json` to the package. This is the file the users can refer to as our default settings. 4. We then take that `defaults.json` and stamp it into an auto generated `.h` file, so we can use it's data without having to worry about reading it from disk. 5. We then change the `LoadAll` function in `CascadiaSettings`. Now, the function does two loads - one from the defaults, and then a second load from the `profiles.json` file, layering the settings from each source upon the previous values. 6. If the `profiles.json` file doesn't exist, we'll create it from a hardcoded `userDefaults.json`, which is stamped in similar to how `defaults.json` is. 7. We also add support for _unbinding_ keybindings that might exist in the `defaults.json`, but the user doesn't want to be bound to anything. 8. We add support for _hiding_ a profile, which is useful if a user doesn't want one of the default profiles to appear in the list of profiles. ## TODO: * [x] Still need to make Alt+Click work on the settings button * [x] Need to write some user documentation on how the new settings model works * [x] Fix the pair of tests I broke (re: Duplicate profiles) <hr> * Create profiles by layering them * Update test to layer multiple times on the same profile * Add support for layering an array of profiles, but break a couple tests * Add a defaults.json to the package * Layer colorschemes * Moves tests into individual classes * adds support for layering a colorscheme on top of another * Layer an array of color schemes * oh no, this was missed with #2481 must have committed without staging this change, uh oh. Not like those tests actually work so nbd * Layer keybindings * Read settings from defaults.json + profiles.json, layer appropriately This is like 80% of #754. Needs tests. * Add tests for keybindings * add support to unbind a key with `null` or `"unbound"` or `"garbage"` * Layer or clear optional properties * Add a helper to get an optional variable for a bunch of different types In the end, I think we need to ask _was this worth it_ * Do this with the stretch mode too * Add back in the GUID check for profiles * Add some tests for global settings layering * M A D W I T H P O W E R Add a MsBuild target to auto-generate a header with the defaults.json as a string in the file. That way, we can _always_ load the defaults. Literally impossible to not. * When the user's profile.json doesn't exist, create it from a template * Re-order profiles to match the order set in the user's profiles.json * Add tests for re-ordering profiles to match user ordering * Add support for hiding profiles using `"hidden": true` * Use the hardcoded defaults.json for the exception->"use defaults" case * Somehow I messed up the git submodules? * woo documentation * Fix a Terminal.App.Unit.Tests failure * signed/unsigned is hard * Use Alt+Settings button to open the default settings * Missed a signed/unsigned * Some very preliminary PR feedback * More PR feedback Use the wil helper for the exe path Move jsonutils into their own file kill some dead code * Add templates to these bois * remove some code for generating defaults, reorder defaults.json a tad * Make guid a std::optional * Large block of PR feedback * Remove some dead code * add some comments * tag some todos * stl is love, stl is life * add `-noprofile` * Fix the crash that dustin found * -Encoding ASCII * Set a profile's default scheme to Campbell * Fix the tests I regressed * Update UsingJsonSetting.md to reflect that changes from these PRs * Change how GenerateGuidForProfile works * Make AppKeyBindings do its own serialization * Remove leftover dead code from the previous commit * Fix up an enormous number of PR nits * Fix a typo; Update the defaults to match #2378 * Tiny nits * Some typos, PR nits * Fix this broken defaults case
1 parent ed87689 commit 8ba8f35

36 files changed

Lines changed: 2783 additions & 699 deletions

‎doc/user-docs/UsingJsonSettings.md‎

Lines changed: 120 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# Editing Windows Terminal JSON Settings
22

3-
One way (currently the only way) to configure Windows Terminal is by editing the profiles.json settings file. At
4-
the time of writing you can open the settings file in your default editor by selecting
5-
`Settings` from the WT pull down menu.
3+
One way (currently the only way) to configure Windows Terminal is by editing the
4+
`profiles.json` settings file. At the time of writing you can open the settings
5+
file in your default editor by selecting `Settings` from the WT pull down menu.
66

7-
The settings are stored in the file `$env:LocalAppData\Packages\Microsoft.WindowsTerminal_<randomString>\RoamingState\profiles.json`
7+
The settings are stored in the file `$env:LocalAppData\Packages\Microsoft.WindowsTerminal_<randomString>\RoamingState\profiles.json`.
88

9-
Details of specific settings can be found [here](../cascadia/SettingsSchema.md). A general introduction is provided below.
9+
As of [#2515](https://github.com/microsoft/terminal/pull/2515), the settings are
10+
split into _two_ files: a hardcoded `defaults.json`, and `profiles.json`, which
11+
contains the user settings. Users should only be concerned with the contents of
12+
the `profiles.json`, which contains their customizations. The `defaults.json`
13+
file is only provided as a reference of what the default settings are. For more
14+
details on how these two files work, see [Settings
15+
Layering](#settings-layering). To view the default settings file, click on the
16+
"Settings" button while holding the <kbd>Alt</kbd> key.
17+
18+
Details of specific settings can be found [here](../cascadia/SettingsSchema.md).
19+
A general introduction is provided below.
1020

1121
The settings are grouped under four headings:
1222

@@ -17,12 +27,13 @@ The settings are grouped under four headings:
1727

1828
## Global Settings
1929

20-
These settings define startup defaults.
30+
These settings define startup defaults, and application-wide settings that might
31+
not affect a particular terminal instance.
2132

2233
* Theme
2334
* Title Bar options
2435
* Initial size
25-
* Default profile used when WT is started
36+
* Default profile used when the Windows Terminal is started
2637

2738
Example settings include
2839

@@ -31,10 +42,13 @@ Example settings include
3142
"initialCols" : 120,
3243
"initialRows" : 50,
3344
"requestedTheme" : "system",
34-
"keybinding" : []
45+
"keybindings" : []
3546
...
3647
```
3748

49+
These global properties can exist either in the root json object, or in and
50+
object under a root property `"globals"`.
51+
3852
## Key Bindings
3953

4054
This is an array of key chords and shortcuts to invoke various commands.
@@ -43,10 +57,29 @@ Each command can have more than one key binding.
4357
NOTE: Key bindings is a subfield of the global settings and
4458
key bindings apply to all profiles in the same manner.
4559

60+
For example, here's a sample of the default keybindings:
61+
62+
```json
63+
{
64+
"keybindings":
65+
[
66+
{ "command": "closePane", "keys": ["ctrl+shift+w"] },
67+
{ "command": "copy", "keys": ["ctrl+shift+c"] },
68+
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
69+
// etc.
70+
]
71+
}
72+
73+
```
74+
4675
## Profiles
4776

48-
A profile contains the settings applied when a new WT tab is opened. Each profile is identified by a GUID and contains
49-
a number of other fields.
77+
A profile contains the settings applied when a new WT tab is opened. Each
78+
profile is identified by a GUID and contains a number of other fields.
79+
80+
> 👉 **Note**: The `guid` property is the unique identifier for a profile. If
81+
> multiple profiles all have the same `guid` value, you may see unexpected
82+
> behavior.
5083
5184
* Which command to execute on startup - this can include arguments.
5285
* Starting directory
@@ -77,6 +110,14 @@ The profile GUID is used to reference the default profile in the global settings
77110

78111
The values for background image stretch mode are documented [here](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.stretch)
79112

113+
### Hiding a profile
114+
115+
If you want to remove a profile from the list of profiles in the new tab
116+
dropdown, but keep the profile around in your `profiles.json` file, you can add
117+
the property `"hidden": true` to the profile's json. This can also be used to
118+
remove the default `cmd` and PowerShell profiles, if the user does not wish to
119+
see them.
120+
80121
## Color Schemes
81122

82123
Each scheme defines the color values to be used for various terminal escape sequences.
@@ -97,6 +138,62 @@ Each schema is identified by the name field. Examples include
97138

98139
The schema name can then be referenced in one or more profiles.
99140

141+
## Settings layering
142+
143+
The runtime settings are actually constructed from _three_ sources:
144+
* The default settings, which are hardcoded into the application, and available
145+
in `defaults.json`. This includes the default keybindings, color schemes, and
146+
profiles for both Windows PowerShell and Command Prompt (`cmd.exe`).
147+
* Dynamic Profiles, which are generated at runtime. These include Powershell
148+
Core, the Azure Cloud Shell connector, and profiles for and WSL distros.
149+
* The user settings from `profiles.json`.
150+
151+
Settings from each of these sources are "layered" upon the settings from
152+
previous sources. In this manner, the user settings in `profiles.json` can
153+
contain _only the changes from the default settings_. For example, if a user
154+
would like to only change the color scheme of the default `cmd` profile to
155+
"Solarized Dark", you could change your cmd profile to the following:
156+
157+
```js
158+
{
159+
// Make changes here to the cmd.exe profile
160+
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
161+
"colorScheme": "Solarized Dark"
162+
}
163+
```
164+
165+
Here, we're know we're changing the `cmd` profile, because the `guid`
166+
`"{0caa0dad-35be-5f56-a8ff-afceeeaa6101}"` is `cmd`'s unique GUID. Any profiles
167+
with that GUID will all be treated as the same object. Any changes in that
168+
profile will overwrite those from the defaults.
169+
170+
Similarly, you can overwrite settings from a color scheme by defining a color
171+
scheme in `profiles.json` with the same name as a default color scheme.
172+
173+
If you'd like to unbind a keystroke that's bound to an action in the default
174+
keybindings, you can set the `"command"` to `"unbound"` or `null`. This will
175+
allow the keystroke to fallthough to the commandline application instead of
176+
performing the default action.
177+
178+
### Dynamic Profiles
179+
180+
When dynamic profiles are created at runtime, they'll be added to the
181+
`profiles.json` file. You can identify these profiles by the presence of a
182+
`"source"` property. These profiles are tied to their source - if you uninstall
183+
a linux distro, then the profile will remain in your `profiles.json` file, but
184+
the profile will be hidden.
185+
186+
If you'd like to disable a particular dynamic profile source, you can add that
187+
`source` to the global `"disabledProfileSources"` array. For example, if you'd
188+
like to hide all the WSL profiles, you could add the following setting:
189+
190+
```json
191+
192+
"disabledProfileSources": ["Microsoft.Terminal.WSL"],
193+
...
194+
195+
```
196+
100197
## Configuration Examples:
101198

102199
### Add a custom background to the WSL Debian terminal profile
@@ -127,15 +224,17 @@ then you should use the URI style path name given in the above example.
127224
More information about UWP URI schemes [here](https://docs.microsoft.com/en-us/windows/uwp/app-resources/uri-schemes).
128225
3. Instead of using a UWP URI you can use a:
129226
1. URL such as
130-
`http://open.esa.int/files/2017/03/Mayer_and_Bond_craters_seen_by_SMART-1-350x346.jpg`
227+
`http://open.esa.int/files/2017/03/Mayer_and_Bond_craters_seen_by_SMART-1-350x346.jpg`
131228
2. Local file location such as `C:\Users\Public\Pictures\openlogo.jpg`
132229

133-
### Adding Copy and Paste Keybindings
230+
### Adding Copy and Paste Keybindings
134231

135-
As of [#1093](https://github.com/microsoft/terminal/pull/1093) (first available in Windows Terminal v0.3), the Windows Terminal now
136-
supports copy and paste keyboard shortcuts. However, if you installed and ran
137-
the terminal before that, you won't automatically get the new keybindings added
138-
to your settings. If you'd like to add shortcuts for copy and paste, you can do so by inserting the following objects into your `globals.keybindings` array:
232+
As of [#1093](https://github.com/microsoft/terminal/pull/1093) (first available
233+
in Windows Terminal v0.3), the Windows Terminal now supports copy and paste
234+
keyboard shortcuts. However, if you installed and ran the terminal before that,
235+
you won't automatically get the new keybindings added to your settings. If you'd
236+
like to add shortcuts for copy and paste, you can do so by inserting the
237+
following objects into your `globals.keybindings` array:
139238

140239
```json
141240
{ "command": "copy", "keys": ["ctrl+shift+c"] },
@@ -171,5 +270,8 @@ You can even set multiple keybindings for a single action if you'd like. For exa
171270
will bind both <kbd>ctrl+shift+v</kbd> and
172271
<kbd>shift+Insert</kbd> to `paste`.
173272

174-
Note: If you set your copy keybinding to `"ctrl+c"`, you'll only be able to send an interrupt to the commandline application using <kbd>Ctrl+C</kbd> when there's no text selection.
175-
Additionally, if you set `paste` to `"ctrl+v"`, commandline applications won't be able to read a ctrl+v from the input. For these reasons, we suggest `"ctrl+shift+c"` and `"ctrl+shift+v"`
273+
Note: If you set your copy keybinding to `"ctrl+c"`, you'll only be able to send
274+
an interrupt to the commandline application using <kbd>Ctrl+C</kbd> when there's
275+
no text selection. Additionally, if you set `paste` to `"ctrl+v"`, commandline
276+
applications won't be able to read a ctrl+v from the input. For these reasons,
277+
we suggest `"ctrl+shift+c"` and `"ctrl+shift+v"`

‎src/cascadia/CascadiaPackage/CascadiaPackage.wapproj‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
<Content Include="$(OpenConsoleDir)res\terminal\Wide310x150Logo.scale-400.png">
250250
<Link>Images\Wide310x150Logo.scale-400.png</Link>
251251
</Content>
252+
<!-- Profile Icons -->
252253
<Content Include="ProfileIcons\{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.scale-100.png" />
253254
<Content Include="ProfileIcons\{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.scale-200.png" />
254255
<Content Include="ProfileIcons\{574e775e-4f2a-5b96-ac1e-a2962a402336}.scale-100.png" />
@@ -259,9 +260,16 @@
259260
<Content Include="ProfileIcons\{9acb9455-ca41-5af7-950f-6bca1bc9722f}.scale-200.png" />
260261
<Content Include="ProfileIcons\{b453ae62-4e3d-5e58-b989-0a998ec441b8}.scale-100.png" />
261262
<Content Include="ProfileIcons\{b453ae62-4e3d-5e58-b989-0a998ec441b8}.scale-200.png" />
263+
<!-- Default Settings -->
264+
<Content Include="$(OpenConsoleDir)src\cascadia\TerminalApp\defaults.json">
265+
<Link>defaults.json</Link>
266+
</Content>
267+
<!-- Resources -->
262268
<PRIResource Include="Resources\en-US\Resources.resw" />
263269
</ItemGroup>
270+
264271
<Import Project="$(OpenConsoleDir)src\wap-common.build.post.props" />
272+
265273
<ItemGroup>
266274
<ProjectReference Include="..\WindowsTerminal\WindowsTerminal.vcxproj" />
267275
<ProjectReference Include="..\..\host\exe\Host.EXE.vcxproj" />

0 commit comments

Comments
 (0)