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

Move commandline->title promotion into TerminalSettings #11029

Merged
1 commit merged into from
Aug 24, 2021

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented Aug 24, 2021

It was insufficient to only promote commandline components to titles
during commandline parsing, because we also have a whole complement of
actions that contain NewTerminalArgs. The tests caught me out a little
too late (sorry!). I decided it was better move promotion down to
TerminalSettings.

Fixes #6776
Re-implements #10998

It was insufficient to only promote commandline components to titles
during commandline parsing, because we also have a whole complement of
actions that contain NewTerminalArgs. The tests caught me out a little
too late (sorry!). I decided it was better move promotion down to
TerminalSettings.

Fixes #6776.
@ghost ghost added Area-Commandline wt.exe's commandline arguments Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. labels Aug 24, 2021
Comment on lines +135 to +137
const auto start{ til::at(commandLine, 0) == L'"' ? 1 : 0 };
const auto terminator{ commandLine.find_first_of(start ? L'"' : L' ', start) }; // look past the first character if it starts with "
// We have to take a copy here; winrt::param::hstring requires a null-terminated string
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is rough but it works. doing a substr with npos-x later is safe (confirmed by docs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it yields a title of nothing, we already have a weird commandline. If the title is too long, oh well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this? winrt::param::hstring has an explicit std::wstring_view constructor and appears to work just fine with it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead sure. This blog post just came out today to reinforce: https://devblogs.microsoft.com/oldnewthing/20210823-00/?p=105598

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shocked

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh.

@DHowett DHowett added the Needs-Second It's a PR that needs another sign-off label Aug 24, 2021
@lhecker
Copy link
Member

lhecker commented Aug 24, 2021

Also, while it's less efficient, I think we should introduce til::trim_prefix/suffix functions...
It's easy to implement with existing functions:

template<typename T, typename Traits>
constexpr std::basic_string_view<T, Traits> trim_prefix(const std::basic_string_view<T, Traits>& str, const std::basic_string_view<T, Traits>& prefix) noexcept
{
#pragma warning(suppress : 26481) // Don't use pointer arithmetic. Use span instead
	return starts_with(str, prefix) ? std::basic_string_view<T, Traits>{ str.data() + prefix.size(), str.size() - prefix.size() } : str;
}

constexpr std::string_view trim_prefix(const std::string_view& str, const std::string_view& prefix) noexcept
{
	return trim_prefix<>(str, prefix);
}

constexpr std::wstring_view trim_prefix(const std::wstring_view& str, const std::wstring_view& prefix) noexcept
{
	return trim_prefix<>(str, prefix);
}

template<typename T, typename Traits>
constexpr std::basic_string_view<T, Traits> trim_suffix(const std::basic_string_view<T, Traits>& str, const std::basic_string_view<T, Traits>& suffix) noexcept
{
#pragma warning(suppress : 26481) // Don't use pointer arithmetic. Use span instead
	return ends_with(str, suffix) ? std::basic_string_view<T, Traits>{ str.data(), str.size() - prefix.size() } : str;
}

constexpr std::string_view trim_suffix(const std::string_view& str, const std::string_view& suffix) noexcept
{
	return trim_prefix<>(str, suffix);
}

constexpr std::wstring_view trim_suffix(const std::wstring_view& str, const std::wstring_view& suffix) noexcept
{
	return trim_prefix<>(str, suffix);
}

// ...

const auto firstComponent = til::trim_suffix(til::trim_prefix(commandLine, L'"'), L'"');

@DHowett
Copy link
Member Author

DHowett commented Aug 24, 2021

That doesn't do the same thing as this, though. This converts "foo" bar into just foo 😄

@DHowett
Copy link
Member Author

DHowett commented Aug 24, 2021

@msftbot merge this in 2 minutes

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

ghost commented Aug 24, 2021

Hello @DHowett!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I won't merge this pull request until after the UTC date Tue, 24 Aug 2021 23:30:42 GMT, which is in 2 minutes

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@ghost ghost merged commit 7b6df26 into main Aug 24, 2021
@ghost ghost deleted the dev/duhowett/try-promotion-again branch August 24, 2021 23:31
@ghost
Copy link

ghost commented Aug 31, 2021

🎉Windows Terminal Preview v1.11.2421.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-Bug It either shouldn't be doing this or needs an investigation. Needs-Second It's a PR that needs another sign-off Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
3 participants