hackathon week is my favorite week

This is basically the complete #8797.
This commit is contained in:
Mike Griese 2021-07-29 15:14:53 -05:00
parent 84e95cf06a
commit 80a4fedc16
3 changed files with 27 additions and 12 deletions

View file

@ -836,11 +836,16 @@ namespace winrt::TerminalApp::implementation
aaa.Action(ShortcutAction::SendInput);
SendInputArgs args{ fmt::format(L"{} {}", prefix.c_str(), opt.c_str()) };
aaa.Args(args);
Command cmd{opt, aaa};
Command cmd{ opt, aaa };
actions.Append(cmd);
}
CommandPalette().SetCommands(actions);
// EnableCommandPaletteMode will make sure to trigger
// _updateFilteredActions, which we need to update the command
// list.
CommandPalette().EnableCommandPaletteMode(CommandPaletteLaunchMode::Action);
CommandPalette().Visibility(Visibility::Visible);
}
}
}

View file

@ -500,6 +500,10 @@ void AppCommandlineArgs::_buildSelectListParser()
// _newTabShort.subcommand = _app.add_subcommand("nt", RS_A(L"CmdNTDesc"));
auto setupSubcommand = [this](auto& subcommand) {
subcommand->add_option("--prefix",
_selectListPrefix,
"prefix to append to the input");
// When ParseCommand is called, if this subcommand was provided, this
// callback function will be triggered on the same thread. We can be sure
// that `this` will still be safe - this function just lets us know this
@ -528,7 +532,7 @@ void AppCommandlineArgs::_buildSelectListParser()
// lines.push_back(winrt::to_hstring{ line });
// }
auto hstringLines = winrt::single_threaded_vector<winrt::hstring>(std::move(lines));
SelectListArgs args{ L"Foo", hstringLines };
SelectListArgs args{ winrt::to_hstring(_selectListPrefix), hstringLines };
aaa.Args(args);
_startupActions.push_back(aaa);
});

View file

@ -163,19 +163,25 @@ winrt::hstring _getStdin()
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
if (hIn)
{
std::array<char, 4096> _buffer{};
std::stringstream ss;
DWORD read{};
const auto readFail{ !ReadFile(hIn, _buffer.data(), gsl::narrow_cast<DWORD>(_buffer.size()), &read, nullptr) };
if (readFail) // reading failed (we must check this first, because read will also be 0.)
do
{
const auto lastError = GetLastError();
// else we call convertUTF8ChunkToUTF16 with an empty string_view to convert possible remaining partials to U+FFFD
return winrt::hstring{};
}
std::array<char, 4096> _buffer{};
const auto readFail{ !ReadFile(hIn, _buffer.data(), gsl::narrow_cast<DWORD>(_buffer.size()), &read, nullptr) };
// reading failed (we must check this first, because read will also be 0.)
if (readFail)
{
const auto lastError = GetLastError();
return winrt::hstring{};
}
ss << std::string_view{ _buffer.data(), read };
return winrt::to_hstring(std::string_view{ _buffer.data(), read });
} while (read == 4096);
// keep reading until we don't read enough to fill the buffer. The
// subsequent read will return ERROR_BROKEN_PIPE.
return winrt::to_hstring(ss.str());
}
return winrt::hstring{};