[PR #14341] [MERGED] Implement the rest of the FTCS marks #30056

Open
opened 2026-01-31 09:38:24 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/14341
Author: @zadjii-msft
Created: 11/4/2022
Status: Merged
Merged: 12/1/2022
Merged by: @undefined

Base: mainHead: dev/migrie/f/11000-more-ftcs-marks


📝 Commits (10+)

  • 58b5d99 I think this is all the FTCS marks from dev/migrie/fhl/more-shell-integration
  • 63ffcc0 clarify notes
  • f1a96c4 scrolling is important
  • a1b9dac notes
  • a3ede80 Merge remote-tracking branch 'origin/main' into dev/migrie/f/11000-more-ftcs-marks
  • b3c523c Merge remote-tracking branch 'origin/main' into dev/migrie/f/11000-more-ftcs-marks
  • b02d222 nits, not the hard stuff
  • 43875fd commit before I get to demolition
  • 609e354 this is more resilient
  • 2317192 cleanup

📊 Changes

10 files changed (+243 additions, -29 deletions)

View changed files

📝 src/cascadia/TerminalControl/ControlCore.cpp (+1 -1)
📝 src/cascadia/TerminalCore/Terminal.cpp (+45 -11)
📝 src/cascadia/TerminalCore/Terminal.hpp (+14 -2)
📝 src/cascadia/TerminalCore/TerminalApi.cpp (+96 -2)
📝 src/host/outputStream.cpp (+16 -1)
📝 src/host/outputStream.hpp (+4 -1)
📝 src/terminal/adapter/DispatchTypes.hpp (+3 -0)
📝 src/terminal/adapter/ITerminalApi.hpp (+4 -1)
📝 src/terminal/adapter/adaptDispatch.cpp (+46 -8)
📝 src/terminal/adapter/ut_adapter/adapterTest.cpp (+14 -2)

📄 Description

As noted in #11000.

This adds support for FTCS_COMMAND_START, FTCS_COMMAND_EXECUTED and FTCS_COMMAND_FINISHED, which allow a shell to more clearly markup parts of the buffer.

As a trick, I'm also making the experimental.autoMarkPrompts setting act like a FTCS_COMMAND_EXECUTED if it comes after a FTCS_COMMAND_START. This lets the whole sequence work for cmd.exe (which wouldn't otherwise be possible).

  • My cmd prompt

    PROMPT $e]133;D$e\$e]133;A$e\$e]9;9;$P$e\[$T]$e[97;46m%_seperator%$P$e[36;49m%_seperator%$e[0m$_$e[0m%_GITPROMPT%$e[94m%username%$e[0m@$e[32m%computername%$e[0m$G$e]133;B$e\
    
  • pwsh profile, heavily cribbed from vscode

    
      $Global:__LastHistoryId = -1
    
      function Global:__Terminal-Get-LastExitCode {
        if ($? -eq $True) {
          return 0
        }
        # TODO: Should we just return a string instead?
        # return -1
        if ("$LastExitCode" -ne "") { return $LastExitCode }
        return -1
      }
    
      function prompt {
        # $gle = $LastExitCode
    
    
        $gle = $(__Terminal-Get-LastExitCode);
        $LastHistoryEntry = $(Get-History -Count 1)
        # Skip finishing the command if the first command has not yet started
        if ($Global:__LastHistoryId -ne -1) {
          if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
            # Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
            $out += "`e]133;D`a"
          } else {
            # Command finished exit code
            # OSC 633 ; D [; <ExitCode>] ST
            $out += "`e]133;D;$gle`a"
          }
        }
    
    
        $loc = $($executionContext.SessionState.Path.CurrentLocation);
        # IMPORTANT: Make sure there's a printable charater _last_ in the prompt.
        # Otherwise, PSReadline is gonna use the terminating `\` here and colorize
        # that if it detects a syntax error
        $out += "`e]133;A$([char]07)";
        $out += "`e]9;9;`"$loc`"$([char]07)";
        $out += "PWSH $loc$('>' * ($nestedPromptLevel + 1)) ";
        $out += "`e]133;B$([char]07)";
    
        $Global:__LastHistoryId = $LastHistoryEntry.Id
    
        return $out
      }
    
  • Doesn't close any issues, because this was always just an element in #11000

  • I work here

  • From FHL code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/14341 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 11/4/2022 **Status:** ✅ Merged **Merged:** 12/1/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/migrie/f/11000-more-ftcs-marks` --- ### 📝 Commits (10+) - [`58b5d99`](https://github.com/microsoft/terminal/commit/58b5d99c9be8297e6e287b8e3b1055be99d8357e) I think this is all the FTCS marks from `dev/migrie/fhl/more-shell-integration` - [`63ffcc0`](https://github.com/microsoft/terminal/commit/63ffcc044b9fdd1f21bc942e67bd4320060c3f4b) clarify notes - [`f1a96c4`](https://github.com/microsoft/terminal/commit/f1a96c4cb5f7855b68c748a25d666a6c5ebf2528) scrolling is important - [`a1b9dac`](https://github.com/microsoft/terminal/commit/a1b9dac49cf050aa6ae7309c168cf87299420699) notes - [`a3ede80`](https://github.com/microsoft/terminal/commit/a3ede801e613f7ca5b612f3fe33d02e941118442) Merge remote-tracking branch 'origin/main' into dev/migrie/f/11000-more-ftcs-marks - [`b3c523c`](https://github.com/microsoft/terminal/commit/b3c523c7678f80d1921579d2be1b4d82f55f0d2c) Merge remote-tracking branch 'origin/main' into dev/migrie/f/11000-more-ftcs-marks - [`b02d222`](https://github.com/microsoft/terminal/commit/b02d222e89ab97b022bb91745fd9b4b367cebc54) nits, not the hard stuff - [`43875fd`](https://github.com/microsoft/terminal/commit/43875fdb52d45b60e6910396994e1c2f0f2ff11d) commit before I get to demolition - [`609e354`](https://github.com/microsoft/terminal/commit/609e354a21f13c4041709222211e1dac38b23be5) this is more resilient - [`2317192`](https://github.com/microsoft/terminal/commit/23171926fdba0b05798e130c11a24baac3dde9a9) cleanup ### 📊 Changes **10 files changed** (+243 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalControl/ControlCore.cpp` (+1 -1) 📝 `src/cascadia/TerminalCore/Terminal.cpp` (+45 -11) 📝 `src/cascadia/TerminalCore/Terminal.hpp` (+14 -2) 📝 `src/cascadia/TerminalCore/TerminalApi.cpp` (+96 -2) 📝 `src/host/outputStream.cpp` (+16 -1) 📝 `src/host/outputStream.hpp` (+4 -1) 📝 `src/terminal/adapter/DispatchTypes.hpp` (+3 -0) 📝 `src/terminal/adapter/ITerminalApi.hpp` (+4 -1) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+46 -8) 📝 `src/terminal/adapter/ut_adapter/adapterTest.cpp` (+14 -2) </details> ### 📄 Description As noted in #11000. This adds support for `FTCS_COMMAND_START`, `FTCS_COMMAND_EXECUTED` and `FTCS_COMMAND_FINISHED`, which allow a shell to more clearly markup parts of the buffer. As a trick, I'm also making the `experimental.autoMarkPrompts` setting act like a `FTCS_COMMAND_EXECUTED` if it comes after a `FTCS_COMMAND_START`. This lets the whole sequence work for cmd.exe (which wouldn't otherwise be possible). * My cmd prompt ```bat PROMPT $e]133;D$e\$e]133;A$e\$e]9;9;$P$e\[$T]$e[97;46m%_seperator%$P$e[36;49m%_seperator%$e[0m$_$e[0m%_GITPROMPT%$e[94m%username%$e[0m@$e[32m%computername%$e[0m$G$e]133;B$e\ ``` * pwsh profile, heavily cribbed from vscode ```pwsh $Global:__LastHistoryId = -1 function Global:__Terminal-Get-LastExitCode { if ($? -eq $True) { return 0 } # TODO: Should we just return a string instead? # return -1 if ("$LastExitCode" -ne "") { return $LastExitCode } return -1 } function prompt { # $gle = $LastExitCode $gle = $(__Terminal-Get-LastExitCode); $LastHistoryEntry = $(Get-History -Count 1) # Skip finishing the command if the first command has not yet started if ($Global:__LastHistoryId -ne -1) { if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) { # Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command) $out += "`e]133;D`a" } else { # Command finished exit code # OSC 633 ; D [; <ExitCode>] ST $out += "`e]133;D;$gle`a" } } $loc = $($executionContext.SessionState.Path.CurrentLocation); # IMPORTANT: Make sure there's a printable charater _last_ in the prompt. # Otherwise, PSReadline is gonna use the terminating `\` here and colorize # that if it detects a syntax error $out += "`e]133;A$([char]07)"; $out += "`e]9;9;`"$loc`"$([char]07)"; $out += "PWSH $loc$('>' * ($nestedPromptLevel + 1)) "; $out += "`e]133;B$([char]07)"; $Global:__LastHistoryId = $LastHistoryEntry.Id return $out } ``` * Doesn't close any issues, because this was always just an element in #11000 * I work here * From FHL code --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:38:24 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30056