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 support for naming windows with the -w parameter #9300

Merged
11 commits merged into from Mar 17, 2021

Conversation

zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Feb 26, 2021

This finishes the implementation of --window to also accept a string
as the "name" of the window. So you can say

wt -w foo new-tab
wt -w foo split-pane

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.

--window,-w <window-id>

Run these commands in the given Windows Terminal session. This enables opening
new tabs, splits, etc. in already running Windows Terminal windows.

  • If window-id is 0, run the given commands in the current window.
  • If window-id is a negative number, or the reserved name new, run the
    commands in a new Terminal window.
  • If window-id is the ID or name of an existing window, then run the
    commandline in that window.
  • If window-id is not the ID or name of an existing window, create a new
    window. That window will be assigned the ID or name provided in the
    commandline. The provided subcommands will be run in that new window.
  • If window-id is omitted, then obey the value of windowingBehavior when
    determining which window to run the command in.

Before this PR, I think we didn't actually properly support assigning
the id with wt -w 12345. If 12345 didn't exist, it would make a new
window, 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

  The history of this had gotten way, way too long. It included everything since I started working on this
@zadjii-msft zadjii-msft added Area-Commandline wt.exe's commandline arguments Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Feb 26, 2021
@zadjii-msft zadjii-msft added this to the Terminal v1.8 milestone Feb 26, 2021
(cherry picked from commit fa26f7f)
Copy link
Member

@carlos-zamora carlos-zamora left a 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.

src/cascadia/TerminalApp/AppLogic.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppLogic.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppLogic.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppCommandlineArgs.cpp Outdated Show resolved Hide resolved
src/cascadia/Remoting/WindowManager.cpp Outdated Show resolved Hide resolved
src/cascadia/Remoting/WindowManager.cpp Outdated Show resolved Hide resolved
@zadjii-msft zadjii-msft self-assigned this Mar 3, 2021
@zadjii-msft zadjii-msft removed their assignment Mar 4, 2021
@zadjii-msft zadjii-msft added the Needs-Second It's a PR that needs another sign-off label Mar 4, 2021
@ghost ghost requested review from miniksa, DHowett, leonMSFT and PankajBhojwani March 4, 2021 15:19
@DHowett
Copy link
Member

DHowett commented Mar 12, 2021

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);
Copy link
Member

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)
Copy link
Member

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 Show resolved Hide resolved
src/cascadia/Remoting/FindTargetWindowArgs.h Outdated Show resolved Hide resolved
src/cascadia/Remoting/Monarch.cpp Outdated Show resolved Hide resolved
src/cascadia/Remoting/Monarch.cpp Outdated Show resolved Hide resolved
src/cascadia/Remoting/Monarch.cpp Outdated Show resolved Hide resolved
Comment on lines 504 to 507
if (auto targetPeasant{ _getPeasant(windowID) })
{
auto result{ winrt::make_self<Remoting::implementation::ProposeCommandlineResult>(false) };

result->WindowName(targetWindowName);
Copy link
Member

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?

Copy link
Member Author

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

src/cascadia/TerminalApp/AppCommandlineArgs.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppCommandlineArgs.cpp Outdated Show resolved Hide resolved
Comment on lines +1293 to +1300
if (parsedTarget == "new")
{
return winrt::make<FindTargetWindowResult>(WindowingBehaviorUseNew);
}
else if (parsedTarget == "last")
{
return winrt::make<FindTargetWindowResult>(WindowingBehaviorUseExisting);
}
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member Author

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"

Copy link
Member

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"));
Copy link
Member

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.

Copy link
Member Author

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 };
Copy link
Member

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?

Copy link
Member Author

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

@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Mar 15, 2021
…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();
Copy link
Member

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.

Copy link
Member

@DHowett DHowett left a 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!

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Mar 17, 2021
@ghost
Copy link

ghost commented Mar 17, 2021

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

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 (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 43c469f into main Mar 17, 2021
@ghost ghost deleted the dev/migrie/f/name-windows-3 branch March 17, 2021 19:28
ghost pushed a commit that referenced this pull request Mar 30, 2021
## 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
@ghost
Copy link

ghost commented Apr 14, 2021

🎉Windows Terminal Preview v1.8.1032.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented May 25, 2021

🎉Windows Terminal v1.8.1444.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Commandline wt.exe's commandline arguments AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Second It's a PR that needs another sign-off Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants