Skip to content

Move commandline->title promotion into TerminalSettings - #11029

Merged
1 commit merged into
mainfrom
dev/duhowett/try-promotion-again
Aug 24, 2021
Merged

1 commit merged into
mainfrom
dev/duhowett/try-promotion-again

Conversation

@DHowett

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shocked

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Uh oh.

@lhecker

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

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

@DHowett

Copy link
Copy Markdown
Member Author

@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
Copy Markdown

Hello Dustin L. Howett (@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
Copy Markdown

🎉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

Development

Successfully merging this pull request may close these issues.

Windows/tabs created with "wt new-tab COMMAND" start with the title of the default Terminal profile, not the COMMAND name

3 participants