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

Implement the FTCS_PROMPT sequence for marking the start of the prompt #13163

Merged
41 commits merged into from
Jun 9, 2022

Conversation

zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented May 24, 2022

Implements the FTCS_PROMPT sequence, OSC 133 ; A ST. In this PR, it's just used to set a simple Prompt mark on the current line, in the same way that the iTerm2 sequence works.

There's rumination in #11000 on how to implement the rest of the FTCS sequences.

This is broken into its own PR at the moment. Quoth j4james:

That should be just as easy, and I've noticed a couple of other terminals that are doing that, so it's not unprecedented. If we don't have any immediate use for the other options, there shouldn't be any harm in ignoring them initially.

And the benefit of going with the more widely supported sequence is that we're more likely to benefit from any shells that have this functionality built in. Otherwise they're forced to try and detect the terminal, which is practically impossible for Windows Terminal. Even iTerm2 supports the OSC 133 sequence, so we'd probably be the only odd one out.

This part of the plumbing is super easy, so I thought it would be valuable to add regardless if we get to the whole of FTCS in 1.15.

  • I work here
  • Tested manually - in my pwsh $PROFILE:
    function prompt {
      $loc = $($executionContext.SessionState.Path.CurrentLocation);
      $out = "PS $loc$('>' * ($nestedPromptLevel + 1)) ";
      $out += "$([char]27)]9;9;`"$loc`"$([char]07)";
      $out += "$([char]27)]133;A;$([char]7)"; # add the FTCS_PROMPT to the... well, end, but you get the point
      return $out
    }
  • See also megathread: Scrollbar Marks #11000

@github-actions

This comment was marked as resolved.

return false;
}

const auto action{ parts[0] };
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe this code requires a string copy. This avoids one:

Suggested change
const auto action{ parts[0] };
const auto& action = parts[0];

Copy link
Member

@DHowett DHowett May 25, 2022

Choose a reason for hiding this comment

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

I see you prefer he not use the uniform initialization syntax (since you switched it to =) 😉

Suggested change
const auto action{ parts[0] };
const auto& action{ parts[0] };

I had to read the rules about const auto& locals and how they extend lifetime -- I still think it's a bad pattern to encourage, but we use it all over the place \_(shrug)_/

Copy link
Member

@lhecker lhecker May 25, 2022

Choose a reason for hiding this comment

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

I see you prefer he not use the uniform initialization syntax (since you switched it to =) 😉

The rest of the file uses classic = assignments. I like consistency. 👉👈

Of course you probably already figured out my deepest secret that - entirely unrelated to this - I personally kinda dislike the uniform initialization syntax. 😅 This is what I write:

auto bar = bar_producer();  // good
auto bar{ bar_producer() }; // "bad"
Foo foo{ bar };             // good

Isn't the uniform initialization syntax nothing but a bolted on language hack, because people were afraid of breaking existing code by making round brackets better? I use it because it's very useful, but would you write this if it was an equivalent thing?

auto bar(bar_producer());

I wouldn't and so I don't use curly brackets either, because I consider curly brackets stricter round brackets. In my mind I'm not constructing an object there, I'm assigning an unnamed rvalue a name via variable assignment. And so I write auto result = foo().

I had to read the rules about const auto& locals and how they extend lifetime -- I still think it's a bad pattern to encourage, but we use it all over the place \_(shrug)_/

I think about it differently: Here we "bind to the memory address" of the first item in an array.

Copy link
Member Author

Choose a reason for hiding this comment

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

ultimately, Audit will complain:

error C26445: Do not assign gsl::span or std::string_view to a reference. They are cheap to construct and are not owners of the underlying data.

so, const auto action = ... it is

Copy link
Member

Choose a reason for hiding this comment

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

error C26445: Do not assign gsl::span or std::string_view to a reference.

But passing it as a by-reference argument is fine? smh

Copy link
Member

Choose a reason for hiding this comment

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

I guess the underlying point is: this is not a string copy, it's a string_view copy ;)

@zadjii-msft zadjii-msft added this to the Terminal v1.15 milestone Jun 9, 2022
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.

Minor nits

@DHowett
Copy link
Member

DHowett commented Jun 9, 2022

My nits are just comment changes? Huh.

Base automatically changed from dev/migrie/f/1527-experimental-marks to main June 9, 2022 21:10
@zadjii-msft zadjii-msft added Area-VT Virtual Terminal sequence support Product-Terminal The new Windows Terminal. 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. labels Jun 9, 2022
@ghost
Copy link

ghost commented Jun 9, 2022

Hello @zadjii-msft!

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 f685720 into main Jun 9, 2022
@ghost ghost deleted the dev/migrie/f/11000-FTCS-simple branch June 9, 2022 22:42
@zadjii-msft zadjii-msft mentioned this pull request Jun 10, 2022
37 tasks
@ghost
Copy link

ghost commented Jul 6, 2022

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

Handy links:

@TBBle
Copy link

TBBle commented Jul 23, 2022

Quick note since this is currently the Windows Terminal bug-tracker example for adding FTCS_PROMPT to one's shell: It seems from the diagram in #11000 and the iTerm docs, that FTCS_PROMPT should be at the start of the prompt.

There also seems to be an extraneous ; after A in the test example. The docs give OSC 133 ; A ST, although I'm having trouble getting it going either way, debug tap shows ␛]133;A␛\ and I have experimental.showMarksOnScrollbar set in my top-level settings.json, but I can't seem to see any actual effect. So I don't know if that extraneous ; is a problem (I added it and it didn't help, so I don't have a known-good state to experiment from).

Edit: I did eventually get it working ("experimental.showMarksOnScrollbar": true in my default profile, I'm sure I'd tried that before... I also added FTCS_COMMAND_START to my prompt, but it still worked after I removed that again) and confirmed it works with and without the extraneous ;, i.e. ␛]133;A;␛\ does also work. (whether it should is an OSC-parser question).

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-VT Virtual Terminal sequence support 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. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants