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

Add WT_PROFILE_ID to the environment of the spawned process #4852

Merged
23 commits merged into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9aaae49
add wt_defaults and wt_profile env vars
oising Mar 9, 2020
c06b6e7
remove commented code
oising Mar 9, 2020
410f9ff
wt_profile -> wt_profiles (match filename)
oising Mar 9, 2020
bf2c2bd
as per devops nit, invoke-codeformat
oising Mar 9, 2020
fd71f0a
add nullptr check around _environment (az shell won't set these vars)
oising Mar 9, 2020
5ad2c6a
make nullptr check idiomatic with rest of codebase
oising Mar 9, 2020
1d5524b
address review nits; add WT_PROFILE_ID var for current profile
oising Mar 10, 2020
fe534fa
undo VS mods to openconsole.sln
oising Mar 10, 2020
bd75029
remove more dead code
oising Mar 10, 2020
e8309b8
add newline to end of openconsole.sln... grrr
oising Mar 10, 2020
10fbf81
address review: switch to Utils::GuidToString
oising Mar 11, 2020
deeae57
rename WT_PROFILES to WT_SETTINGS to match PR #5199
oising Apr 1, 2020
21642ef
Merge branch 'master' of https://github.com/microsoft/terminal into f…
oising Apr 2, 2020
0c52159
oops, paths ain't string no mo'.
oising Apr 3, 2020
2a82bde
add apis.txt for spell checker
oising Apr 4, 2020
44df680
Merge branch 'master' into feature/profile-env-vars
zadjii-msft Apr 9, 2020
9b14c34
Merge branch 'master' into feature/profile-env-vars
oising Apr 10, 2020
e1c0051
Remove WT_DEFAULTS and WT_SETTINGS env vars for the moment, leaving W…
oising Apr 14, 2020
6b5e65e
Merge branch 'feature/profile-env-vars' of https://github.com/oising/…
oising Apr 14, 2020
8bfd932
Merge branch 'master' into feature/profile-env-vars
oising Apr 15, 2020
898d128
Update src/cascadia/TerminalConnection/ConptyConnection.cpp
oising Apr 16, 2020
afa43fa
address dustin's comments (don't clobber wslenv)
oising Apr 17, 2020
c6ed972
fix code formatting
oising Apr 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
IMap
ICustom
IObject
LCID
Expand Down
30 changes: 23 additions & 7 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DebugTapConnection.h"

using namespace winrt;
using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::System;
Expand Down Expand Up @@ -572,7 +573,13 @@ namespace winrt::TerminalApp::implementation
// TODO GH#4661: Replace this with directly using the AzCon when our VT is better
std::filesystem::path azBridgePath{ wil::GetModuleFileNameW<std::wstring>(nullptr) };
azBridgePath.replace_filename(L"TerminalAzBridge.exe");
connection = TerminalConnection::ConptyConnection(azBridgePath.wstring(), L".", L"Azure", settings.InitialRows(), settings.InitialCols(), winrt::guid());
connection = TerminalConnection::ConptyConnection(azBridgePath.wstring(),
L".",
L"Azure",
nullptr,
settings.InitialRows(),
settings.InitialCols(),
winrt::guid());
}

else if (profile->HasConnectionType() &&
Expand All @@ -583,12 +590,21 @@ namespace winrt::TerminalApp::implementation

else
{
auto conhostConn = TerminalConnection::ConptyConnection(settings.Commandline(),
settings.StartingDirectory(),
settings.StartingTitle(),
settings.InitialRows(),
settings.InitialCols(),
winrt::guid());
std::wstring guidWString = Utils::GuidToString(profileGuid);

StringMap envMap{};
envMap.Insert(L"WT_PROFILE_ID", guidWString);
envMap.Insert(L"WSLENV", L"WT_PROFILE_ID");
oising marked this conversation as resolved.
Show resolved Hide resolved

auto conhostConn = TerminalConnection::ConptyConnection(
settings.Commandline(),
settings.StartingDirectory(),
settings.StartingTitle(),
envMap.GetView(),
settings.InitialRows(),
settings.InitialCols(),
winrt::guid());

sessionGuid = conhostConn.Guid();
connection = conhostConn;
}
Expand Down
14 changes: 13 additions & 1 deletion src/cascadia/TerminalConnection/ConptyConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "ConptyConnection.g.cpp"

#include "../../types/inc/Utils.hpp"
#include "../../types/inc/utils.hpp"
#include "../../types/inc/Environment.hpp"
#include "LibraryResources.h"

Expand Down Expand Up @@ -110,7 +110,17 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
// Ensure every connection has the unique identifier in the environment.
environment.insert_or_assign(L"WT_SESSION", guidSubStr.data());

if (_environment)
{
// add additional WT env vars like WT_SETTINGS, WT_DEFAULTS and WT_PROFILE_ID
for (auto item : _environment)
{
environment.insert_or_assign(item.Key().c_str(), item.Value().c_str());
}
}

auto wslEnv = environment[L"WSLENV"]; // We always want to load something, even if it's blank.
//
oising marked this conversation as resolved.
Show resolved Hide resolved
// WSLENV is a colon-delimited list of environment variables (+flags) that should appear inside WSL
// https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
wslEnv = L"WT_SESSION:" + wslEnv; // prepend WT_SESSION to make sure it's visible inside WSL.
Expand Down Expand Up @@ -173,6 +183,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
ConptyConnection::ConptyConnection(const hstring& commandline,
const hstring& startingDirectory,
const hstring& startingTitle,
const Windows::Foundation::Collections::IMapView<hstring, hstring>& environment,
const uint32_t initialRows,
const uint32_t initialCols,
const guid& initialGuid) :
Expand All @@ -181,6 +192,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
_commandline{ commandline },
_startingDirectory{ startingDirectory },
_startingTitle{ startingTitle },
_environment{ environment },
_guid{ initialGuid },
_u8State{},
_u16Str{},
Expand Down
10 changes: 9 additions & 1 deletion src/cascadia/TerminalConnection/ConptyConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
{
struct ConptyConnection : ConptyConnectionT<ConptyConnection>, ConnectionStateHolder<ConptyConnection>
{
ConptyConnection(const hstring& cmdline, const hstring& startingDirectory, const hstring& startingTitle, const uint32_t rows, const uint32_t cols, const guid& guid);
ConptyConnection(
const hstring& cmdline,
const hstring& startingDirectory,
const hstring& startingTitle,
const Windows::Foundation::Collections::IMapView<hstring, hstring>& environment,
const uint32_t rows,
const uint32_t cols,
const guid& guid);

void Start();
void WriteInput(hstring const& data);
Expand All @@ -40,6 +47,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
hstring _commandline;
hstring _startingDirectory;
hstring _startingTitle;
Windows::Foundation::Collections::IMapView<hstring, hstring> _environment;
guid _guid{}; // A unique session identifier for connected client
hstring _clientName{}; // The name of the process hosted by this ConPTY connection (as of launch).

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalConnection/ConptyConnection.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.Terminal.TerminalConnection
[default_interface]
runtimeclass ConptyConnection : ITerminalConnection
{
ConptyConnection(String cmdline, String startingDirectory, String startingTitle, UInt32 rows, UInt32 columns, Guid guid);
ConptyConnection(String cmdline, String startingDirectory, String startingTitle, IMapView<String,String> environment, UInt32 rows, UInt32 columns, Guid guid);
Guid Guid { get; };
};

Expand Down