Compare commits

...

1 Commits

Author SHA1 Message Date
Mike Griese
73afe48041 plumb it through. It works
(cherry-picked from 38999195b)
2024-06-01 12:27:21 -05:00
10 changed files with 74 additions and 2 deletions

26
.wt.json Normal file
View File

@@ -0,0 +1,26 @@
{
"actions":
[
{
"command": { "action": "sendInput", "input": "bx\r" },
"name": "Build project",
"description": "Build the project in the CWD"
},
{
"command": { "action": "sendInput", "input": "bz\r" },
"name": "Build solution, incremental",
"description": "Just build changes to the solution"
},
{
"command": { "action": "sendInput", "input": "bcz\r" },
"name": "Clean & build solution",
"description": "Start over. Go get your coffee. "
},
{
"command": { "action": "sendInput", "input": "nuget push -apikey az -source TerminalDependencies %userprofile%\\Downloads" },
"name": "Upload package to nuget feed",
"description": "Go download a .nupkg, put it in ~/Downloads, and use this to push to our private feed."
},
]
}

View File

@@ -2256,7 +2256,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
return winrt::hstring{ L"" };
};
const auto currentCommand = _terminal->CurrentCommand();
const auto trimmedCurrentCommand = trimToHstring(currentCommand);
@@ -2279,6 +2278,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
auto context = winrt::make_self<CommandHistoryContext>(std::move(commands));
context->CurrentCommandline(trimmedCurrentCommand);
context->CurrentWorkingDirectory(winrt::hstring{ _terminal->GetWorkingDirectory() });
return *context;
}

View File

@@ -68,6 +68,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
til::property<Windows::Foundation::Collections::IVector<winrt::hstring>> History;
til::property<winrt::hstring> CurrentCommandline;
til::property<winrt::hstring> CurrentWorkingDirectory;
CommandHistoryContext(std::vector<winrt::hstring>&& history)
{

View File

@@ -70,6 +70,7 @@ namespace Microsoft.Terminal.Control
{
IVector<String> History { get; };
String CurrentCommandline { get; };
String CurrentWorkingDirectory { get; };
};
[default_interface] runtimeclass ControlCore : ICoreState

View File

@@ -1095,6 +1095,20 @@ void CascadiaSettings::ExportFile(winrt::hstring path, winrt::hstring content)
}
CATCH_LOG();
}
winrt::hstring CascadiaSettings::ReadFile(winrt::hstring path)
{
try
{
auto maybeContents = ReadUTF8FileIfExists({ path.c_str() });
if (maybeContents.has_value())
{
return winrt::hstring{ til::u8u16(*maybeContents) };
}
}
CATCH_LOG();
return L"";
}
void CascadiaSettings::_validateThemeExists()
{

View File

@@ -113,6 +113,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static winrt::hstring ApplicationVersion();
static bool IsPortableMode();
static void ExportFile(winrt::hstring path, winrt::hstring content);
static winrt::hstring ReadFile(winrt::hstring path);
CascadiaSettings() noexcept = default;
CascadiaSettings(const winrt::hstring& userJSON, const winrt::hstring& inboxJSON);

View File

@@ -21,6 +21,7 @@ namespace Microsoft.Terminal.Settings.Model
static String ApplicationVersion { get; };
static void ExportFile(String path, String content);
static String ReadFile(String path);
CascadiaSettings(String userJSON, String inboxJSON);

View File

@@ -828,4 +828,29 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return winrt::single_threaded_vector<Model::Command>(std::move(result));
}
void Command::AddLocalCommands(const Windows::Foundation::Collections::IVector<Model::Command>& commands,
winrt::hstring localTasksFileContents)
{
auto data = winrt::to_string(localTasksFileContents);
std::string errs;
static std::unique_ptr<Json::CharReader> reader{ Json::CharReaderBuilder::CharReaderBuilder().newCharReader() };
Json::Value root;
if (!reader->parse(data.data(), data.data() + data.size(), &root, &errs))
{
throw winrt::hresult_error(WEB_E_INVALID_JSON_STRING, winrt::to_hstring(errs));
}
if (auto actions{ root[JsonKey("actions")] })
{
std::vector<SettingsLoadWarnings> warnings;
for (const auto& json : actions)
{
auto parsed = Command::FromJson(json, warnings, OriginTag::Generated, false);
if (parsed->ActionAndArgs().Action() != ShortcutAction::SendInput)
continue;
commands.Append(*parsed);
}
}
}
}

View File

@@ -77,6 +77,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static Windows::Foundation::Collections::IVector<Model::Command> HistoryToCommands(Windows::Foundation::Collections::IVector<winrt::hstring> history,
winrt::hstring currentCommandline,
bool directories);
static void AddLocalCommands(const Windows::Foundation::Collections::IVector<Model::Command>&, winrt::hstring localTasksFileContents);
WINRT_PROPERTY(ExpandCommandType, IterateOn, ExpandCommandType::None);
WINRT_PROPERTY(Model::ActionAndArgs, ActionAndArgs);

View File

@@ -49,6 +49,6 @@ namespace Microsoft.Terminal.Settings.Model
static IVector<Command> ParsePowerShellMenuComplete(String json, Int32 replaceLength);
static IVector<Command> HistoryToCommands(IVector<String> commandHistory, String commandline, Boolean directories);
static void AddLocalCommands(IVector<Command> commands, String localTasksFileContents);
}
}