Skip to content

Commit

Permalink
[PTRun][Terminal]Array settings parsing (#17707)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed Apr 13, 2022
1 parent a5323b7 commit e530968
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 10 deletions.
Expand Up @@ -38,7 +38,10 @@
</ItemGroup>

<ItemGroup>
<None Update="settings.json">
<None Update="settings 1.11.2421.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="settings 1.11.2421.0_2.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Expand Up @@ -23,12 +23,14 @@ public void ArgumentsTest(string profile, bool openNewTab, string expectedArgume
Assert.AreEqual(arguments, expectedArguments);
}

[TestMethod]
public void ParseSettingsTest()
[DataTestMethod]
[DataRow("settings 1.11.2421.0.json")]
[DataRow("settings 1.11.2421.0_2.json")]
public void ParseSettingsTest(string file)
{
var terminal = new TerminalPackage(string.Empty, new Version(), string.Empty, string.Empty, string.Empty);

var settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
var settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
var settings = File.ReadAllText(settingsPath);
var profiles = TerminalHelper.ParseSettings(terminal, settings);

Expand Down
@@ -0,0 +1,95 @@
// This file was initially generated by Windows Terminal Preview 1.11.2421.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",

"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings

// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,

// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,

// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles": [
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
"name": "Git Bash",
"source": "Git"
}
],

// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [],

// Add custom actions and keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
"actions": [
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{
"command": {
"action": "copy",
"singleLine": false
},
"keys": "ctrl+c"
},
{
"command": "paste",
"keys": "ctrl+v"
},

// Press Ctrl+Shift+F to open the search box
{
"command": "find",
"keys": "ctrl+shift+f"
},

// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{
"command": {
"action": "splitPane",
"split": "auto",
"splitMode": "duplicate"
},
"keys": "alt+shift+d"
}
]
}
Expand Up @@ -35,15 +35,22 @@ public static List<TerminalProfile> ParseSettings(TerminalPackage terminal, stri
};

var json = JsonDocument.Parse(settingsJson, options);
JsonElement profilesList;

json.RootElement.TryGetProperty("profiles", out JsonElement profilesElement);
if (profilesElement.ValueKind != JsonValueKind.Object)
if (profilesElement.ValueKind == JsonValueKind.Object)
{
return profiles;
profilesElement.TryGetProperty("list", out profilesList);
if (profilesList.ValueKind != JsonValueKind.Array)
{
return profiles;
}
}

profilesElement.TryGetProperty("list", out JsonElement profilesList);
if (profilesList.ValueKind != JsonValueKind.Array)
else if (profilesElement.ValueKind == JsonValueKind.Array)
{
profilesList = profilesElement;
}
else
{
return profiles;
}
Expand Down
Expand Up @@ -68,6 +68,6 @@ private IEnumerable<TerminalPackage> GetTerminals()
var settingsPath = Path.Combine(localAppDataPath, "Packages", p.Id.FamilyName, "LocalState", "settings.json");
yield return new TerminalPackage(aumid, version, p.DisplayName, settingsPath, p.Logo.LocalPath);
}
}
}
}
}

0 comments on commit e530968

Please sign in to comment.