plumb it through. It works

This commit is contained in:
Mike Griese
2024-03-18 06:55:27 -05:00
parent 318256098c
commit 38999195b2
11 changed files with 91 additions and 1 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

@@ -52,6 +52,23 @@ namespace winrt::TerminalApp::implementation
// string.
const auto tasks = _settings.GlobalSettings().ActionMap().FilterToSendInput(L""); // IVector<Model::Command>
if (const auto& strongControl{ _control.get() })
{
// TODO! this is wack. CurrentWorkingDirectory should be it's own
// property, or a property of ControlCore.DirectoryHistory() or
// something. I only have 5 minutes to pch tho so garbage will do
auto cwd = strongControl.CommandHistory().CurrentWorkingDirectory();
if (!cwd.empty())
{
auto localTasks = CascadiaSettings::ReadFile(cwd + L"\\.wt.json");
if (!localTasks.empty())
{
Command::AddLocalCommands(tasks, localTasks);
}
}
}
_allTasks = winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>();
for (const auto& t : tasks)
{
@@ -106,6 +123,7 @@ namespace winrt::TerminalApp::implementation
void TasksPaneContent::SetLastActiveControl(const Microsoft::Terminal::Control::TermControl& control)
{
_control = control;
UpdateSettings(_settings);
}
void TasksPaneContent::_runCommandButtonClicked(const Windows::Foundation::IInspectable& sender,

View File

@@ -2122,6 +2122,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
auto context = winrt::make_self<CommandHistoryContext>(std::move(commands));
context->CurrentCommandline(winrt::hstring{ _terminal->CurrentCommand() });
context->CurrentWorkingDirectory(winrt::hstring{ _terminal->GetWorkingDirectory() });
return *context;
}

View File

@@ -58,6 +58,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

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

View File

@@ -1204,6 +1204,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

@@ -106,6 +106,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

@@ -20,6 +20,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

@@ -790,4 +790,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);
if (parsed->ActionAndArgs().Action() != ShortcutAction::SendInput)
continue;
commands.Append(*parsed);
}
}
}
}

View File

@@ -71,6 +71,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

@@ -48,6 +48,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);
}
}