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 support for naming windows with the -w
parameter
#9300
Conversation
The history of this had gotten way, way too long. It included everything since I started working on this
(cherry picked from commit fa26f7f)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought (for after this PR), what if we had window names appear as the window titles? That'd be kinda neat.
Most of my comments are small things, honestly.
Testing- can I leave comments? Michael can't. |
@@ -1595,58 +1595,129 @@ namespace TerminalAppLocalTests | |||
{ | |||
{ | |||
std::vector<winrt::hstring> args{ L"wt.exe" }; | |||
VERIFY_ARE_EQUAL(WindowingBehaviorUseNew, | |||
appImpl::AppLogic::_doFindTargetWindow({ args }, WindowingMode::UseNew)); | |||
auto result = appImpl::AppLogic::_doFindTargetWindow({ args }, WindowingMode::UseNew); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful to a future debugger to leave either a general comment or a Log
comment per block here as to the general gist of each test section.
try | ||
{ | ||
auto otherName = p.WindowName(); | ||
if (otherName == name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case sensitive compare? Are you sure? Lots of people love to be lazy on the capitalization when doing a command line thing and I suspect that might apply to -w
.
src/cascadia/Remoting/Monarch.cpp
Outdated
if (auto targetPeasant{ _getPeasant(windowID) }) | ||
{ | ||
auto result{ winrt::make_self<Remoting::implementation::ProposeCommandlineResult>(false) }; | ||
|
||
result->WindowName(targetWindowName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. We look up the ID from the name, and then .. tell it that the window name is the name we got the ID from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh. I suppose that only really applies in the "we failed to propose the commandline, make a new window instead" case. I'll add a test
if (parsedTarget == "new") | ||
{ | ||
return winrt::make<FindTargetWindowResult>(WindowingBehaviorUseNew); | ||
} | ||
else if (parsedTarget == "last") | ||
{ | ||
return winrt::make<FindTargetWindowResult>(WindowingBehaviorUseExisting); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we lift these somewhere, or map them somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we reserve _
names here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh like, just always return UseNew for those? That's an interesting idea - I was figuring we wouldn't do anything special for now, and just document "We reserve the right to use names starting with _ for whatever we want in the future. Don't use '_' as the first character of a window name in any scripts"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, idc. Just a thought.
// to remove 1 while looking for "two". Technically, we shouldn't be | ||
// relying on any sort of ordering for an unordered_map iterator, but | ||
// this one just so happens to work. | ||
VERIFY_ARE_EQUAL(p2->GetID(), m0->_lookupPeasantIdForName(L"two")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'd rather we search for one
-- that will guarantee that we trip over its corpse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, the point of this test is to check if looking for a peasant that's still alive correctly prunes the dead peasant. LookupNamedPeasantWhenItDied
does exactly what you're looking for 😉
constexpr int32_t WindowingBehaviorUseNew{ -1 }; | ||
constexpr int32_t WindowingBehaviorUseExisting{ -2 }; | ||
constexpr int32_t WindowingBehaviorUseAnyExisting{ -3 }; | ||
constexpr int32_t WindowingBehaviorUseName{ -4 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scary! What if they pass -w -4
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, for negative numbers, we figure out that it's a number, then clamp the number to [-1, INT_MAX], then return it, so we never parse -4
as a string
…dows-3 # Conflicts: # src/cascadia/Remoting/FindTargetWindowArgs.h # src/cascadia/Remoting/ProposeCommandlineResult.h
add a test, and add liberal comments.
void RemotingTests::_findTargetWindowByNameHelper(const winrt::Windows::Foundation::IInspectable& /*sender*/, | ||
const winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs& args) | ||
{ | ||
const auto arguments = args.Args().Commandline(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the args' args' args, we store in arguments. Not a nit, just a fun read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nailed my concerns down and then some. Thanks!
Hello @DHowett! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
## Summary of the Pull Request This is a follow up to #9300. Now that we have names on our windows, it would be nice to see who is named what. So this adds two actions: * `identifyWindow`: This action will pop up a little toast (#8592) displaying the name and ID of the window, and is bound by default. ![identify-window-toast-000](https://user-images.githubusercontent.com/18356694/111529085-bf710580-872f-11eb-8880-b0b617596cfc.gif) * `identifyWindows`: This action will request that ALL windows pop up that toast. This is meant to feel like the "Identify" button on the Windows display settings. However, sometimes, it's wonky. ![teaching-tip-dismiss-001](https://user-images.githubusercontent.com/18356694/111529292-fe06c000-872f-11eb-8d4a-5688e4ce1175.gif) That's being tracked upstream on microsoft/microsoft-ui-xaml#4382 Because it's so wonky, we won't bind that by default. Maybe if we get that fixed, then we'll change the default binding from `identifyWindow` to `identifyWindows` ## References ## PR Checklist * [x] Closes https://github.com/microsoft/terminal/projects/5#card-51431492 * [x] I work here * [x] Tests added/passed * [ ] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments You may note that there are some macros to make interacting with lots and lots of actions easier. There's a lot of boilerplate whenever you need to make a new action, so I thought: "Can we make that easier?" Turns out you can make it a _LOT_ easier, but that work is still behind another PR after this one. Get excited
🎉 Handy links: |
🎉 Handy links: |
This finishes the implementation of
--window
to also accept a stringas the "name" of the window. So you can say
and have both those commands execute in the same window, the one named
"foo". This is just slightly more ergonomic than manually using the IDs
of windows. In the future, I'll be working on renaming windows, and
displaying these names.
Before this PR, I think we didn't actually properly support assigning
the id with
wt -w 12345
. If12345
didn't exist, it would make a newwindow, but just assign it the next id, not assign it 12345.
References
Validation Steps Performed
Ran tests
Messed with naming windows, working as expected.
Closes https://github.com/microsoft/terminal/projects/5#card-51431478