mirror of
https://github.com/microsoft/terminal.git
synced 2026-04-07 06:39:44 +00:00
Merge branch 'dev/migrie/fhl/non-terminal-panes-2023' into dev/migrie/fhl/scratchpad-pane
This commit is contained in:
2
.github/actions/spelling/allow/allow.txt
vendored
2
.github/actions/spelling/allow/allow.txt
vendored
@@ -13,6 +13,7 @@ clickable
|
||||
clig
|
||||
CMMI
|
||||
copyable
|
||||
Counterintuitively
|
||||
CtrlDToClose
|
||||
cybersecurity
|
||||
dalet
|
||||
@@ -94,6 +95,7 @@ shcha
|
||||
slnt
|
||||
Sos
|
||||
ssh
|
||||
sustainability
|
||||
stakeholders
|
||||
sxn
|
||||
timeline
|
||||
|
||||
4
.github/actions/spelling/allow/apis.txt
vendored
4
.github/actions/spelling/allow/apis.txt
vendored
@@ -28,6 +28,7 @@ CYICON
|
||||
Dacl
|
||||
dataobject
|
||||
dcomp
|
||||
debugbreak
|
||||
delayimp
|
||||
DERR
|
||||
dlldata
|
||||
@@ -219,16 +220,19 @@ UFIELD
|
||||
ULARGE
|
||||
UOI
|
||||
UPDATEINIFILE
|
||||
urlmon
|
||||
userenv
|
||||
USEROBJECTFLAGS
|
||||
Vcpp
|
||||
Viewbox
|
||||
virtualalloc
|
||||
vsnwprintf
|
||||
wcsnlen
|
||||
wcsstr
|
||||
wcstoui
|
||||
WDJ
|
||||
winhttp
|
||||
wininet
|
||||
winmain
|
||||
winsta
|
||||
winstamin
|
||||
|
||||
4
.github/actions/spelling/allow/microsoft.txt
vendored
4
.github/actions/spelling/allow/microsoft.txt
vendored
@@ -4,6 +4,7 @@ advapi
|
||||
altform
|
||||
altforms
|
||||
appendwttlogging
|
||||
appinstaller
|
||||
appx
|
||||
appxbundle
|
||||
appxerror
|
||||
@@ -59,12 +60,13 @@ PRIINFO
|
||||
propkey
|
||||
pscustomobject
|
||||
QWORD
|
||||
rdpclip
|
||||
regedit
|
||||
resfiles
|
||||
robocopy
|
||||
SACLs
|
||||
segoe
|
||||
sdkddkver
|
||||
segoe
|
||||
Shobjidl
|
||||
sid
|
||||
Skype
|
||||
|
||||
11
.github/actions/spelling/expect/expect.txt
vendored
11
.github/actions/spelling/expect/expect.txt
vendored
@@ -188,8 +188,10 @@ changelist
|
||||
chaof
|
||||
charinfo
|
||||
CHARSETINFO
|
||||
chcbpat
|
||||
chh
|
||||
chk
|
||||
chshdng
|
||||
CHT
|
||||
Cic
|
||||
cielab
|
||||
@@ -749,7 +751,6 @@ gfx
|
||||
GGI
|
||||
GHIJK
|
||||
GHIJKL
|
||||
GHIJKLM
|
||||
gitfilters
|
||||
gitmodules
|
||||
gle
|
||||
@@ -1000,7 +1001,6 @@ listptrsize
|
||||
lld
|
||||
llx
|
||||
LMENU
|
||||
LMNOP
|
||||
lnk
|
||||
lnkd
|
||||
lnkfile
|
||||
@@ -1223,7 +1223,6 @@ nonspace
|
||||
NOOWNERZORDER
|
||||
Nop
|
||||
NOPAINT
|
||||
NOPQRST
|
||||
noprofile
|
||||
NOREDRAW
|
||||
NOREMOVE
|
||||
@@ -1498,7 +1497,6 @@ pwsz
|
||||
pythonw
|
||||
Qaabbcc
|
||||
qos
|
||||
QRSTU
|
||||
QUERYOPEN
|
||||
QUESTIONMARK
|
||||
quickedit
|
||||
@@ -1861,7 +1859,6 @@ testname
|
||||
TESTNULL
|
||||
testpass
|
||||
testpasses
|
||||
testtimeout
|
||||
TEXCOORD
|
||||
texel
|
||||
TExpected
|
||||
@@ -1908,6 +1905,7 @@ touchpad
|
||||
Tpp
|
||||
Tpqrst
|
||||
tprivapi
|
||||
tput
|
||||
tracelog
|
||||
tracelogging
|
||||
traceloggingprovider
|
||||
@@ -2018,7 +2016,6 @@ utext
|
||||
UText
|
||||
UTEXT
|
||||
utr
|
||||
UVWX
|
||||
UVWXY
|
||||
UVWXYZ
|
||||
uwa
|
||||
@@ -2077,7 +2074,6 @@ VTRGBTo
|
||||
vtseq
|
||||
vtterm
|
||||
vttest
|
||||
VWX
|
||||
waitable
|
||||
WANSUNG
|
||||
WANTARROWS
|
||||
@@ -2273,6 +2269,7 @@ YCast
|
||||
YCENTER
|
||||
YCount
|
||||
YDPI
|
||||
YLimit
|
||||
YOffset
|
||||
YSubstantial
|
||||
YVIRTUALSCREEN
|
||||
|
||||
@@ -239,8 +239,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{89CDCC
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Types.Unit.Tests", "src\types\ut_types\Types.Unit.Tests.vcxproj", "{34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PublicTerminalCore", "src\cascadia\PublicTerminalCore\PublicTerminalCore.vcxproj", "{84848BFA-931D-42CE-9ADF-01EE54DE7890}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfTerminalControl", "src\cascadia\WpfTerminalControl\WpfTerminalControl.csproj", "{376FE273-6B84-4EB5-8B30-8DE9D21B022C}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests_TerminalApp", "src\cascadia\ut_app\TerminalApp.UnitTests.vcxproj", "{CA5CAD1A-9333-4D05-B12A-1905CBF112F9}"
|
||||
@@ -334,7 +332,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmt", "src\dep\fmt\fmt.vcxp
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfTerminalTestNetCore", "src\cascadia\WpfTerminalTestNetCore\WpfTerminalTestNetCore.csproj", "{1588FD7C-241E-4E7D-9113-43735F3E6BAD}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890} = {84848BFA-931D-42CE-9ADF-01EE54DE7890}
|
||||
{CA5CAD1A-F542-4635-A069-7CAEFB930070} = {CA5CAD1A-F542-4635-A069-7CAEFB930070}
|
||||
{A22EC5F6-7851-4B88-AC52-47249D437A52} = {A22EC5F6-7851-4B88-AC52-47249D437A52}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
@@ -1711,34 +1709,6 @@ Global
|
||||
{34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.Release|x64.Build.0 = Release|x64
|
||||
{34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.Release|x86.ActiveCfg = Release|Win32
|
||||
{34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.Release|x86.Build.0 = Release|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.AuditMode|Any CPU.ActiveCfg = AuditMode|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.AuditMode|ARM.ActiveCfg = AuditMode|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.AuditMode|x64.ActiveCfg = AuditMode|x64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.AuditMode|x64.Build.0 = AuditMode|x64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.AuditMode|x86.ActiveCfg = AuditMode|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.AuditMode|x86.Build.0 = AuditMode|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Debug|ARM.ActiveCfg = Debug|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Debug|x64.Build.0 = Debug|x64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Debug|x86.Build.0 = Debug|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Fuzzing|Any CPU.ActiveCfg = Fuzzing|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Fuzzing|ARM.ActiveCfg = Fuzzing|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Fuzzing|ARM64.ActiveCfg = Fuzzing|ARM64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Fuzzing|x64.ActiveCfg = Fuzzing|x64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Fuzzing|x86.ActiveCfg = Fuzzing|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Release|Any CPU.ActiveCfg = Release|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Release|ARM.ActiveCfg = Release|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Release|x64.ActiveCfg = Release|x64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Release|x64.Build.0 = Release|x64
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Release|x86.ActiveCfg = Release|Win32
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890}.Release|x86.Build.0 = Release|Win32
|
||||
{376FE273-6B84-4EB5-8B30-8DE9D21B022C}.AuditMode|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{376FE273-6B84-4EB5-8B30-8DE9D21B022C}.AuditMode|ARM.ActiveCfg = Debug|Any CPU
|
||||
{376FE273-6B84-4EB5-8B30-8DE9D21B022C}.AuditMode|ARM.Build.0 = Debug|Any CPU
|
||||
@@ -2894,7 +2864,6 @@ Global
|
||||
{05500DEF-2294-41E3-AF9A-24E580B82836} = {89CDCC5C-9F53-4054-97A4-639D99F169CD}
|
||||
{1E4A062E-293B-4817-B20D-BF16B979E350} = {89CDCC5C-9F53-4054-97A4-639D99F169CD}
|
||||
{34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73} = {89CDCC5C-9F53-4054-97A4-639D99F169CD}
|
||||
{84848BFA-931D-42CE-9ADF-01EE54DE7890} = {4DAF0299-495E-4CD1-A982-9BAC16A45932}
|
||||
{376FE273-6B84-4EB5-8B30-8DE9D21B022C} = {4DAF0299-495E-4CD1-A982-9BAC16A45932}
|
||||
{CA5CAD1A-9333-4D05-B12A-1905CBF112F9} = {BDB237B6-1D1D-400F-84CC-40A58FA59C8E}
|
||||
{CA5CAD1A-9A12-429C-B551-8562EC954746} = {59840756-302F-44DF-AA47-441A9D673202}
|
||||
|
||||
24
README.md
24
README.md
@@ -1,4 +1,4 @@
|
||||

|
||||

|
||||
|
||||
# Welcome to the Windows Terminal, Console and Command-Line repo
|
||||
|
||||
@@ -118,6 +118,28 @@ repository.
|
||||
|
||||
---
|
||||
|
||||
## Installing Windows Terminal Canary
|
||||
Windows Terminal Canary is a nightly build of Windows Terminal. This build has the latest code from our `main` branch, giving you an opportunity to try features before they make it to Windows Terminal Preview.
|
||||
|
||||
Windows Terminal Canary is our least stable offering, so you may discover bugs before we have had a chance to find them.
|
||||
|
||||
Windows Terminal Canary is available as an App Installer distribution and a Portable ZIP distribution.
|
||||
|
||||
The App Installer distribution supports automatic updates. Due to platform limitations, this installer only works on Windows 11.
|
||||
|
||||
The Portable ZIP distribution is a portable application. It will not automatically update and will not automatically check for updates. This portable ZIP distribution works on Windows 10 (19041+) and Windows 11.
|
||||
|
||||
| Distribution | Architecture | Link |
|
||||
|---------------|:---------------:|------------------------------------------------------|
|
||||
| App Installer | x64, arm64, x86 | [download](https://aka.ms/terminal-canary-installer) |
|
||||
| Portable ZIP | x64 | [download](https://aka.ms/terminal-canary-zip-x64) |
|
||||
| Portable ZIP | ARM64 | [download](https://aka.ms/terminal-canary-zip-arm64) |
|
||||
| Portable ZIP | x86 | [download](https://aka.ms/terminal-canary-zip-x86) |
|
||||
|
||||
_Learn more about the [types of Windows Terminal distributions](https://learn.microsoft.com/windows/terminal/distributions)._
|
||||
|
||||
---
|
||||
|
||||
## Windows Terminal Roadmap
|
||||
|
||||
The plan for the Windows Terminal [is described here](/doc/roadmap-2023.md) and
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[
|
||||
{
|
||||
"MatchedPath": [
|
||||
"PublicTerminalCore.dll"
|
||||
"Microsoft.Terminal.Control/Microsoft.Terminal.Control.dll"
|
||||
],
|
||||
"SigningInfo": {
|
||||
"Operations": [
|
||||
|
||||
1127
build/config/release.gdnbaselines
Normal file
1127
build/config/release.gdnbaselines
Normal file
File diff suppressed because it is too large
Load Diff
38
build/config/template.appinstaller
Normal file
38
build/config/template.appinstaller
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<AppInstaller
|
||||
xmlns="http://schemas.microsoft.com/appx/appinstaller/2017/2"
|
||||
Version="1.0.0.0"
|
||||
Uri="$$ROOT$$$$NAME$$.appinstaller">
|
||||
|
||||
<MainBundle
|
||||
Name="$$NAME$$"
|
||||
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
|
||||
Version="$$VERSION$$"
|
||||
Uri="$$ROOT$$$$PACKAGE$$" />
|
||||
|
||||
<Dependencies>
|
||||
<Package
|
||||
Name="Microsoft.UI.Xaml.2.8"
|
||||
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
|
||||
Version="8.2305.5001.0"
|
||||
ProcessorArchitecture="x64"
|
||||
Uri="https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.4/Microsoft.UI.Xaml.2.8.x64.appx" />
|
||||
<Package
|
||||
Name="Microsoft.UI.Xaml.2.8"
|
||||
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
|
||||
Version="8.2305.5001.0"
|
||||
ProcessorArchitecture="x86"
|
||||
Uri="https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.4/Microsoft.UI.Xaml.2.8.x86.appx" />
|
||||
<Package
|
||||
Name="Microsoft.UI.Xaml.2.8"
|
||||
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
|
||||
Version="8.2305.5001.0"
|
||||
ProcessorArchitecture="arm64"
|
||||
Uri="https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.4/Microsoft.UI.Xaml.2.8.arm64.appx" />
|
||||
</Dependencies>
|
||||
|
||||
<UpdateSettings>
|
||||
<OnLaunch
|
||||
HoursBetweenUpdateChecks="6" />
|
||||
</UpdateSettings>
|
||||
</AppInstaller>
|
||||
6
build/config/tsa.json
Normal file
6
build/config/tsa.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"instanceUrl": "https://microsoft.visualstudio.com",
|
||||
"projectName": "OS",
|
||||
"areaPath": "OS\\Windows Client and Services\\ADEPT\\E4D-Engineered for Developers\\SHINE\\Terminal",
|
||||
"notificationAliases": ["condev@microsoft.com", "duhowett@microsoft.com"]
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
trigger: none
|
||||
pr: none
|
||||
schedules:
|
||||
- cron: "30 3 * * 2-6" # Run at 03:30 UTC Tuesday through Saturday (After the work day in Pacific, Mon-Fri)
|
||||
displayName: "Nightly Terminal Build"
|
||||
branches:
|
||||
include:
|
||||
- main
|
||||
always: false # only run if there's code changes!
|
||||
|
||||
name: $(BuildDefinitionName)_$(date:yyMM).$(date:dd)$(rev:rrr)
|
||||
|
||||
extends:
|
||||
template: templates-v2\pipeline-full-release-build.yml
|
||||
parameters:
|
||||
branding: Canary
|
||||
buildTerminal: true
|
||||
pgoBuildMode: Optimize
|
||||
codeSign: true
|
||||
generateSbom: true
|
||||
publishSymbolsToPublic: true
|
||||
publishVpackToWindows: false
|
||||
symbolExpiryTime: 15 # Nightly builds do not keep symbols for very long!
|
||||
53
build/pipelines/ob-nightly.yml
Normal file
53
build/pipelines/ob-nightly.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
trigger: none
|
||||
pr: none
|
||||
schedules:
|
||||
- cron: "30 3 * * 2-6" # Run at 03:30 UTC Tuesday through Saturday (After the work day in Pacific, Mon-Fri)
|
||||
displayName: "Nightly Terminal Build"
|
||||
branches:
|
||||
include:
|
||||
- main
|
||||
always: false # only run if there's code changes!
|
||||
|
||||
parameters:
|
||||
- name: publishToAzure
|
||||
displayName: "Deploy to **PUBLIC** Azure Storage"
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
name: $(BuildDefinitionName)_$(date:yyMM).$(date:dd)$(rev:rrr)
|
||||
|
||||
variables:
|
||||
- template: templates-v2/variables-nuget-package-version.yml
|
||||
parameters:
|
||||
branding: Canary
|
||||
- template: templates-v2/variables-onebranch-config.yml
|
||||
|
||||
extends:
|
||||
template: templates-v2/pipeline-onebranch-full-release-build.yml
|
||||
parameters:
|
||||
official: true
|
||||
branding: Canary
|
||||
buildTerminal: true
|
||||
pgoBuildMode: Optimize
|
||||
codeSign: true
|
||||
publishSymbolsToPublic: true
|
||||
publishVpackToWindows: false
|
||||
symbolExpiryTime: 15
|
||||
${{ if eq(true, parameters.publishToAzure) }}:
|
||||
extraPublishJobs:
|
||||
- template: build/pipelines/templates-v2/job-deploy-to-azure-storage.yml@self
|
||||
parameters:
|
||||
pool: { type: windows }
|
||||
variables:
|
||||
ob_git_checkout: false # This job checks itself out
|
||||
ob_git_skip_checkout_none: true
|
||||
ob_outputDirectory: "$(Build.SourcesDirectory)/_none"
|
||||
dependsOn: [PublishSymbols]
|
||||
storagePublicRootURL: $(AppInstallerRootURL)
|
||||
subscription: $(AzureSubscriptionName)
|
||||
storageAccount: $(AzureStorageAccount)
|
||||
storageContainer: $(AzureStorageContainer)
|
||||
buildConfiguration: Release
|
||||
buildPlatforms: [x64, x86, arm64]
|
||||
environment: production-canary
|
||||
|
||||
@@ -44,14 +44,6 @@ parameters:
|
||||
- x64
|
||||
- x86
|
||||
- arm64
|
||||
- name: codeSign
|
||||
displayName: "Sign all build outputs"
|
||||
type: boolean
|
||||
default: true
|
||||
- name: generateSbom
|
||||
displayName: "Generate a Bill of Materials"
|
||||
type: boolean
|
||||
default: true
|
||||
- name: terminalInternalPackageVersion
|
||||
displayName: "Terminal Internal Package Version"
|
||||
type: string
|
||||
@@ -68,9 +60,16 @@ parameters:
|
||||
|
||||
name: $(BuildDefinitionName)_$(date:yyMM).$(date:dd)$(rev:rrr)
|
||||
|
||||
variables:
|
||||
- template: templates-v2/variables-nuget-package-version.yml
|
||||
parameters:
|
||||
branding: ${{ parameters.branding }}
|
||||
- template: templates-v2/variables-onebranch-config.yml
|
||||
|
||||
extends:
|
||||
template: templates-v2/pipeline-full-release-build.yml
|
||||
template: templates-v2/pipeline-onebranch-full-release-build.yml
|
||||
parameters:
|
||||
official: true
|
||||
branding: ${{ parameters.branding }}
|
||||
buildTerminal: ${{ parameters.buildTerminal }}
|
||||
buildConPTY: ${{ parameters.buildConPTY }}
|
||||
@@ -78,8 +77,7 @@ extends:
|
||||
pgoBuildMode: ${{ parameters.pgoBuildMode }}
|
||||
buildConfigurations: ${{ parameters.buildConfigurations }}
|
||||
buildPlatforms: ${{ parameters.buildPlatforms }}
|
||||
codeSign: ${{ parameters.codeSign }}
|
||||
generateSbom: ${{ parameters.generateSbom }}
|
||||
codeSign: true
|
||||
terminalInternalPackageVersion: ${{ parameters.terminalInternalPackageVersion }}
|
||||
publishSymbolsToPublic: ${{ parameters.publishSymbolsToPublic }}
|
||||
publishVpackToWindows: ${{ parameters.publishVpackToWindows }}
|
||||
@@ -97,7 +97,7 @@ jobs:
|
||||
flattenFolders: true
|
||||
|
||||
- ${{ if eq(parameters.codeSign, true) }}:
|
||||
- task: EsrpCodeSigning@1
|
||||
- task: EsrpCodeSigning@3
|
||||
displayName: Submit *.nupkg to ESRP for code signing
|
||||
inputs:
|
||||
ConnectedServiceName: 9d6d2960-0793-4d59-943e-78dcb434840a
|
||||
|
||||
@@ -62,6 +62,9 @@ parameters:
|
||||
- name: publishArtifacts
|
||||
type: boolean
|
||||
default: true
|
||||
- name: removeAllNonSignedFiles
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
jobs:
|
||||
- job: ${{ parameters.jobName }}
|
||||
@@ -89,6 +92,11 @@ jobs:
|
||||
# Yup.
|
||||
BuildTargetParameter: ' '
|
||||
SelectedSigningFragments: ' '
|
||||
# When building the unpackaged distribution, build it in portable mode if it's Canary-branded
|
||||
${{ if eq(parameters.branding, 'Canary') }}:
|
||||
UnpackagedBuildArguments: -PortableMode
|
||||
${{ else }}:
|
||||
UnpackagedBuildArguments: ' '
|
||||
JobOutputDirectory: $(Terminal.BinDir)
|
||||
JobOutputArtifactName: build-$(BuildPlatform)-$(BuildConfiguration)${{ parameters.artifactStem }}
|
||||
${{ insert }}: ${{ parameters.variables }}
|
||||
@@ -114,7 +122,7 @@ jobs:
|
||||
$SignFragments += "wpfdotnet"
|
||||
}
|
||||
If ([bool]::Parse("${{ parameters.buildWPF }}")) {
|
||||
$BuildTargets += "Terminal\wpf\PublicTerminalCore"
|
||||
$BuildTargets += "Terminal\Control\Microsoft_Terminal_Control"
|
||||
$SignFragments += "wpf"
|
||||
}
|
||||
If ([bool]::Parse("${{ parameters.buildConPTY }}")) {
|
||||
@@ -168,6 +176,7 @@ jobs:
|
||||
# - Directories ending in Lib (static lib projects that we fully linked into DLLs which may also contain unnecessary resources)
|
||||
# - All LocalTests_ project outputs, as they were subsumed into TestHostApp
|
||||
# - All PDB files inside the WindowsTerminal/ output, which do not belong there.
|
||||
# - console.dll, which apparently breaks XFGCheck? lol.
|
||||
- pwsh: |-
|
||||
$binDir = '$(Terminal.BinDir)'
|
||||
$ImportLibs = Get-ChildItem $binDir -Recurse -File -Filter '*.exp' | ForEach-Object { $_.FullName -Replace "exp$","lib" }
|
||||
@@ -184,6 +193,8 @@ jobs:
|
||||
$Items += Get-ChildItem '$(Terminal.BinDir)' -Filter '*.pdb' -Recurse
|
||||
}
|
||||
|
||||
$Items += Get-ChildItem $binDir -Filter 'console.dll'
|
||||
|
||||
$Items | Remove-Item -Recurse -Force -Verbose -ErrorAction:Ignore
|
||||
displayName: Clean up static libs and extra symbols
|
||||
errorActionPreference: silentlyContinue # It's OK if this silently fails
|
||||
@@ -224,7 +235,7 @@ jobs:
|
||||
|
||||
# Code-sign everything we just put together.
|
||||
# We run the signing in Terminal.BinDir, because all of the signing batches are relative to the final architecture/configuration output folder.
|
||||
- task: EsrpCodeSigning@1
|
||||
- task: EsrpCodeSigning@3
|
||||
displayName: Submit Signing Request
|
||||
inputs:
|
||||
ConnectedServiceName: 9d6d2960-0793-4d59-943e-78dcb434840a
|
||||
@@ -241,6 +252,14 @@ jobs:
|
||||
Write-Host "##vso[task.setvariable variable=WindowsTerminalPackagePath]${PackageFilename}"
|
||||
displayName: Re-pack the new Terminal package after signing
|
||||
|
||||
# Some of our governed pipelines explicitly fail builds that have *any* non-codesigned filed (!)
|
||||
- ${{ if eq(parameters.removeAllNonSignedFiles, true) }}:
|
||||
- pwsh: |-
|
||||
Get-ChildItem "$(Terminal.BinDir)" -Recurse -Include "*.dll","*.exe" |
|
||||
Where-Object { (Get-AuthenticodeSignature $_).Status -Ne "Valid" } |
|
||||
Remove-Item -Verbose -Force
|
||||
displayName: Remove all non-signed output files
|
||||
|
||||
- ${{ else }}: # No Signing
|
||||
- ${{ if or(parameters.buildTerminal, parameters.buildEverything) }}:
|
||||
- pwsh: |-
|
||||
@@ -255,7 +274,7 @@ jobs:
|
||||
- pwsh: |-
|
||||
$XamlAppxPath = (Get-Item "src\cascadia\CascadiaPackage\AppPackages\*\Dependencies\$(BuildPlatform)\Microsoft.UI.Xaml*.appx").FullName
|
||||
$outDir = New-Item -Type Directory "$(Terminal.BinDir)/_unpackaged" -ErrorAction:Ignore
|
||||
& .\build\scripts\New-UnpackagedTerminalDistribution.ps1 -TerminalAppX $(WindowsTerminalPackagePath) -XamlAppX $XamlAppxPath -Destination $outDir.FullName
|
||||
& .\build\scripts\New-UnpackagedTerminalDistribution.ps1 $(UnpackagedBuildArguments) -TerminalAppX $(WindowsTerminalPackagePath) -XamlAppX $XamlAppxPath -Destination $outDir.FullName
|
||||
displayName: Build Unpackaged Distribution (from MSIX)
|
||||
condition: and(succeeded(), ne(variables.WindowsTerminalPackagePath, ''))
|
||||
|
||||
|
||||
92
build/pipelines/templates-v2/job-deploy-to-azure-storage.yml
Normal file
92
build/pipelines/templates-v2/job-deploy-to-azure-storage.yml
Normal file
@@ -0,0 +1,92 @@
|
||||
parameters:
|
||||
- name: buildConfiguration
|
||||
type: string
|
||||
- name: buildPlatforms
|
||||
type: object
|
||||
- name: pool
|
||||
type: object
|
||||
default: []
|
||||
- name: dependsOn
|
||||
type: object
|
||||
default: null
|
||||
- name: artifactStem
|
||||
type: string
|
||||
default: ''
|
||||
- name: variables
|
||||
type: object
|
||||
default: {}
|
||||
- name: environment
|
||||
type: string
|
||||
- name: storagePublicRootURL
|
||||
type: string
|
||||
- name: subscription
|
||||
type: string
|
||||
- name: storageAccount
|
||||
type: string
|
||||
- name: storageContainer
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
- job: DeployAzure
|
||||
${{ if ne(length(parameters.pool), 0) }}:
|
||||
pool: ${{ parameters.pool }}
|
||||
displayName: Publish to Azure Storage (Prod)
|
||||
dependsOn: ${{ parameters.dependsOn }}
|
||||
variables:
|
||||
${{ insert }}: ${{ parameters.variables }}
|
||||
steps:
|
||||
- download: none
|
||||
|
||||
- checkout: self
|
||||
clean: true
|
||||
fetchDepth: 1
|
||||
fetchTags: false # Tags still result in depth > 1 fetch; we don't need them here
|
||||
submodules: true
|
||||
persistCredentials: True
|
||||
|
||||
- task: DownloadPipelineArtifact@2
|
||||
displayName: Download MSIX Bundle Artifact
|
||||
inputs:
|
||||
artifactName: appxbundle-${{ parameters.buildConfiguration }}${{ parameters.artifactStem }}
|
||||
downloadPath: '$(Build.SourcesDirectory)/_out'
|
||||
itemPattern: '**/*.msixbundle'
|
||||
|
||||
- ${{ each platform in parameters.buildPlatforms }}:
|
||||
- task: DownloadPipelineArtifact@2
|
||||
displayName: Download unpackaged build for ${{ platform }} ${{ parameters.buildConfiguration }}
|
||||
inputs:
|
||||
artifactName: build-${{ platform }}-${{ parameters.buildConfiguration }}${{ parameters.artifactStem }}
|
||||
downloadPath: '$(Build.SourcesDirectory)/_unpackaged'
|
||||
itemPattern: '**/_unpackaged/*.zip'
|
||||
|
||||
- pwsh: |-
|
||||
$b = Get-Item _out/*.msixbundle
|
||||
./build/scripts/New-AppInstallerFromTemplateAndBundle.ps1 -BundlePath $b.FullName -AppInstallerTemplatePath ./build/config/template.appinstaller -AppInstallerRoot "${{ parameters.storagePublicRootURL }}" -OutputPath _out/Microsoft.WindowsTerminalCanary.appinstaller
|
||||
displayName: "Produce AppInstaller for MSIX bundle"
|
||||
|
||||
- pwsh: |-
|
||||
$zips = Get-ChildItem -Recurse -Filter *.zip _unpackaged
|
||||
$zips | ForEach-Object {
|
||||
$name = $_.Name
|
||||
$parts = $name.Split('_')
|
||||
$parts[1] = "latest"
|
||||
$name = [String]::Join('_', $parts)
|
||||
$_ | Move-Item -Destination (Join-Path "_out" $name)
|
||||
}
|
||||
displayName: "Wrangle Unpackaged builds into place, rename"
|
||||
|
||||
- powershell: |-
|
||||
Get-PackageProvider -Name NuGet -ForceBootstrap
|
||||
Install-Module -Verbose -AllowClobber -Force Az.Accounts, Az.Storage, Az.Network, Az.Resources, Az.Compute
|
||||
displayName: Install Azure Module Dependencies
|
||||
|
||||
- task: AzureFileCopy@5
|
||||
displayName: Publish to Storage Account
|
||||
inputs:
|
||||
sourcePath: _out/*
|
||||
Destination: AzureBlob
|
||||
azureSubscription: ${{ parameters.subscription }}
|
||||
storage: ${{ parameters.storageAccount }}
|
||||
ContainerName: ${{ parameters.storageContainer }}
|
||||
AdditionalArgumentsForBlobCopy: "--content-type application/octet-stream"
|
||||
|
||||
@@ -29,6 +29,9 @@ parameters:
|
||||
- name: publishArtifacts
|
||||
type: boolean
|
||||
default: true
|
||||
- name: afterBuildSteps
|
||||
type: stepList
|
||||
default: []
|
||||
|
||||
jobs:
|
||||
- job: ${{ parameters.jobName }}
|
||||
@@ -48,6 +51,8 @@ jobs:
|
||||
BundleStemName: Microsoft.WindowsTerminal
|
||||
${{ elseif eq(parameters.branding, 'Preview') }}:
|
||||
BundleStemName: Microsoft.WindowsTerminalPreview
|
||||
${{ elseif eq(parameters.branding, 'Canary') }}:
|
||||
BundleStemName: Microsoft.WindowsTerminalCanary
|
||||
${{ else }}:
|
||||
BundleStemName: WindowsTerminalDev
|
||||
JobOutputDirectory: '$(System.ArtifactsDirectory)/bundle'
|
||||
@@ -83,11 +88,13 @@ jobs:
|
||||
$Components[0] = ([int]$Components[0] + $VersionEpoch)
|
||||
$BundleVersion = $Components -Join "."
|
||||
New-Item -Type Directory "$(System.ArtifactsDirectory)/bundle"
|
||||
.\build\scripts\Create-AppxBundle.ps1 -InputPath 'bin/' -ProjectName CascadiaPackage -BundleVersion $BundleVersion -OutputPath "$(System.ArtifactsDirectory)\bundle\$(BundleStemName)_$(XES_APPXMANIFESTVERSION)_8wekyb3d8bbwe.msixbundle"
|
||||
$BundlePath = "$(System.ArtifactsDirectory)\bundle\$(BundleStemName)_$(XES_APPXMANIFESTVERSION)_8wekyb3d8bbwe.msixbundle"
|
||||
.\build\scripts\Create-AppxBundle.ps1 -InputPath 'bin/' -ProjectName CascadiaPackage -BundleVersion $BundleVersion -OutputPath $BundlePath
|
||||
Write-Host "##vso[task.setvariable variable=MsixBundlePath]${BundlePath}"
|
||||
displayName: Create msixbundle
|
||||
|
||||
- ${{ if eq(parameters.codeSign, true) }}:
|
||||
- task: EsrpCodeSigning@1
|
||||
- task: EsrpCodeSigning@3
|
||||
displayName: Submit *.msixbundle to ESRP for code signing
|
||||
inputs:
|
||||
ConnectedServiceName: 9d6d2960-0793-4d59-943e-78dcb434840a
|
||||
@@ -137,6 +144,8 @@ jobs:
|
||||
ValidateSignature: true
|
||||
Verbosity: 'Verbose'
|
||||
|
||||
- ${{ parameters.afterBuildSteps }}
|
||||
|
||||
- ${{ if eq(parameters.publishArtifacts, true) }}:
|
||||
- publish: $(JobOutputDirectory)
|
||||
artifact: $(JobOutputArtifactName)
|
||||
|
||||
@@ -82,7 +82,7 @@ jobs:
|
||||
versionEnvVar: XES_PACKAGEVERSIONNUMBER
|
||||
|
||||
- ${{ if eq(parameters.codeSign, true) }}:
|
||||
- task: EsrpCodeSigning@1
|
||||
- task: EsrpCodeSigning@3
|
||||
displayName: Submit *.nupkg to ESRP for code signing
|
||||
inputs:
|
||||
ConnectedServiceName: 9d6d2960-0793-4d59-943e-78dcb434840a
|
||||
|
||||
@@ -17,6 +17,12 @@ parameters:
|
||||
- name: symbolExpiryTime
|
||||
type: string
|
||||
default: 36530 # This is the default from PublishSymbols@2
|
||||
- name: variables
|
||||
type: object
|
||||
default: {}
|
||||
- name: symbolPatGoesInTaskInputs
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
jobs:
|
||||
- job: ${{ parameters.jobName }}
|
||||
@@ -27,6 +33,8 @@ jobs:
|
||||
${{ else }}:
|
||||
displayName: Publish Symbols Internally
|
||||
dependsOn: ${{ parameters.dependsOn }}
|
||||
variables:
|
||||
${{ insert }}: ${{ parameters.variables }}
|
||||
steps:
|
||||
- checkout: self
|
||||
clean: true
|
||||
@@ -76,6 +84,8 @@ jobs:
|
||||
SymbolsProduct: 'Windows Terminal Converged Symbols'
|
||||
SymbolsVersion: '$(XES_APPXMANIFESTVERSION)'
|
||||
SymbolExpirationInDays: ${{ parameters.symbolExpiryTime }}
|
||||
${{ if eq(parameters.symbolPatGoesInTaskInputs, true) }}:
|
||||
Pat: $(ADO_microsoftpublicsymbols_PAT)
|
||||
# The ADO task does not support indexing of GitHub sources.
|
||||
# There is a bug which causes this task to fail if LIB includes an inaccessible path (even though it does not depend on it).
|
||||
# To work around this issue, we just force LIB to be any dir that we know exists.
|
||||
@@ -83,4 +93,5 @@ jobs:
|
||||
env:
|
||||
LIB: $(Build.SourcesDirectory)
|
||||
ArtifactServices_Symbol_AccountName: microsoftpublicsymbols
|
||||
ArtifactServices_Symbol_PAT: $(ADO_microsoftpublicsymbols_PAT)
|
||||
${{ if ne(parameters.symbolPatGoesInTaskInputs, true) }}:
|
||||
ArtifactServices_Symbol_PAT: $(ADO_microsoftpublicsymbols_PAT)
|
||||
|
||||
@@ -51,6 +51,9 @@ parameters:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
- name: extraPublishJobs
|
||||
type: object
|
||||
default: []
|
||||
- name: pool
|
||||
type: object
|
||||
default:
|
||||
@@ -58,28 +61,9 @@ parameters:
|
||||
demands: ImageOverride -equals SHINE-VS17-Latest
|
||||
|
||||
variables:
|
||||
# If we are building a branch called "release-*", change the NuGet suffix
|
||||
# to "preview". If we don't do that, XES will set the suffix to "release1"
|
||||
# because it truncates the value after the first period.
|
||||
# We also want to disable the suffix entirely if we're Release branded while
|
||||
# on a release branch.
|
||||
# main is special, however. XES ignores main. Since we never produce actual
|
||||
# shipping builds from main, we want to force it to have a beta label as
|
||||
# well.
|
||||
#
|
||||
# In effect:
|
||||
# BRANCH / BRANDING | Release | Preview
|
||||
# ------------------|----------------------------|-----------------------------
|
||||
# release-* | 1.12.20220427 | 1.13.20220427-preview
|
||||
# main | 1.14.20220427-experimental | 1.14.20220427-experimental
|
||||
# all others | 1.14.20220427-mybranch | 1.14.20220427-mybranch
|
||||
${{ if startsWith(variables['Build.SourceBranchName'], 'release-') }}:
|
||||
${{ if eq(parameters.branding, 'Release') }}:
|
||||
NoNuGetPackBetaVersion: true
|
||||
${{ else }}:
|
||||
NuGetPackBetaVersion: preview
|
||||
${{ elseif eq(variables['Build.SourceBranchName'], 'main') }}:
|
||||
NuGetPackBetaVersion: experimental
|
||||
- template: variables-nuget-package-version.yml
|
||||
parameters:
|
||||
branding: ${{ parameters.branding }}
|
||||
|
||||
resources:
|
||||
repositories:
|
||||
@@ -193,4 +177,5 @@ stages:
|
||||
includePublicSymbolServer: ${{ parameters.publishSymbolsToPublic }}
|
||||
symbolExpiryTime: ${{ parameters.symbolExpiryTime }}
|
||||
|
||||
- ${{ parameters.extraPublishJobs }}
|
||||
...
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
parameters:
|
||||
- name: official
|
||||
type: boolean
|
||||
default: false
|
||||
- name: branding
|
||||
type: string
|
||||
default: Release
|
||||
values:
|
||||
- Release
|
||||
- Preview
|
||||
- Canary
|
||||
- Dev
|
||||
- name: buildTerminal
|
||||
type: boolean
|
||||
default: true
|
||||
- name: buildConPTY
|
||||
type: boolean
|
||||
default: false
|
||||
- name: buildWPF
|
||||
type: boolean
|
||||
default: false
|
||||
- name: pgoBuildMode
|
||||
type: string
|
||||
default: Optimize
|
||||
values:
|
||||
- Optimize
|
||||
- Instrument
|
||||
- None
|
||||
- name: buildConfigurations
|
||||
type: object
|
||||
default:
|
||||
- Release
|
||||
- name: buildPlatforms
|
||||
type: object
|
||||
default:
|
||||
- x64
|
||||
- x86
|
||||
- arm64
|
||||
- name: codeSign
|
||||
type: boolean
|
||||
default: true
|
||||
- name: terminalInternalPackageVersion
|
||||
type: string
|
||||
default: '0.0.8'
|
||||
|
||||
- name: publishSymbolsToPublic
|
||||
type: boolean
|
||||
default: true
|
||||
- name: symbolExpiryTime
|
||||
type: string
|
||||
default: 36530 # This is the default from PublishSymbols@2
|
||||
- name: publishVpackToWindows
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
- name: extraPublishJobs
|
||||
type: object
|
||||
default: []
|
||||
|
||||
resources:
|
||||
repositories:
|
||||
- repository: templates
|
||||
type: git
|
||||
name: OneBranch.Pipelines/GovernedTemplates
|
||||
ref: refs/heads/main
|
||||
|
||||
extends:
|
||||
${{ if eq(parameters.official, true) }}:
|
||||
template: v2/Microsoft.Official.yml@templates # https://aka.ms/obpipelines/templates
|
||||
${{ else }}:
|
||||
template: v2/Microsoft.NonOfficial.yml@templates
|
||||
parameters:
|
||||
featureFlags:
|
||||
WindowsHostVersion: 1ESWindows2022
|
||||
platform:
|
||||
name: 'windows_undocked'
|
||||
product: 'Windows Terminal'
|
||||
cloudvault: # https://aka.ms/obpipelines/cloudvault
|
||||
enabled: false
|
||||
globalSdl: # https://aka.ms/obpipelines/sdl
|
||||
tsa:
|
||||
enabled: true
|
||||
configFile: '$(Build.SourcesDirectory)\build\config\tsa.json'
|
||||
binskim:
|
||||
break: false
|
||||
scanOutputDirectoryOnly: true
|
||||
policheck:
|
||||
break: false
|
||||
severity: Note
|
||||
baseline:
|
||||
baselineFile: '$(Build.SourcesDirectory)\build\config\release.gdnbaselines'
|
||||
suppressionSet: default
|
||||
|
||||
stages:
|
||||
- stage: Build
|
||||
displayName: Build
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: ./build/pipelines/templates-v2/job-build-project.yml@self
|
||||
parameters:
|
||||
pool: { type: windows }
|
||||
variables:
|
||||
ob_git_checkout: false # This job checks itself out
|
||||
ob_git_skip_checkout_none: true
|
||||
ob_outputDirectory: $(JobOutputDirectory)
|
||||
ob_artifactBaseName: $(JobOutputArtifactName)
|
||||
publishArtifacts: false # Handled by OneBranch
|
||||
branding: ${{ parameters.branding }}
|
||||
buildTerminal: ${{ parameters.buildTerminal }}
|
||||
buildConPTY: ${{ parameters.buildConPTY }}
|
||||
buildWPF: ${{ parameters.buildWPF }}
|
||||
pgoBuildMode: ${{ parameters.pgoBuildMode }}
|
||||
buildConfigurations: ${{ parameters.buildConfigurations }}
|
||||
buildPlatforms: ${{ parameters.buildPlatforms }}
|
||||
generateSbom: false # this is handled by onebranch
|
||||
removeAllNonSignedFiles: true # appease the overlords
|
||||
codeSign: ${{ parameters.codeSign }}
|
||||
beforeBuildSteps: # Right before we build, lay down the universal package and localizations
|
||||
- task: PkgESSetupBuild@12
|
||||
displayName: Package ES - Setup Build
|
||||
inputs:
|
||||
disableOutputRedirect: true
|
||||
|
||||
- task: UniversalPackages@0
|
||||
displayName: Download terminal-internal Universal Package
|
||||
inputs:
|
||||
feedListDownload: 2b3f8893-a6e8-411f-b197-a9e05576da48
|
||||
packageListDownload: e82d490c-af86-4733-9dc4-07b772033204
|
||||
versionListDownload: ${{ parameters.terminalInternalPackageVersion }}
|
||||
|
||||
- template: ./build/pipelines/templates-v2/steps-fetch-and-prepare-localizations.yml@self
|
||||
parameters:
|
||||
includePseudoLoc: true
|
||||
|
||||
- ${{ if eq(parameters.buildWPF, true) }}:
|
||||
# Add an Any CPU build flavor for the WPF control bits
|
||||
- template: ./build/pipelines/templates-v2/job-build-project.yml@self
|
||||
parameters:
|
||||
pool: { type: windows }
|
||||
variables:
|
||||
ob_git_checkout: false # This job checks itself out
|
||||
ob_git_skip_checkout_none: true
|
||||
ob_outputDirectory: $(JobOutputDirectory)
|
||||
ob_artifactBaseName: $(JobOutputArtifactName)
|
||||
publishArtifacts: false # Handled by OneBranch
|
||||
jobName: BuildWPF
|
||||
branding: ${{ parameters.branding }}
|
||||
buildTerminal: false
|
||||
buildWPFDotNetComponents: true
|
||||
buildConfigurations: ${{ parameters.buildConfigurations }}
|
||||
buildPlatforms:
|
||||
- Any CPU
|
||||
generateSbom: false # this is handled by onebranch
|
||||
removeAllNonSignedFiles: true # appease the overlords
|
||||
codeSign: ${{ parameters.codeSign }}
|
||||
beforeBuildSteps:
|
||||
- task: PkgESSetupBuild@12
|
||||
displayName: Package ES - Setup Build
|
||||
inputs:
|
||||
disableOutputRedirect: true
|
||||
# WPF doesn't need the localizations or the universal package, but if it does... put them here.
|
||||
|
||||
- stage: Package
|
||||
displayName: Package
|
||||
dependsOn: [Build]
|
||||
jobs:
|
||||
- ${{ if eq(parameters.buildTerminal, true) }}:
|
||||
- template: ./build/pipelines/templates-v2/job-merge-msix-into-bundle.yml@self
|
||||
parameters:
|
||||
pool: { type: windows }
|
||||
variables:
|
||||
ob_git_checkout: false # This job checks itself out
|
||||
ob_git_skip_checkout_none: true
|
||||
ob_outputDirectory: $(JobOutputDirectory)
|
||||
ob_artifactBaseName: $(JobOutputArtifactName)
|
||||
### This job is also in charge of submitting the vpack to Windows if it's enabled
|
||||
ob_createvpack_enabled: ${{ and(parameters.buildTerminal, parameters.publishVpackToWindows) }}
|
||||
ob_updateOSManifest_enabled: ${{ and(parameters.buildTerminal, parameters.publishVpackToWindows) }}
|
||||
### If enabled above, these options are in play.
|
||||
ob_createvpack_packagename: 'WindowsTerminal.app'
|
||||
ob_createvpack_owneralias: 'conhost@microsoft.com'
|
||||
ob_createvpack_description: 'VPack for the Windows Terminal Application'
|
||||
ob_createvpack_targetDestinationDirectory: '$(Destination)'
|
||||
ob_createvpack_propsFile: false
|
||||
ob_createvpack_provData: true
|
||||
ob_createvpack_metadata: '$(Build.SourceVersion)'
|
||||
ob_createvpack_topLevelRetries: 0
|
||||
ob_createvpack_failOnStdErr: true
|
||||
ob_createvpack_taskLogVerbosity: Detailed
|
||||
ob_createvpack_verbose: true
|
||||
ob_createvpack_vpackdirectory: '$(JobOutputDirectory)\vpack'
|
||||
ob_updateOSManifest_gitcheckinConfigPath: '$(Build.SourcesDirectory)\build\config\GitCheckin.json'
|
||||
# We're skipping the 'fetch' part of the OneBranch rules, but that doesn't mean
|
||||
# that it doesn't expect to have downloaded a manifest directly to some 'destination'
|
||||
# folder that it can then update and upload.
|
||||
# Effectively: it says "destination" but it means "source"
|
||||
# DH: Don't ask why.
|
||||
ob_updateOSManifest_destination: $(XES_VPACKMANIFESTDIRECTORY)
|
||||
ob_updateOSManifest_skipFetch: true
|
||||
publishArtifacts: false # Handled by OneBranch
|
||||
jobName: Bundle
|
||||
branding: ${{ parameters.branding }}
|
||||
buildConfigurations: ${{ parameters.buildConfigurations }}
|
||||
buildPlatforms: ${{ parameters.buildPlatforms }}
|
||||
generateSbom: false # Handled by onebranch
|
||||
codeSign: ${{ parameters.codeSign }}
|
||||
afterBuildSteps:
|
||||
# This directory has to exist, even if we aren't using createvpack, because the Guardian rules demand it.
|
||||
- pwsh: |-
|
||||
New-Item "$(JobOutputDirectory)/vpack" -Type Directory
|
||||
displayName: Make sure the vpack directory exists
|
||||
|
||||
- ${{ if parameters.publishVpackToWindows }}:
|
||||
- pwsh: |-
|
||||
Copy-Item -Verbose -Path "$(MsixBundlePath)" -Destination (Join-Path "$(JobOutputDirectory)/vpack" 'Microsoft.WindowsTerminal_8wekyb3d8bbwe.msixbundle')
|
||||
displayName: Stage msixbundle for vpack
|
||||
|
||||
- ${{ if eq(parameters.buildConPTY, true) }}:
|
||||
- template: ./build/pipelines/templates-v2/job-package-conpty.yml@self
|
||||
parameters:
|
||||
pool: { type: windows }
|
||||
variables:
|
||||
ob_git_checkout: false # This job checks itself out
|
||||
ob_git_skip_checkout_none: true
|
||||
ob_outputDirectory: $(JobOutputDirectory)
|
||||
ob_artifactBaseName: $(JobOutputArtifactName)
|
||||
publishArtifacts: false # Handled by OneBranch
|
||||
buildConfigurations: ${{ parameters.buildConfigurations }}
|
||||
buildPlatforms: ${{ parameters.buildPlatforms }}
|
||||
generateSbom: false # this is handled by onebranch
|
||||
codeSign: ${{ parameters.codeSign }}
|
||||
|
||||
- ${{ if eq(parameters.buildWPF, true) }}:
|
||||
- template: ./build/pipelines/templates-v2/job-build-package-wpf.yml@self
|
||||
parameters:
|
||||
pool: { type: windows }
|
||||
variables:
|
||||
ob_git_checkout: false # This job checks itself out
|
||||
ob_git_skip_checkout_none: true
|
||||
ob_outputDirectory: $(JobOutputDirectory)
|
||||
ob_artifactBaseName: $(JobOutputArtifactName)
|
||||
publishArtifacts: false # Handled by OneBranch
|
||||
buildConfigurations: ${{ parameters.buildConfigurations }}
|
||||
buildPlatforms: ${{ parameters.buildPlatforms }}
|
||||
generateSbom: false # this is handled by onebranch
|
||||
codeSign: ${{ parameters.codeSign }}
|
||||
|
||||
- stage: Publish
|
||||
displayName: Publish
|
||||
dependsOn: [Build, Package]
|
||||
jobs:
|
||||
- template: ./build/pipelines/templates-v2/job-publish-symbols.yml@self
|
||||
parameters:
|
||||
pool: { type: windows }
|
||||
includePublicSymbolServer: ${{ parameters.publishSymbolsToPublic }}
|
||||
symbolPatGoesInTaskInputs: true # onebranch tries to muck with the PAT variable, so we need to change how it get the PAT
|
||||
symbolExpiryTime: ${{ parameters.symbolExpiryTime }}
|
||||
variables:
|
||||
ob_git_checkout: false # This job checks itself out
|
||||
ob_git_skip_checkout_none: true
|
||||
ob_outputDirectory: $(Build.ArtifactStagingDirectory)
|
||||
# Without this, OneBranch will nerf our symbol tasks
|
||||
ob_symbolsPublishing_enabled: true
|
||||
|
||||
- ${{ parameters.extraPublishJobs }}
|
||||
@@ -0,0 +1,27 @@
|
||||
parameters:
|
||||
- name: branding
|
||||
type: string
|
||||
|
||||
variables:
|
||||
# If we are building a branch called "release-*", change the NuGet suffix
|
||||
# to "preview". If we don't do that, XES will set the suffix to "release1"
|
||||
# because it truncates the value after the first period.
|
||||
# We also want to disable the suffix entirely if we're Release branded while
|
||||
# on a release branch.
|
||||
# main is special, however. XES ignores main. Since we never produce actual
|
||||
# shipping builds from main, we want to force it to have a beta label as
|
||||
# well.
|
||||
#
|
||||
# In effect:
|
||||
# BRANCH / BRANDING | Release | Preview
|
||||
# ------------------|----------------------------|-----------------------------
|
||||
# release-* | 1.12.20220427 | 1.13.20220427-preview
|
||||
# main | 1.14.20220427-experimental | 1.14.20220427-experimental
|
||||
# all others | 1.14.20220427-mybranch | 1.14.20220427-mybranch
|
||||
${{ if startsWith(variables['Build.SourceBranchName'], 'release-') }}:
|
||||
${{ if eq(parameters.branding, 'Release') }}:
|
||||
NoNuGetPackBetaVersion: true
|
||||
${{ else }}:
|
||||
NuGetPackBetaVersion: preview
|
||||
${{ elseif eq(variables['Build.SourceBranchName'], 'main') }}:
|
||||
NuGetPackBetaVersion: experimental
|
||||
@@ -0,0 +1,2 @@
|
||||
variables:
|
||||
WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2022/vse2022:latest'
|
||||
42
build/scripts/New-AppInstallerFromTemplateAndBundle.ps1
Normal file
42
build/scripts/New-AppInstallerFromTemplateAndBundle.ps1
Normal file
@@ -0,0 +1,42 @@
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory,
|
||||
HelpMessage="Path to the .msixbundle")]
|
||||
[string]
|
||||
$BundlePath,
|
||||
|
||||
[Parameter(Mandatory,
|
||||
HelpMessage="Path to the .appinstaller template")]
|
||||
[string]
|
||||
$AppInstallerTemplatePath,
|
||||
|
||||
[string]
|
||||
$AppInstallerRoot,
|
||||
|
||||
[Parameter(Mandatory,
|
||||
HelpMessage="Output Path")]
|
||||
[string]
|
||||
$OutputPath
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$sentinelFile = New-TemporaryFile
|
||||
$directory = New-Item -Type Directory "$($sentinelFile.FullName)_Package"
|
||||
Remove-Item $sentinelFile -Force -EA:Ignore
|
||||
|
||||
$bundle = (Get-Item $BundlePath)
|
||||
& tar.exe -x -f $bundle.FullName -C $directory AppxMetadata/AppxBundleManifest.xml
|
||||
|
||||
$xml = [xml](Get-Content (Join-Path $directory "AppxMetadata\AppxBundleManifest.xml"))
|
||||
$name = $xml.Bundle.Identity.Name
|
||||
$version = $xml.Bundle.Identity.Version
|
||||
|
||||
$doc = (Get-Content -ReadCount 0 $AppInstallerTemplatePath)
|
||||
$doc = $doc -Replace '\$\$ROOT\$\$',$AppInstallerRoot
|
||||
$doc = $doc -Replace '\$\$NAME\$\$',$name
|
||||
$doc = $doc -Replace '\$\$VERSION\$\$',$version
|
||||
$doc = $doc -Replace '\$\$PACKAGE\$\$',$bundle.Name
|
||||
$doc | Out-File -Encoding utf8NoBOM $OutputPath
|
||||
|
||||
Get-Item $OutputPath
|
||||
@@ -25,7 +25,12 @@ Param(
|
||||
[Parameter(HelpMessage="Path to makeappx.exe", ParameterSetName='Layout')]
|
||||
[ValidateScript({Test-Path $_ -Type Leaf})]
|
||||
[string]
|
||||
$MakeAppxPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\MakeAppx.exe"
|
||||
$MakeAppxPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\MakeAppx.exe",
|
||||
|
||||
[Parameter(HelpMessage="Include the portable mode marker file by default", ParameterSetName='AppX')]
|
||||
[Parameter(HelpMessage="Include the portable mode marker file by default", ParameterSetName='Layout')]
|
||||
[switch]
|
||||
$PortableMode = $PSCmdlet.ParameterSetName -eq 'Layout'
|
||||
)
|
||||
|
||||
$filesToRemove = @("*.xml", "*.winmd", "Appx*", "Images/*Tile*", "Images/*Logo*") # Remove from Terminal
|
||||
@@ -128,6 +133,11 @@ $finalTerminalPriFile = Join-Path $terminalAppPath "resources.pri"
|
||||
# Packaging
|
||||
########
|
||||
|
||||
$portableModeMarkerFile = Join-Path $terminalAppPath ".portable"
|
||||
If ($PortableMode) {
|
||||
"" | Out-File $portableModeMarkerFile
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ParameterSetName -Eq "AppX") {
|
||||
# We only produce a ZIP when we're combining two AppX directories.
|
||||
New-Item -ItemType Directory -Path $Destination -ErrorAction:SilentlyContinue | Out-Null
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<XesUseOneStoreVersioning>true</XesUseOneStoreVersioning>
|
||||
<XesBaseYearForStoreVersion>2023</XesBaseYearForStoreVersion>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<VersionMinor>19</VersionMinor>
|
||||
<VersionMinor>20</VersionMinor>
|
||||
<VersionInfoProductName>Windows Terminal</VersionInfoProductName>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<package id="Microsoft.VisualStudio.Setup.Configuration.Native" version="2.3.2262" targetFramework="native" developmentDependency="true" />
|
||||
<package id="Microsoft.UI.Xaml" version="2.8.4" targetFramework="native" />
|
||||
<package id="Microsoft.Web.WebView2" version="1.0.1661.34" targetFramework="native" />
|
||||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" developmentDependency="true" />
|
||||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.230824.2" targetFramework="native" developmentDependency="true" />
|
||||
|
||||
<!-- Managed packages -->
|
||||
<package id="Appium.WebDriver" version="3.0.0.2" targetFramework="net45" />
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
* `/src/cascadia/TerminalApp` - This DLL represents the implementation of the Windows Terminal application. This includes parsing settings, hosting tabs & panes with Terminals in them, and displaying other UI elements. This DLL is almost entirely UWP-like code, and shouldn't be doing any Win32-like UI work.
|
||||
* `/src/cascadia/WindowsTerminal` - This EXE provides Win32 hosting for the TerminalApp. It will set up XAML islands, and is responsible for drawing the window, either as a standard window or with content in the titlebar (non-client area).
|
||||
* `/src/cascadia/CascadiaPackage` - This is a project for packaging the Windows Terminal and its dependencies into an .appx/.msix for deploying to the machine.
|
||||
* `/src/cascadia/PublicTerminalCore` - This is a DLL wrapper for the TerminalCore and Renderer, similar to `TermControl`, which exposes some exported functions that so the Terminal can be used from C#.
|
||||
* `/src/cascadia/WpfTerminalControl` - A DLL implementing a WPF version of the Terminal Control.
|
||||
* `/src/host` – The meat of the windows console host. This includes buffer, input, output, windowing, server management, clipboard, and most interactions with the console host window that aren’t stated anywhere else. We’re trying to pull things out that are reusable into other libraries, but it’s a work in progress
|
||||
* `/src/host/lib` – Builds the reusable LIB copy of the host
|
||||
|
||||
@@ -378,8 +378,12 @@
|
||||
},
|
||||
"ShortcutActionName": {
|
||||
"enum": [
|
||||
"addMark",
|
||||
"adjustFontSize",
|
||||
"adjustOpacity",
|
||||
"clearAllMarks",
|
||||
"clearBuffer",
|
||||
"clearMark",
|
||||
"closeOtherPanes",
|
||||
"closeOtherTabs",
|
||||
"closePane",
|
||||
@@ -390,6 +394,7 @@
|
||||
"copy",
|
||||
"duplicateTab",
|
||||
"expandSelectionToWord",
|
||||
"experimental.colorSelection",
|
||||
"exportBuffer",
|
||||
"find",
|
||||
"findMatch",
|
||||
@@ -397,64 +402,60 @@
|
||||
"globalSummon",
|
||||
"identifyWindow",
|
||||
"identifyWindows",
|
||||
"markMode",
|
||||
"moveFocus",
|
||||
"movePane",
|
||||
"swapPane",
|
||||
"markMode",
|
||||
"moveTab",
|
||||
"multipleActions",
|
||||
"newTab",
|
||||
"newWindow",
|
||||
"nextTab",
|
||||
"openAbout",
|
||||
"openNewTabDropdown",
|
||||
"openSettings",
|
||||
"openSystemMenu",
|
||||
"openTabColorPicker",
|
||||
"openTabRenamer",
|
||||
"openWindowRenamer",
|
||||
"paste",
|
||||
"prevTab",
|
||||
"renameTab",
|
||||
"openSystemMenu",
|
||||
"openTabRenamer",
|
||||
"quakeMode",
|
||||
"quit",
|
||||
"renameTab",
|
||||
"renameWindow",
|
||||
"resetFontSize",
|
||||
"resizePane",
|
||||
"renameWindow",
|
||||
"restoreLastClosed",
|
||||
"scrollDown",
|
||||
"scrollDownPage",
|
||||
"scrollToBottom",
|
||||
"scrollToMark",
|
||||
"scrollToTop",
|
||||
"scrollUp",
|
||||
"scrollUpPage",
|
||||
"scrollToBottom",
|
||||
"scrollToTop",
|
||||
"searchWeb",
|
||||
"selectAll",
|
||||
"sendInput",
|
||||
"setColorScheme",
|
||||
"setFocusMode",
|
||||
"setFullScreen",
|
||||
"setMaximized",
|
||||
"setTabColor",
|
||||
"showSuggestions",
|
||||
"splitPane",
|
||||
"swapPane",
|
||||
"switchSelectionEndpoint",
|
||||
"switchToTab",
|
||||
"tabSearch",
|
||||
"toggleAlwaysOnTop",
|
||||
"toggleBlockSelection",
|
||||
"toggleFocusMode",
|
||||
"selectAll",
|
||||
"setFocusMode",
|
||||
"switchSelectionEndpoint",
|
||||
"toggleFullscreen",
|
||||
"setFullScreen",
|
||||
"setMaximized",
|
||||
"togglePaneZoom",
|
||||
"toggleSplitOrientation",
|
||||
"toggleReadOnlyMode",
|
||||
"toggleShaderEffects",
|
||||
"toggleSplitOrientation",
|
||||
"wt",
|
||||
"quit",
|
||||
"adjustOpacity",
|
||||
"restoreLastClosed",
|
||||
"addMark",
|
||||
"scrollToMark",
|
||||
"clearMark",
|
||||
"clearAllMarks",
|
||||
"searchWeb",
|
||||
"experimental.colorSelection",
|
||||
"unbound"
|
||||
],
|
||||
"type": "string"
|
||||
@@ -672,7 +673,7 @@
|
||||
},
|
||||
"allowEmpty": {
|
||||
"description": "Whether to render a folder without entries, or to hide it",
|
||||
"default": "false",
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
@@ -2279,11 +2280,6 @@
|
||||
"description": "When set to true, the background image for the currently focused profile is expanded to encompass the entire window, beneath other panes.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"compatibility.reloadEnvironmentVariables": {
|
||||
"default": true,
|
||||
"description": "When set to true, when opening a new tab or pane it will get reloaded environment variables.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"initialCols": {
|
||||
"default": 120,
|
||||
"description": "The number of columns displayed in the window upon first load. If \"launchMode\" is set to \"maximized\" (or \"maximizedFocus\"), this property is ignored.",
|
||||
@@ -2532,6 +2528,11 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"compatibility.reloadEnvironmentVariables": {
|
||||
"default": true,
|
||||
"description": "When set to true, when opening a new tab or pane it will get reloaded environment variables.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"unfocusedAppearance": {
|
||||
"$ref": "#/$defs/AppearanceConfig",
|
||||
"description": "Sets the appearance of the terminal when it is unfocused.",
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 585 KiB |
744
doc/specs/#1595 - Suggestions UI/Suggestions-UI.md
Normal file
744
doc/specs/#1595 - Suggestions UI/Suggestions-UI.md
Normal file
@@ -0,0 +1,744 @@
|
||||
---
|
||||
author: Mike Griese
|
||||
created on: 2022-08-22
|
||||
last updated: 2023-08-03
|
||||
issue id: 1595
|
||||
---
|
||||
|
||||
# Windows Terminal - Suggestions UI
|
||||
|
||||
## Abstract
|
||||
|
||||
Multiple related scenarios have come up where it would be beneficial to display
|
||||
actionable UI to the user within the context of the active terminal itself. This
|
||||
UI would be akin to the Intellisense UI in Visual Studio. It appears right where
|
||||
the user is typing, and can help provide immediate content for the user, based
|
||||
on some context. The "Suggestions UI" is this new ephemeral UI within the
|
||||
Windows Terminal that can display different types of actions, from different
|
||||
sources.
|
||||
|
||||
## Background
|
||||
|
||||
The Suggestions UI is the singular UI by which the Terminal can display a
|
||||
variety of suggestions to the user. These include:
|
||||
|
||||
* Recent commands the user has executed in this terminal, powered by shell integration.
|
||||
* Recent directories, similarly powered by shell integration
|
||||
* Completions from the shell itself (like the shell completions in PowerShell)
|
||||
* Tasks, which are `sendInput` actions from the user's settings
|
||||
* Buffer Completions, which is a dumb type of autocomplete based on words in the buffer
|
||||
* and more (as provided via extensions)
|
||||
|
||||
All of these scenarios are places where it makes sense to present the user a
|
||||
menu at the point of text insertion in the terminal control itself.
|
||||
|
||||
### Inspiration
|
||||
|
||||
Primarily, the inspiration is any Intellisense-like experience, in any app.
|
||||
Visual Studio, VsCode, PowerShell, vim, Sublime any JetBrains IDE - there's more
|
||||
than enough examples in the wild.
|
||||
|
||||
Ultimately, the inspiration for the Suggestions UI came from a bunch of places
|
||||
all at once. In the course of a few months though, it became clear that we'd
|
||||
need a unified UI for displaying a variety of suggestion-like experiences in the
|
||||
Terminal. Our work with the PowerShell and VsCode teams helped refine these
|
||||
requests all into the unified design below.
|
||||
|
||||
### User Stories
|
||||
|
||||
Size | Description
|
||||
-----------|--
|
||||
🐣 Crawl | The user can bring up the Suggestions UI with recent commands, powered by shell integration
|
||||
🐣 Crawl | [#12863] The user can bring up the Suggestions UI with recent directories, powered by shell integration
|
||||
🚶 Walk | The user can bring up the Suggestions UI with tasks from their settings
|
||||
🚶 Walk | CLI apps can invoke the Suggestions UI with a new VT sequence
|
||||
🚶 Walk | The Suggestions UI can be opened using the current typed commandline as a filter
|
||||
🚶 Walk | Recent commands and directories are stored in `state.json`, across sessions
|
||||
🏃♂️ Run | Suggestions can have descriptions presented in / alongside the UI
|
||||
🏃♂️ Run | The Suggestions UI can be opened without any nesting
|
||||
🏃♂️ Run | The Suggestions UI can be opened, nested by `source` of the suggestion
|
||||
🚀 Sprint | Extensions can provide suggestion sources for the Suggestions UI
|
||||
🚀 Sprint | The Suggestions UI can be opened in "inline" mode, only showing the text of the first suggestion
|
||||
|
||||
### Elevator Pitch
|
||||
|
||||
The Suggestions UI is a UI element displayed in the Terminal for providing
|
||||
different types of text suggestions to the user - anything from recently run
|
||||
commands, to saved commands, to tab-completion suggestions from the shell
|
||||
itself.
|
||||
|
||||
## Business Justification
|
||||
|
||||
It will delight developers.
|
||||
|
||||
Furthermore, our partners on the Visual Studio team have been requesting similar
|
||||
functionality for some time now. The way autocompletion menus in PowerShell
|
||||
currently interact with UIA clients leaves much to be desired. They'd like a way
|
||||
to provide richer context to screen readers. Something to enable the terminal to
|
||||
more specifically describe the context of what's being presented to the user.
|
||||
|
||||
## Scenario Details
|
||||
|
||||
### UI/UX Design
|
||||
|
||||
#### Prototypes
|
||||
|
||||
The following gif was a VsCode prototype of [shell-driven autocompletion]. This
|
||||
is the point of reference we're starting from when talking about what the
|
||||
suggestions UI might look like.
|
||||
|
||||

|
||||
|
||||
These suggestions are populated by logic within PowerShell itself, and
|
||||
communicated to the Terminal. The Terminal can then display them in the
|
||||
Suggestions UI.
|
||||
|
||||
The following demonstrate a prototype of what that might look like for the
|
||||
Terminal. These are meant to be informative, not normative, representations of
|
||||
what the UI would look like.
|
||||
|
||||

|
||||
|
||||
A prototype of the recent commands UI, powered by shell integration:
|
||||
|
||||

|
||||
|
||||
A prototype of the tasks UI, powered by the user's settings:
|
||||
|
||||

|
||||
|
||||
(admittedly, the `TeachingTip` in that gif is a prototype and was later replaced
|
||||
with a better version.)
|
||||
|
||||
In general, the Suggestions UI will present a list of elements to select from,
|
||||
near the text cursor. This control might be contain a text box for filtering
|
||||
these items (a "**palette**"), or it might not (a "**menu**").
|
||||
|
||||

|
||||
|
||||
#### Palette vs Menu
|
||||
|
||||
Depending on how the suggestions UI is invoked, we may or may not want to
|
||||
display a text box for filtering these suggestions. Consider the Intellisense
|
||||
menu in Visual Studio. That's a UI that only allows for up/down for navigation
|
||||
(and enter/tab for selecting the suggestion).
|
||||
|
||||
For suggestions driven by the Terminal, we'll display a filtering text box in
|
||||
the Suggestions UI. This is similar to the command palette's search - a fuzzy
|
||||
search to filter the contents. This is the "**palette**" style of the
|
||||
suggestions dialog.
|
||||
|
||||
For completions driven by the shell, we should probably not display the
|
||||
filtering text box. This is the "**menu**" style of the suggestion dialog. The
|
||||
user is primarily interacting with the shell here, not the Terminal.
|
||||
|
||||
> **Warning**
|
||||
> TODO! For discussion, possibly with a real UX designer.
|
||||
|
||||
How should we handle completions here? Tab? Enter? Right-Arrow? Should we have
|
||||
an element selected when we open the menu, or should tab/enter only work once
|
||||
the user has used the arrows at least once? Sublime allows for <kbd>tab</kbd> to
|
||||
complete the suggestion immediately.
|
||||
|
||||
Consider also that these suggestions might be provided by the shell, as the user
|
||||
is typing at a commandline shell. For something like PowerShell, the user might
|
||||
want to start typing a command and have it tab-complete based off the shell's
|
||||
tab expansion rules. PowerShell's inline suggestions use right-arrow to
|
||||
differentiate "use this suggestion" vs tab for "tab expand what I'm typing at
|
||||
the prompt". We should probably preserve this behavior.
|
||||
|
||||
We probably don't want to provide different experiences for the **menu** version
|
||||
of the Suggestions UI vs. the **palette** version. In the palette version, the
|
||||
user won't be pressing tab to tab-complete at the shell - the focus is out of
|
||||
the of terminal and in the Suggestions UI. With the menu version, the focus is
|
||||
still "in the terminal", and users would expect tab to tab-complete.
|
||||
|
||||
We will want to make sure that there's some semblance of consistency across our
|
||||
implementation for the Suggestions UI, our own Command Palette, VsCode's
|
||||
intellisense and their own implementation of shell-completions in the Terminal.
|
||||
|
||||
> **Note**
|
||||
> In my prototype, for the "Menu" mode, I accepted ALL of right-arrow, tab, and
|
||||
> enter as "accept completion", and any other key dismissed the UI. This _felt_
|
||||
> right for that mode. I'm not sure we could make the same call for "palette"
|
||||
> mode, where we'd need tab for navigating focus.
|
||||
|
||||
### Implementation Details
|
||||
|
||||
#### Fork the Command Palette
|
||||
|
||||
We're largely going to start with the Command Palette to build the Suggestions
|
||||
UI[[1](#footnote-1)]. The Command Palette is already a control we've built for displaying a
|
||||
transient list of commands and dispatching them to the rest of the app.
|
||||
|
||||
Currently, the Command Palette is a single static control, at the top-center of
|
||||
the Terminal window, and occupying a decent portion of the screen. For the
|
||||
Suggestions UI, we'll instead want to make sure that the control appears
|
||||
relative to the current cursor position.
|
||||
|
||||
We'll start by taking the command palette, and copying it over to a new control.
|
||||
This will allow us to remove large chunks of code dealing with different modes
|
||||
(i.e. the tab switcher), and code dealing with prefix characters to switch
|
||||
modes.
|
||||
|
||||
We'll need to make some small modifications to enable the Suggestions UI to
|
||||
* work as a text cursor-relative control
|
||||
* exist as a Flyout outside the bounds of the Terminal window
|
||||
* If the Suggestions UI is too close to the bottom of the screen, we'll need it to open
|
||||
"upwards", with the search box at the _bottom_ and the list extending above it
|
||||
* prevent it from switching to command-line mode
|
||||
* display tooltips / `TeachingTip`s / some secondary flyout with a description
|
||||
of the suggestion (if provided)
|
||||
|
||||
#### Completion sources
|
||||
|
||||
The Suggestions UI will support suggestions from a variety of different
|
||||
"sources". As an example, consider the following actions:
|
||||
|
||||
```json
|
||||
{ "command": { "action":"suggestions", "source": "commandHistory" } },
|
||||
{ "command": { "action":"suggestions", "source": "directoryHistory" } },
|
||||
|
||||
{ "command": { "action":"suggestions", "source": "tasks" } },
|
||||
{ "command": { "action":"suggestions", "source": "local" } },
|
||||
|
||||
{ "command": { "action":"suggestions", "source": ["local", "tasks", "commandHistory"] } },
|
||||
|
||||
{ "command": { "action":"suggestions", "source": "Microsoft.Terminal.Extensions.BufferComplete" } },
|
||||
```
|
||||
|
||||
Each of these `suggestions` actions would open the Suggestions UI with a
|
||||
different set of actions.
|
||||
|
||||
* `commandHistory`: Use commands from this session, as identified via shell
|
||||
integration. This won't be able to return any suggestions if the user has not
|
||||
configured their shell to support shell integration sequences yet.
|
||||
* `directoryHistory`: Populate the list with a series of `cd {path}` commands,
|
||||
where the paths are populated via shell integration. Paths are in MRU order.
|
||||
* `tasks`: Populate the list with all `sendInput` actions in the user's settings
|
||||
file. The command structure should remain unchanged. For example, if they have
|
||||
`sendInput` actions nested under a "git" command, then the "git" entry will
|
||||
remain in this tasks view with their `sendInput` actions nested inside it. For
|
||||
more details, see the [Tasks] spec.
|
||||
* `local`: Populate the list with tasks that are located in the CWD, in a file
|
||||
named `.wt.json`. For more details, see the [Tasks] spec.
|
||||
* `Microsoft.Terminal.Extensions.BufferComplete`: As an example, this
|
||||
demonstrates how an action might be authored to reference a suggestion source
|
||||
from an extension[[2](#footnote-2)].
|
||||
|
||||
Each of these different sources will build a different set of `Command`s,
|
||||
primarily populated with `sendInput` actions. We'll load those `Command`s into
|
||||
the Suggestions UI control, and open it at the text cursor.
|
||||
|
||||
To drill in on a single example - the `commandHistory` source. In that
|
||||
particular case, the TerminalPage will query the active TermControl for a list
|
||||
of its recent commands. If it knows these (via shell integration), then the
|
||||
TerminalPage will use that list of commands to build a list of `sendInput`
|
||||
actions. Those will then get fed to the suggestions UI.
|
||||
|
||||
Not listed above is [shell-driven autocompletion]. These aren't something that
|
||||
the Terminal can invoke all on its own - these are something the shell would
|
||||
need to invoke themselves.
|
||||
|
||||
#### Pre-populate the current commandline context
|
||||
|
||||
Consider the following scenario. A user has typed `git c` in their shell, and
|
||||
has [shell integration] enabled for their shell. They want to open the
|
||||
Suggestions UI filtered to their recent history, but starting with what they've
|
||||
already typed. To support this scenario, we'll add an additional property:
|
||||
|
||||
* `"useCommandline"`: `bool` (**default**: `true`)
|
||||
* `true`: the current commandline the user has typed will pre-populate the
|
||||
filter of the Suggestions UI. This requires that the user has enabled shell
|
||||
integration in their shell's config.
|
||||
* `false`: the filter will start empty, regardless of what the user has typed.
|
||||
|
||||
With that setting, the user can achieve their desired UX with the following action:
|
||||
|
||||
```json
|
||||
{ "command": { "action":"suggestions", "source": "commandHistory", "useCommandline": true } },
|
||||
```
|
||||
|
||||
Now, when they type `git c` and invoke the Suggestions UI, they can immediately
|
||||
start searching for recent commands that started with `git c`.
|
||||
|
||||
The primary use case for `useCommandline: false` was for `"nesting": "source"`.
|
||||
When filtering a list of ["Tasks...", "Recent commands...", "Recent
|
||||
directories...", "Docker...", "Git..."], then there's minimal value to start by
|
||||
filtering to "git c".
|
||||
|
||||
#### Default actions
|
||||
|
||||
I propose adding the following actions to the Terminal by default:
|
||||
|
||||
```json
|
||||
{ "command": { "action":"suggestions", "source": "commandHistory", "useCommandline": true } },
|
||||
{ "command": { "action":"suggestions", "source": "directoryHistory" } },
|
||||
{ "command": { "action":"suggestions", "source": ["local", "tasks", "commandHistory"], "useCommandline": true, "nesting": "disabled" } },
|
||||
{ "command": { "action":"suggestions", "source": ["all"], "useCommandline": false, "nesting": "source" } },
|
||||
```
|
||||
|
||||
These actions are colloquially:
|
||||
* Give me suggestions from my recent commands, using what I've typed
|
||||
* Give me suggestions of directories I've recently been in
|
||||
* _(After [Tasks] are implemented)_ Give me suggestions from recent commands,
|
||||
commands I've saved, and commands for this project. Don't nest any, so they're
|
||||
all in the top-level menu. Use what I've typed already to start filtering.
|
||||
* Just open the Suggestions UI with all suggestions sources, and group them by
|
||||
the source of the suggestions.
|
||||
|
||||
This should cover most of the basic use cases for suggestions.
|
||||
|
||||
#### Who owns this menu?
|
||||
|
||||
There was some discussion of who should own the suggestions menu. The control
|
||||
itself? Or the app hosting the control?
|
||||
|
||||
A main argument for hosting this UI in the control itself is that any consumer
|
||||
of the `TermControl` should be able to display the [shell-driven autocompletion]
|
||||
menu. And they should get the UI from us "for free". Consumers shouldn't need to
|
||||
reimplement it themselves. This probably could be done without many changes:
|
||||
* Instead of operating on `Command`s and actions from the terminal settings,
|
||||
the control could just know that all the entries in the menu are "send
|
||||
input" "actions".
|
||||
* The control could offer a method to manually invoke the Suggestions UI for a
|
||||
list of {suggestion, name, description} objects.
|
||||
* The app layer could easily translate between sendInput actions and these
|
||||
pseudo-actions.
|
||||
|
||||
A big argument in favor of having the app layer host the control: Consider an
|
||||
app like Visual Studio. When they embed the control, they'll want to style the
|
||||
shell-completions UI in their own way. They already have their own intellisense
|
||||
menu, and their own UI paradigm.
|
||||
|
||||
For now, we'll leave this as something that's owned by the app layer. When we
|
||||
get around to finalizing the [shell-driven autocompletion] design, we can
|
||||
iterate on ideas for supporting both consumers that want to use a pre-built
|
||||
suggestions control, or consumers who want to bring their own.
|
||||
|
||||
## Tenets
|
||||
|
||||
<table>
|
||||
|
||||
<tr><td><strong>Compatibility</strong></td><td>
|
||||
|
||||
This shouldn't break any existing flows. This is a general purpose UI element,
|
||||
to be extended in a variety of ways. Those customizations will all be opt-in by
|
||||
the user, so I'm not expecting any breaking compatibility changes here.
|
||||
|
||||
</td></tr>
|
||||
|
||||
<tr><td><strong>Accessibility</strong></td><td>
|
||||
|
||||
The Suggestions UI was designed with the goal of making commandline shell
|
||||
suggestions _more_ accessible. As Carlos previously wrote:
|
||||
|
||||
> Screen readers struggle with this because the entire menu is redrawn every time, making it harder to understand what exactly is "selected" (as the concept of selection in this instance is a shell-side concept represented by visual manipulation).
|
||||
>
|
||||
> ...
|
||||
>
|
||||
> _\[Shell driven suggestions\]_ can then be leveraged by Windows Terminal to create UI elements. Doing so leverages WinUI's accessible design.
|
||||
|
||||
This will allow the Terminal to provide more context-relevant information to
|
||||
screen readers.
|
||||
|
||||
</td></tr>
|
||||
|
||||
<tr><td><strong>Sustainability</strong></td><td>
|
||||
|
||||
No sustainability changes expected.
|
||||
|
||||
</td></tr>
|
||||
|
||||
<tr><td><strong>Localization</strong></td><td>
|
||||
|
||||
The localization needs of the Suggestions UI will be effectively the same as the
|
||||
needs of the Command Palette.
|
||||
|
||||
The Terminal will have no way to localize suggestions that are provided via
|
||||
[shell-driven autocompletion]. These are just verbatim strings that the shell
|
||||
told us to use. We don't consider this to be something to worry about, however.
|
||||
This is no different than the fact that Terminal cannot localize the `Get-Help`
|
||||
(or any other) output of PowerShell.
|
||||
|
||||
</td></tr>
|
||||
|
||||
</table>
|
||||
|
||||
## Implementation Plan
|
||||
|
||||
This is more of an informative outline, rather than a normative one. Many of the
|
||||
things from Crawl, Walk, and Run are all already in PRs as of the time of this
|
||||
spec's review.
|
||||
|
||||
### 🐣 Crawl
|
||||
|
||||
* [ ] Fork the Command palette to a new UI element, the `SuggestionsControl`
|
||||
* [ ] Enable previewing `sendInput` actions in the Command Palette and `SuggestionsControl`
|
||||
* [ ] Enable the `SuggestionsControl` to open top-down (aligned to the bottom of the cursor row) or bottom-up (aligned to the top of the cursor row).
|
||||
* [ ] Disable sorting on the `SuggestionsControl` - elements should presumably be pre-sorted by the source.
|
||||
* [ ] Expose the recent commands as a accessor on `TermControl`
|
||||
* [ ] Add a `suggestions` action which accepts a single option `recentCommands`. These should be fed in MRU order to the `SuggestionsControl`.
|
||||
* [ ] Expose the recent directories as an accessor on `TermControl`, and add a `recentDirectories` source.
|
||||
|
||||
### 🚶 Walk
|
||||
|
||||
* [ ] Add a `tasks` source to `suggestions` which opens the Suggestions UI with
|
||||
a tree of all `sendInput` commands
|
||||
* [ ] Enable the `SuggestionsControl` to open with or without a search box
|
||||
* [ ] Plumb support for shell-driven completions through the core up to the app
|
||||
* [ ] Expose the _current_ commandline from the `TermControl`
|
||||
* [ ] Add a `useCommandline` property to `suggestions`, to pre-populate the search with the current commandline.
|
||||
* [ ] Persist recent commands / directories accordingly
|
||||
|
||||
### 🏃♂️ Run
|
||||
|
||||
* [ ] Add a `description` field to `Command`
|
||||
* [ ] Add a `TeachingTip` (or similar) to the Suggestions UI to display
|
||||
descriptions (when available)
|
||||
* [ ] Use the `ToolTip` property of shell-driven suggestions as the description
|
||||
* [ ] Add a boolean `nesting` property which can be used to disable nesting on the `tasks` source.
|
||||
* [ ] Add the ability for `nesting` to accept `enabled`/`disabled` as `true`/`false` equivalents
|
||||
* [ ] Add the ability for `nesting` to accept `source`, which instead groups all
|
||||
commands to the Suggestions UI by the source of that suggestion.
|
||||
|
||||
### 🚀 Sprint
|
||||
|
||||
The two "sprint" tasks here are much more ambitious than the other listed
|
||||
scenarios, so breaking them down to atomic tasks sees less reasonable. We'd have
|
||||
to spend a considerable amount more time figuring out _how_ to do each of these
|
||||
first.
|
||||
|
||||
For example - extensions. We have yet to fully realize what extensions _are_.
|
||||
Determining how extensions will provide suggestions is left as something we'll
|
||||
need to do as a part of the Extensions spec.
|
||||
|
||||
## Conclusion
|
||||
|
||||
Here's a sample json schema for the settings discussed here.
|
||||
|
||||
```json
|
||||
"OpenSuggestionsAction": {
|
||||
"description": "Arguments corresponding to a Open Suggestions Action",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/$defs/ShortcutAction"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"const": "suggestions"
|
||||
},
|
||||
"source": {
|
||||
"$ref": "#/$defs/SuggestionSource",
|
||||
"description": "Which suggestion sources to filter."
|
||||
},
|
||||
"useCommandline": {
|
||||
"default": false,
|
||||
"description": "When set to `true`, the current commandline the user has typed will pre-populate the filter of the Suggestions UI. This requires that the user has enabled shell integration in their shell's config. When set to false, the filter will start empty."
|
||||
},
|
||||
"nesting": {
|
||||
"default": true,
|
||||
"description": "When set to `true`, suggestions will follow the provided nesting structure. For Tasks, these will follow the structure of the Command Palette. When set to `false`, no nesting will be used (and all suggestions will be in the top-level menu.",
|
||||
"$comment": "This setting is a possible follow-up setting, not required for v1. "
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"BuiltinSuggestionSource": {
|
||||
"enum": [
|
||||
"commandHistory",
|
||||
"directoryHistory",
|
||||
"tasks",
|
||||
"local",
|
||||
"all"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"SuggestionSource": {
|
||||
"default": "all",
|
||||
"description": "Either a single suggestion source, or an array of sources to concatenate. Built-in sources include `commandHistory`, `directoryHistory`, `tasks`, and `local`. Extensions may provide additional values. The special value `all` indicates all suggestion sources should be included",
|
||||
"$comment": "`tasks` and `local` are sources that would be added by the Tasks feature, as a follow-up"
|
||||
"oneOf": [
|
||||
{
|
||||
"type": [ "string", "null", "BuiltinSuggestionSource" ]
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": { "type": "BuiltinSuggestionSource" }
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
}
|
||||
]
|
||||
},
|
||||
```
|
||||
|
||||
### Future Considerations
|
||||
|
||||
* Another extension idea: `WithFig.FigCompletions`. Imagine an extension that
|
||||
could parse existing [Fig] completion specs, and provide those as suggestions
|
||||
in this way.
|
||||
* This might be a good example of an async suggestion source. The current
|
||||
commandline is used as the starting filter, and the suggestions would be
|
||||
populated by some `fig` process / thread / async operation that returns the
|
||||
suggestions.
|
||||
* If the user hasn't enabled shell completion, we could add text to the
|
||||
`commandHistory` or `directoryHistory` menus to inform the user how they could
|
||||
go enable shell integration. We already have a docs page dedicated to this, so
|
||||
we could start by linking to that page. More notes on this in [Automatic shell
|
||||
integration](#Automatic-shell-integration).
|
||||
* Maybe there could be a per-profile setting for automatic suggestions after
|
||||
some timeout. Like, as you type, a menu version of the Suggestions UI appears.
|
||||
So you could just start typing `git c`, and it would automatically give you a
|
||||
menu with suggestions, implicitly using the typed command as the "filter".
|
||||
* Maybe we could do this as an `implicit` property on the `suggestions` action
|
||||
|
||||
|
||||
#### Description Tooltips
|
||||
|
||||
> **Note**: _This is left as a future consideration for the initial draft of
|
||||
> this spec. I'd like to flesh out [shell-driven autocompletion] more before
|
||||
> committing any plans here._
|
||||
|
||||
It would be beneficial for the Suggestions UI to display additional context to
|
||||
the user. Consider a extension that provides some commands for the user, like a
|
||||
hypothetical "Docker" extension. The extension author might be able to give the
|
||||
commands simplified names, but also want to expose a more detailed description
|
||||
of the commands to the user.
|
||||
|
||||
Or consider the Suggestions UI when invoked by [shell-driven autocompletion].
|
||||
The shell might want to provide help text to the user with each of the
|
||||
suggestions. This would allow a user to browse through the suggestions that they
|
||||
might not know about, and learn how they work before committing to one.
|
||||
|
||||
Only the help text for the currently hovered command should be presented to the
|
||||
user. To support this kind of UX, we'll add an optional flyout of some sort to
|
||||
display with the Suggestions UI. This flyout will only appear if there's more
|
||||
information provided to the Terminal.
|
||||
|
||||
This might be in the form of a `TeachingTip`, as in this example:
|
||||
|
||||

|
||||
|
||||
Actions in the settings could also accept an optional `description` property, to
|
||||
specify the string that would be presented in that flyout.
|
||||
|
||||
#### Automatic shell integration
|
||||
|
||||
A large portion of these features all rely on shell integration being enabled by
|
||||
the user. However, this is not a trivial thing for the Terminal to do on behalf
|
||||
of the user. Shell integration relies on changes to the user's shell config. If
|
||||
the Terminal were to try and configure those itself, we may accidentally destroy
|
||||
configuration that the user has already set up. Hence why the Terminal can't
|
||||
just have a "Light up all the bells and whistles" toggle in the Settings UI.
|
||||
|
||||
This is a non-trivial problem to solve, so it is being left as a future
|
||||
consideration, for a later spec. It deserves its own spec to sort out how we
|
||||
should expose this to users and safely implement it.
|
||||
|
||||
#### Pre-filtering the UI & filter by source
|
||||
|
||||
> **Note**: _This is a brainstorm I considered while writing this spec. I would
|
||||
> not include it in the v1 of this spec. Rather, I'd like to leave it for
|
||||
> where we might go with this UX in the future._
|
||||
|
||||
Do want to support different _types_ of nesting? So instead of just the default,
|
||||
there could be something like `nesting: "source"`, to create a menu structured
|
||||
like:
|
||||
|
||||
```
|
||||
Suggestions UI
|
||||
├─ Recent Commands...
|
||||
│ ├─ git checkout main
|
||||
│ ├─ git fetch
|
||||
│ └─ git pull
|
||||
├─ Recent Directories...
|
||||
│ ├─ d:\dev
|
||||
│ ├─ d:\dev\public
|
||||
│ └─ d:\dev\public\terminal
|
||||
├─ Saved tasks...
|
||||
│ ├─ Git...
|
||||
│ │ └─ git commit -m "
|
||||
│ │ └─ git log...
|
||||
│ └─ bx & runut
|
||||
└─ Docker
|
||||
├─ docker build --platform linux/amd64 <path>
|
||||
└─ docker logs -f --tail <lines_count> <container_name>
|
||||
```
|
||||
|
||||
> **Note**
|
||||
> I'm using `Docker` as an example fragment extension that provides
|
||||
> some `docker` commands. When grouping by `"source"`, we could pull those into
|
||||
> a separate top-level entry. When not grouping by `"source"`, those would still
|
||||
> show up with the rest of `tasks`. )
|
||||
|
||||
#### Store recent commands across sessions
|
||||
|
||||
> **Note**
|
||||
> _I'm not sure we really want to put this in this spec or not, hence
|
||||
> why it is in the "Future considerations" section. I think it is worth
|
||||
> mentioning. This might be better served in the [shell integration] doc._
|
||||
|
||||
We'll probably want a way for recent commands to be saved across sessions. That way, your `cmd.exe` command history could persist across sessions. We'd need:
|
||||
|
||||
* A setting to enable this behavior
|
||||
* A setting to control the context of these saved commandlines.
|
||||
* Do we want them saved per-profile, or globally?
|
||||
* If they're saved per-profile, maybe a profile can opt-in to loading all the commands?
|
||||
* How does defterm play with this? Do we "layer" by concatenating per-profile commands with `profiles.defaults` ones?
|
||||
* A button in the Settings UI for clearing these commands
|
||||
* Should fragments be able to pre-populate "recent commands"?
|
||||
* I'm just gonna say _no_. That would be a better idea for Tasks (aka just a `sendInput` Action that we load from the fragment normally as a Task), or a specific suggestion source for the fragment extension.
|
||||
|
||||
#### Inline mode
|
||||
|
||||
> **Note**
|
||||
> _This is a half-baked idea with some potential. However, I don't
|
||||
> think it needs to be a part of the v1 of the Suggestions UI, so I'm leaving it
|
||||
> under future considerations for a future revision._
|
||||
|
||||
Do we want to have a suggestions UI "mode", that's just **one** inline
|
||||
suggestion, "no" UI? Some UX ala the `PsReadline` recent command suggestion
|
||||
feature. Imagine, we just display the IME ghost text thing for the first result,
|
||||
given the current prompt?
|
||||
|
||||
Take the following action as an example:
|
||||
|
||||
```json
|
||||
{ "command": { "action":"suggestions", "source": "commandHistory", "useCommandline": true, "inline": true } },
|
||||
```
|
||||
|
||||
Type the start of some command at the prompt, and press that key. Presto, we do
|
||||
the `pwsh` thing. Ghost text appears for the first match in the `commandHistory`
|
||||
for what the user has typed. If they press another key, ~they've typed into the
|
||||
"hidden" Suggestions UI, which filters the (hidden) list more, and updates the
|
||||
one inline suggestion.~
|
||||
|
||||
Or, instead, typed keys go to the shell, and then we re-query the commandline,
|
||||
and update the filter accordingly. That would allow tab-completion to still
|
||||
work. We'd use <kbd>right arrow</kbd> to accept the suggestion (and dismiss the
|
||||
ghost text preview).
|
||||
|
||||
This would seemingly SUPER conflict with PowerShell's own handler. Probably not
|
||||
something someone should enable for PowerShell 7 profiles if they're using that
|
||||
feature.
|
||||
|
||||
### Rejected ideas
|
||||
|
||||
These are musings from earlier versions of the spec.
|
||||
* **Asynchronous prompting**: This was rejected because it was so fundamentally
|
||||
different from the rest of the UX of the Suggestions UI, it didn't make sense
|
||||
to try and also do that behavior.
|
||||
* ...
|
||||
|
||||
#### REJECTED: Asynchronous prompting
|
||||
|
||||
Certain suggestion sources might want to provide results asynchronously.
|
||||
Consider a source that might want to make a web request to populate what strings
|
||||
to suggest. That source might want to prompt the user for input first, then
|
||||
dispatch the request, then populate the UI. Or something like a `fig`-like
|
||||
suggestion source, which would need to parse some files from the disk to
|
||||
generate the list of suggestions.
|
||||
|
||||
The easiest way to do this would be to provide a secondary UI element for
|
||||
prompting the user for input, doing the request in the background, then opening
|
||||
the UI later. However, that feels a little disjointed. Could we instead provide
|
||||
a more continuous experience?
|
||||
|
||||
The following is a proposal for using the Suggestions UI itself as the control
|
||||
to prompt the user for input.
|
||||
|
||||
```c++
|
||||
TerminalPage::SetUpSuggestionsUI()
|
||||
{
|
||||
const auto& asyncSource{ AsyncSuggestions() };
|
||||
|
||||
suggestionsUI.OnInputChanged({ asyncSource, AsyncSuggestions::InputChangedHandler});
|
||||
// In this example, we don't want the UI to filter item based on the input
|
||||
// string - the source has already determined the list of relevant matches.
|
||||
suggestionsUI.FilterByInput(false);
|
||||
|
||||
asyncSource.SuggestionsChanged([](const auto& newCommands){
|
||||
suggestionsUI.Loading(false);
|
||||
suggestionsUI.Commands(newCommands);
|
||||
})
|
||||
}
|
||||
|
||||
void AsyncSuggestions::InputChangedHandler(FilterChangedArgs args)
|
||||
{
|
||||
// kick off a trailing ThrottledFunc to do a new query
|
||||
_loadNewResults->Run(args.NewInputText());
|
||||
// If we get another request, we might want to cancel the pending throttled
|
||||
// func entirely, and start the timeout fresh. Just so that we only make a
|
||||
// query for the final string they type.
|
||||
|
||||
args.RequestLoading(true); // pass a boolean back up in the args, so that
|
||||
// the Suggestions UI can clear out the current commands, and start displaying an
|
||||
// indeterminate progress wheel.
|
||||
}
|
||||
```
|
||||
|
||||
That would basically _have_ to be special cased for this source, at least for
|
||||
now. We could refactor that later to better deal with extensions.
|
||||
|
||||
Let's make sure this would work for something `fig`-like, where the "prompt" is
|
||||
literally the prompt, what the user has already typed at the commandline.
|
||||
|
||||
After some discussion:
|
||||
* How do we differentiate the prompting version of the Suggestions UI from the
|
||||
filtering version?
|
||||
* The prompting version _doesn't_ filter results
|
||||
* Async modes wouldn't work with sync ones at all. E.g. if you did `source:
|
||||
["tasks", "myAsyncSource"]`. It doesn't make sense to start with a list of
|
||||
`tasks`, then type, find no tasks, but then oh! the UI fills in some other
|
||||
suggestions too. That's weird.
|
||||
|
||||
## Resources
|
||||
|
||||
These are some other work streams that have a lot of tie-in to the Suggestions
|
||||
UI. These are all being spec'd at roughly the same time, so links may not be
|
||||
fully up to date.
|
||||
* [Shell integration]
|
||||
* [Shell-driven autocompletion]
|
||||
* [Tasks]
|
||||
|
||||
### Footnotes
|
||||
|
||||
<a name="footnote-1"><a>[1]: We've had discussion in the past ([#7285]) about
|
||||
possibly creating a more abstract "Live filtering list view" to replace the
|
||||
Command Palette. We could most certainly use that here too. We've decided to
|
||||
initially go with a fork for now.
|
||||
|
||||
<a name="footnote-2"><a>[2]: Obviously, we're not having a real discussion about
|
||||
extensions in this doc. This example is solely to show that there's room for
|
||||
extensions to work with the "source" property in this design. What the final
|
||||
shape of extensions will be is very much still to be determined.
|
||||
|
||||
|
||||
[Fig]: https://github.com/withfig/autocomplete
|
||||
[Warp]: https://www.warp.dev/
|
||||
[workflows]: https://docs.warp.dev/features/workflows
|
||||
[also working on workflows]: https://fig.io/user-manual/workflows
|
||||
[winget script]: https://github.com/microsoft/PowerToys/blob/main/.github/workflows/package-submissions.yml
|
||||
[#1595]: https://github.com/microsoft/terminal/issues/1595
|
||||
[#7039]: https://github.com/microsoft/terminal/issues/7039
|
||||
[#3121]: https://github.com/microsoft/terminal/issues/3121
|
||||
[#10436]: https://github.com/microsoft/terminal/issues/10436
|
||||
[#12927]: https://github.com/microsoft/terminal/issues/12927
|
||||
[#12863]: https://github.com/microsoft/terminal/issues/12863
|
||||
[#7285]: https://github.com/microsoft/terminal/issues/7285
|
||||
[#14939]: https://github.com/microsoft/terminal/issues/7285
|
||||
|
||||
[#keep]: https://github.com/zadjii/keep
|
||||
[VsCode Tasks]: https://github.com/microsoft/terminal/blob/main/.vscode/tasks.json
|
||||
|
||||
<!-- Note: This is its own spec in progress, but for the time being #12862 will do -->
|
||||
[Tasks]: https://github.com/microsoft/terminal/issues/12862
|
||||
<!-- Note: This is just a link to the PR that introduced the shell integration spec -->
|
||||
[shell integration]: https://github.com/microsoft/terminal/pull/14792
|
||||
<!-- Note: If I ever write a spec for this, go ahead and replace this link -->
|
||||
[shell-driven autocompletion]: https://github.com/microsoft/terminal/issues/3121
|
||||
BIN
doc/specs/#1595 - Suggestions UI/command-history-suggestions.gif
Normal file
BIN
doc/specs/#1595 - Suggestions UI/command-history-suggestions.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 965 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
BIN
doc/specs/#1595 - Suggestions UI/tasks-suggestions.gif
Normal file
BIN
doc/specs/#1595 - Suggestions UI/tasks-suggestions.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
BIN
doc/specs/#1595 - Suggestions UI/vscode-shell-suggestions.gif
Normal file
BIN
doc/specs/#1595 - Suggestions UI/vscode-shell-suggestions.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 431 KiB |
@@ -152,11 +152,15 @@ til::CoordType CharToColumnMapper::GetTrailingColumnAt(ptrdiff_t offset) noexcep
|
||||
return col;
|
||||
}
|
||||
|
||||
// If given a pointer inside the ROW's text buffer, this function will return the corresponding column.
|
||||
// This function in particular returns the glyph's first column.
|
||||
til::CoordType CharToColumnMapper::GetLeadingColumnAt(const wchar_t* str) noexcept
|
||||
{
|
||||
return GetLeadingColumnAt(str - _chars);
|
||||
}
|
||||
|
||||
// If given a pointer inside the ROW's text buffer, this function will return the corresponding column.
|
||||
// This function in particular returns the glyph's last column (this matters for wide glyphs).
|
||||
til::CoordType CharToColumnMapper::GetTrailingColumnAt(const wchar_t* str) noexcept
|
||||
{
|
||||
return GetTrailingColumnAt(str - _chars);
|
||||
@@ -364,11 +368,16 @@ void ROW::TransferAttributes(const til::small_rle<TextAttribute, uint16_t, 1>& a
|
||||
|
||||
void ROW::CopyFrom(const ROW& source)
|
||||
{
|
||||
RowCopyTextFromState state{ .source = source };
|
||||
CopyTextFrom(state);
|
||||
TransferAttributes(source.Attributes(), _columnCount);
|
||||
_lineRendition = source._lineRendition;
|
||||
_wrapForced = source._wrapForced;
|
||||
|
||||
RowCopyTextFromState state{
|
||||
.source = source,
|
||||
.sourceColumnLimit = source.GetReadableColumnCount(),
|
||||
};
|
||||
CopyTextFrom(state);
|
||||
|
||||
TransferAttributes(source.Attributes(), _columnCount);
|
||||
}
|
||||
|
||||
// Returns the previous possible cursor position, preceding the given column.
|
||||
@@ -382,7 +391,17 @@ til::CoordType ROW::NavigateToPrevious(til::CoordType column) const noexcept
|
||||
// Returns the row width if column is beyond the width of the row.
|
||||
til::CoordType ROW::NavigateToNext(til::CoordType column) const noexcept
|
||||
{
|
||||
return _adjustForward(_clampedColumn(column + 1));
|
||||
return _adjustForward(_clampedColumnInclusive(column + 1));
|
||||
}
|
||||
|
||||
// Returns the starting column of the glyph at the given column.
|
||||
// In other words, if you have 3 wide glyphs
|
||||
// AA BB CC
|
||||
// 01 23 45 <-- column
|
||||
// then `AdjustToGlyphStart(3)` returns 2.
|
||||
til::CoordType ROW::AdjustToGlyphStart(til::CoordType column) const noexcept
|
||||
{
|
||||
return _adjustBackward(_clampedColumn(column));
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
@@ -719,11 +738,12 @@ try
|
||||
if (sourceColBeg < sourceColLimit)
|
||||
{
|
||||
charOffsets = source._charOffsets.subspan(sourceColBeg, static_cast<size_t>(sourceColLimit) - sourceColBeg + 1);
|
||||
const auto charsOffset = charOffsets.front() & CharOffsetsMask;
|
||||
const auto beg = size_t{ charOffsets.front() } & CharOffsetsMask;
|
||||
const auto end = size_t{ charOffsets.back() } & CharOffsetsMask;
|
||||
// We _are_ using span. But C++ decided that string_view and span aren't convertible.
|
||||
// _chars is a std::span for performance and because it refers to raw, shared memory.
|
||||
#pragma warning(suppress : 26481) // Don't use pointer arithmetic. Use span instead (bounds.1).
|
||||
chars = { source._chars.data() + charsOffset, source._chars.size() - charsOffset };
|
||||
chars = { source._chars.data() + beg, end - beg };
|
||||
}
|
||||
|
||||
WriteHelper h{ *this, state.columnBegin, state.columnLimit, chars };
|
||||
@@ -939,6 +959,16 @@ til::CoordType ROW::MeasureLeft() const noexcept
|
||||
|
||||
til::CoordType ROW::MeasureRight() const noexcept
|
||||
{
|
||||
if (_wrapForced)
|
||||
{
|
||||
auto width = _columnCount;
|
||||
if (_doubleBytePadded)
|
||||
{
|
||||
width--;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
const auto text = GetText();
|
||||
const auto beg = text.begin();
|
||||
const auto end = text.end();
|
||||
|
||||
@@ -136,6 +136,7 @@ public:
|
||||
|
||||
til::CoordType NavigateToPrevious(til::CoordType column) const noexcept;
|
||||
til::CoordType NavigateToNext(til::CoordType column) const noexcept;
|
||||
til::CoordType AdjustToGlyphStart(til::CoordType column) const noexcept;
|
||||
|
||||
void ClearCell(til::CoordType column);
|
||||
OutputCellIterator WriteCells(OutputCellIterator it, til::CoordType columnBegin, std::optional<bool> wrap = std::nullopt, std::optional<til::CoordType> limitRight = std::nullopt);
|
||||
|
||||
@@ -8,30 +8,21 @@
|
||||
|
||||
using namespace Microsoft::Console::Types;
|
||||
|
||||
bool Search::ResetIfStale(Microsoft::Console::Render::IRenderData& renderData)
|
||||
{
|
||||
return ResetIfStale(renderData,
|
||||
_needle,
|
||||
_step == -1, // this is the opposite of the initializer below
|
||||
_caseInsensitive);
|
||||
}
|
||||
|
||||
bool Search::ResetIfStale(Microsoft::Console::Render::IRenderData& renderData, const std::wstring_view& needle, bool reverse, bool caseInsensitive)
|
||||
{
|
||||
const auto& textBuffer = renderData.GetTextBuffer();
|
||||
const auto lastMutationId = textBuffer.GetLastMutationId();
|
||||
|
||||
if (_needle == needle &&
|
||||
_reverse == reverse &&
|
||||
_caseInsensitive == caseInsensitive &&
|
||||
_lastMutationId == lastMutationId)
|
||||
{
|
||||
_step = reverse ? -1 : 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
_renderData = &renderData;
|
||||
_needle = needle;
|
||||
_reverse = reverse;
|
||||
_caseInsensitive = caseInsensitive;
|
||||
_lastMutationId = lastMutationId;
|
||||
|
||||
@@ -42,14 +33,40 @@ bool Search::ResetIfStale(Microsoft::Console::Render::IRenderData& renderData, c
|
||||
return true;
|
||||
}
|
||||
|
||||
void Search::MovePastCurrentSelection()
|
||||
void Search::MoveToCurrentSelection()
|
||||
{
|
||||
if (_renderData->IsSelectionActive())
|
||||
{
|
||||
MovePastPoint(_renderData->GetTextBuffer().ScreenToBufferPosition(_renderData->GetSelectionAnchor()));
|
||||
MoveToPoint(_renderData->GetTextBuffer().ScreenToBufferPosition(_renderData->GetSelectionAnchor()));
|
||||
}
|
||||
}
|
||||
|
||||
void Search::MoveToPoint(const til::point anchor) noexcept
|
||||
{
|
||||
if (_results.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto count = gsl::narrow_cast<ptrdiff_t>(_results.size());
|
||||
ptrdiff_t index = 0;
|
||||
|
||||
if (_step < 0)
|
||||
{
|
||||
for (index = count - 1; index >= 0 && til::at(_results, index).start > anchor; --index)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (index = 0; index < count && til::at(_results, index).start < anchor; ++index)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
_index = (index + count) % count;
|
||||
}
|
||||
|
||||
void Search::MovePastPoint(const til::point anchor) noexcept
|
||||
{
|
||||
if (_results.empty())
|
||||
@@ -58,18 +75,17 @@ void Search::MovePastPoint(const til::point anchor) noexcept
|
||||
}
|
||||
|
||||
const auto count = gsl::narrow_cast<ptrdiff_t>(_results.size());
|
||||
const auto highestIndex = count - 1;
|
||||
auto index = _reverse ? highestIndex : 0;
|
||||
ptrdiff_t index = 0;
|
||||
|
||||
if (_reverse)
|
||||
if (_step < 0)
|
||||
{
|
||||
for (; index >= 0 && til::at(_results, index).start >= anchor; --index)
|
||||
for (index = count - 1; index >= 0 && til::at(_results, index).start >= anchor; --index)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; index <= highestIndex && til::at(_results, index).start <= anchor; ++index)
|
||||
for (index = 0; index < count && til::at(_results, index).start <= anchor; ++index)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -119,7 +135,7 @@ const std::vector<til::point_span>& Search::Results() const noexcept
|
||||
return _results;
|
||||
}
|
||||
|
||||
size_t Search::CurrentMatch() const noexcept
|
||||
ptrdiff_t Search::CurrentMatch() const noexcept
|
||||
{
|
||||
return _index;
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ class Search final
|
||||
public:
|
||||
Search() = default;
|
||||
|
||||
bool ResetIfStale(Microsoft::Console::Render::IRenderData& renderData);
|
||||
bool ResetIfStale(Microsoft::Console::Render::IRenderData& renderData, const std::wstring_view& needle, bool reverse, bool caseInsensitive);
|
||||
|
||||
void MovePastCurrentSelection();
|
||||
void MoveToCurrentSelection();
|
||||
void MoveToPoint(til::point anchor) noexcept;
|
||||
void MovePastPoint(til::point anchor) noexcept;
|
||||
void FindNext() noexcept;
|
||||
|
||||
@@ -36,14 +36,12 @@ public:
|
||||
bool SelectCurrent() const;
|
||||
|
||||
const std::vector<til::point_span>& Results() const noexcept;
|
||||
size_t CurrentMatch() const noexcept;
|
||||
bool CurrentDirection() const noexcept;
|
||||
ptrdiff_t CurrentMatch() const noexcept;
|
||||
|
||||
private:
|
||||
// _renderData is a pointer so that Search() is constexpr default constructable.
|
||||
Microsoft::Console::Render::IRenderData* _renderData = nullptr;
|
||||
std::wstring _needle;
|
||||
bool _reverse = false;
|
||||
bool _caseInsensitive = false;
|
||||
uint64_t _lastMutationId = 0;
|
||||
|
||||
|
||||
@@ -806,9 +806,9 @@ void TextBuffer::IncrementCircularBuffer(const TextAttribute& fillAttributes)
|
||||
// - The viewport
|
||||
//Return value:
|
||||
// - Coordinate position (relative to the text buffer)
|
||||
til::point TextBuffer::GetLastNonSpaceCharacter(std::optional<const Microsoft::Console::Types::Viewport> viewOptional) const
|
||||
til::point TextBuffer::GetLastNonSpaceCharacter(const Viewport* viewOptional) const
|
||||
{
|
||||
const auto viewport = viewOptional.has_value() ? viewOptional.value() : GetSize();
|
||||
const auto viewport = viewOptional ? *viewOptional : GetSize();
|
||||
|
||||
til::point coordEndOfText;
|
||||
// Search the given viewport by starting at the bottom.
|
||||
@@ -1070,46 +1070,40 @@ void TextBuffer::Reset() noexcept
|
||||
// - newSize - new size of screen.
|
||||
// Return Value:
|
||||
// - Success if successful. Invalid parameter if screen buffer size is unexpected. No memory if allocation failed.
|
||||
[[nodiscard]] NTSTATUS TextBuffer::ResizeTraditional(til::size newSize) noexcept
|
||||
void TextBuffer::ResizeTraditional(til::size newSize)
|
||||
{
|
||||
// Guard against resizing the text buffer to 0 columns/rows, which would break being able to insert text.
|
||||
newSize.width = std::max(newSize.width, 1);
|
||||
newSize.height = std::max(newSize.height, 1);
|
||||
|
||||
try
|
||||
TextBuffer newBuffer{ newSize, _currentAttributes, 0, false, _renderer };
|
||||
const auto cursorRow = GetCursor().GetPosition().y;
|
||||
const auto copyableRows = std::min<til::CoordType>(_height, newSize.height);
|
||||
til::CoordType srcRow = 0;
|
||||
til::CoordType dstRow = 0;
|
||||
|
||||
if (cursorRow >= newSize.height)
|
||||
{
|
||||
TextBuffer newBuffer{ newSize, _currentAttributes, 0, false, _renderer };
|
||||
const auto cursorRow = GetCursor().GetPosition().y;
|
||||
const auto copyableRows = std::min<til::CoordType>(_height, newSize.height);
|
||||
til::CoordType srcRow = 0;
|
||||
til::CoordType dstRow = 0;
|
||||
|
||||
if (cursorRow >= newSize.height)
|
||||
{
|
||||
srcRow = cursorRow - newSize.height + 1;
|
||||
}
|
||||
|
||||
for (; dstRow < copyableRows; ++dstRow, ++srcRow)
|
||||
{
|
||||
newBuffer.GetMutableRowByOffset(dstRow).CopyFrom(GetRowByOffset(srcRow));
|
||||
}
|
||||
|
||||
// NOTE: Keep this in sync with _reserve().
|
||||
_buffer = std::move(newBuffer._buffer);
|
||||
_bufferEnd = newBuffer._bufferEnd;
|
||||
_commitWatermark = newBuffer._commitWatermark;
|
||||
_initialAttributes = newBuffer._initialAttributes;
|
||||
_bufferRowStride = newBuffer._bufferRowStride;
|
||||
_bufferOffsetChars = newBuffer._bufferOffsetChars;
|
||||
_bufferOffsetCharOffsets = newBuffer._bufferOffsetCharOffsets;
|
||||
_width = newBuffer._width;
|
||||
_height = newBuffer._height;
|
||||
|
||||
_SetFirstRowIndex(0);
|
||||
srcRow = cursorRow - newSize.height + 1;
|
||||
}
|
||||
CATCH_RETURN();
|
||||
|
||||
return S_OK;
|
||||
for (; dstRow < copyableRows; ++dstRow, ++srcRow)
|
||||
{
|
||||
newBuffer.GetMutableRowByOffset(dstRow).CopyFrom(GetRowByOffset(srcRow));
|
||||
}
|
||||
|
||||
// NOTE: Keep this in sync with _reserve().
|
||||
_buffer = std::move(newBuffer._buffer);
|
||||
_bufferEnd = newBuffer._bufferEnd;
|
||||
_commitWatermark = newBuffer._commitWatermark;
|
||||
_initialAttributes = newBuffer._initialAttributes;
|
||||
_bufferRowStride = newBuffer._bufferRowStride;
|
||||
_bufferOffsetChars = newBuffer._bufferOffsetChars;
|
||||
_bufferOffsetCharOffsets = newBuffer._bufferOffsetCharOffsets;
|
||||
_width = newBuffer._width;
|
||||
_height = newBuffer._height;
|
||||
|
||||
_SetFirstRowIndex(0);
|
||||
}
|
||||
|
||||
void TextBuffer::SetAsActiveBuffer(const bool isActiveBuffer) noexcept
|
||||
@@ -2201,6 +2195,7 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows,
|
||||
// Routine Description:
|
||||
// - Generates an RTF document based on the passed in text and color data
|
||||
// RTF 1.5 Spec: https://www.biblioscape.com/rtf15_spec.htm
|
||||
// RTF 1.9.1 Spec: https://msopenspecs.azureedge.net/files/Archive_References/[MSFT-RTF].pdf
|
||||
// Arguments:
|
||||
// - rows - the text and color data we will format & encapsulate
|
||||
// - backgroundColor - default background color for characters, also used in padding
|
||||
@@ -2220,10 +2215,18 @@ std::string TextBuffer::GenRTF(const TextAndColor& rows, const int fontHeightPoi
|
||||
|
||||
// Standard RTF header.
|
||||
// This is similar to the header generated by WordPad.
|
||||
// \ansi - specifies that the ANSI char set is used in the current doc
|
||||
// \ansicpg1252 - represents the ANSI code page which is used to perform the Unicode to ANSI conversion when writing RTF text
|
||||
// \deff0 - specifies that the default font for the document is the one at index 0 in the font table
|
||||
// \nouicompat - ?
|
||||
// \ansi:
|
||||
// Specifies that the ANSI char set is used in the current doc.
|
||||
// \ansicpg1252:
|
||||
// Represents the ANSI code page which is used to perform
|
||||
// the Unicode to ANSI conversion when writing RTF text.
|
||||
// \deff0:
|
||||
// Specifies that the default font for the document is the one
|
||||
// at index 0 in the font table.
|
||||
// \nouicompat:
|
||||
// Some features are blocked by default to maintain compatibility
|
||||
// with older programs (Eg. Word 97-2003). `nouicompat` disables this
|
||||
// behavior, and unblocks these features. See: Spec 1.9.1, Pg. 51.
|
||||
rtfBuilder << "\\rtf1\\ansi\\ansicpg1252\\deff0\\nouicompat";
|
||||
|
||||
// font table
|
||||
@@ -2232,17 +2235,25 @@ std::string TextBuffer::GenRTF(const TextAndColor& rows, const int fontHeightPoi
|
||||
// map to keep track of colors:
|
||||
// keys are colors represented by COLORREF
|
||||
// values are indices of the corresponding colors in the color table
|
||||
std::unordered_map<COLORREF, int> colorMap;
|
||||
auto nextColorIndex = 1; // leave 0 for the default color and start from 1.
|
||||
std::unordered_map<COLORREF, size_t> colorMap;
|
||||
|
||||
// RTF color table
|
||||
std::ostringstream colorTableBuilder;
|
||||
colorTableBuilder << "{\\colortbl ;";
|
||||
colorTableBuilder << "\\red" << static_cast<int>(GetRValue(backgroundColor))
|
||||
<< "\\green" << static_cast<int>(GetGValue(backgroundColor))
|
||||
<< "\\blue" << static_cast<int>(GetBValue(backgroundColor))
|
||||
<< ";";
|
||||
colorMap[backgroundColor] = nextColorIndex++;
|
||||
|
||||
const auto getColorTableIndex = [&](const COLORREF color) -> size_t {
|
||||
// Exclude the 0 index for the default color, and start with 1.
|
||||
|
||||
const auto [it, inserted] = colorMap.emplace(color, colorMap.size() + 1);
|
||||
if (inserted)
|
||||
{
|
||||
colorTableBuilder << "\\red" << static_cast<int>(GetRValue(color))
|
||||
<< "\\green" << static_cast<int>(GetGValue(color))
|
||||
<< "\\blue" << static_cast<int>(GetBValue(color))
|
||||
<< ";";
|
||||
}
|
||||
return it->second;
|
||||
};
|
||||
|
||||
// content
|
||||
std::ostringstream contentBuilder;
|
||||
@@ -2252,7 +2263,12 @@ std::string TextBuffer::GenRTF(const TextAndColor& rows, const int fontHeightPoi
|
||||
// \fs specifies font size in half-points i.e. \fs20 results in a font size
|
||||
// of 10 pts. That's why, font size is multiplied by 2 here.
|
||||
contentBuilder << "\\pard\\slmult1\\f0\\fs" << std::to_string(2 * fontHeightPoints)
|
||||
<< "\\highlight1"
|
||||
// Set the background color for the page. But, the
|
||||
// standard way (\cbN) to do this isn't supported in Word.
|
||||
// However, the following control words sequence works
|
||||
// in Word (and other RTF editors also) for applying the
|
||||
// text background color. See: Spec 1.9.1, Pg. 23.
|
||||
<< "\\chshdng0\\chcbpat" << getColorTableIndex(backgroundColor)
|
||||
<< " ";
|
||||
|
||||
std::optional<COLORREF> fgColor = std::nullopt;
|
||||
@@ -2302,43 +2318,8 @@ std::string TextBuffer::GenRTF(const TextAndColor& rows, const int fontHeightPoi
|
||||
if (colorChanged)
|
||||
{
|
||||
writeAccumulatedChars(false);
|
||||
|
||||
auto bkColorIndex = 0;
|
||||
if (colorMap.find(bkColor.value()) != colorMap.end())
|
||||
{
|
||||
// color already exists in the map, just retrieve the index
|
||||
bkColorIndex = colorMap[bkColor.value()];
|
||||
}
|
||||
else
|
||||
{
|
||||
// color not present in the map, so add it
|
||||
colorTableBuilder << "\\red" << static_cast<int>(GetRValue(bkColor.value()))
|
||||
<< "\\green" << static_cast<int>(GetGValue(bkColor.value()))
|
||||
<< "\\blue" << static_cast<int>(GetBValue(bkColor.value()))
|
||||
<< ";";
|
||||
colorMap[bkColor.value()] = nextColorIndex;
|
||||
bkColorIndex = nextColorIndex++;
|
||||
}
|
||||
|
||||
auto fgColorIndex = 0;
|
||||
if (colorMap.find(fgColor.value()) != colorMap.end())
|
||||
{
|
||||
// color already exists in the map, just retrieve the index
|
||||
fgColorIndex = colorMap[fgColor.value()];
|
||||
}
|
||||
else
|
||||
{
|
||||
// color not present in the map, so add it
|
||||
colorTableBuilder << "\\red" << static_cast<int>(GetRValue(fgColor.value()))
|
||||
<< "\\green" << static_cast<int>(GetGValue(fgColor.value()))
|
||||
<< "\\blue" << static_cast<int>(GetBValue(fgColor.value()))
|
||||
<< ";";
|
||||
colorMap[fgColor.value()] = nextColorIndex;
|
||||
fgColorIndex = nextColorIndex++;
|
||||
}
|
||||
|
||||
contentBuilder << "\\highlight" << bkColorIndex
|
||||
<< "\\cf" << fgColorIndex
|
||||
contentBuilder << "\\chshdng0\\chcbpat" << getColorTableIndex(bkColor.value())
|
||||
<< "\\cf" << getColorTableIndex(fgColor.value())
|
||||
<< " ";
|
||||
}
|
||||
|
||||
@@ -2412,204 +2393,181 @@ void TextBuffer::_AppendRTFText(std::ostringstream& contentBuilder, const std::w
|
||||
// the new buffer. The rows's new value is placed back into this parameter.
|
||||
// Return Value:
|
||||
// - S_OK if we successfully copied the contents to the new buffer, otherwise an appropriate HRESULT.
|
||||
HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer,
|
||||
TextBuffer& newBuffer,
|
||||
const std::optional<Viewport> lastCharacterViewport,
|
||||
std::optional<std::reference_wrapper<PositionInformation>> positionInfo)
|
||||
try
|
||||
void TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer, const Viewport* lastCharacterViewport, PositionInformation* positionInfo)
|
||||
{
|
||||
const auto& oldCursor = oldBuffer.GetCursor();
|
||||
auto& newCursor = newBuffer.GetCursor();
|
||||
|
||||
// We need to save the old cursor position so that we can
|
||||
// place the new cursor back on the equivalent character in
|
||||
// the new buffer.
|
||||
const auto cOldCursorPos = oldCursor.GetPosition();
|
||||
const auto cOldLastChar = oldBuffer.GetLastNonSpaceCharacter(lastCharacterViewport);
|
||||
til::point oldCursorPos = oldCursor.GetPosition();
|
||||
til::point newCursorPos;
|
||||
|
||||
const auto cOldRowsTotal = cOldLastChar.y + 1;
|
||||
// BODGY: We use oldCursorPos in two critical places below:
|
||||
// * To compute an oldHeight that includes at a minimum the cursor row
|
||||
// * For REFLOW_JANK_CURSOR_WRAP (see comment below)
|
||||
// Both of these would break the reflow algorithm, but the latter of the two in particular
|
||||
// would cause the main copy loop below to deadlock. In other words, these two lines
|
||||
// protect this function against yet-unknown bugs in other parts of the code base.
|
||||
oldCursorPos.x = std::clamp(oldCursorPos.x, 0, oldBuffer._width - 1);
|
||||
oldCursorPos.y = std::clamp(oldCursorPos.y, 0, oldBuffer._height - 1);
|
||||
|
||||
til::point cNewCursorPos;
|
||||
auto fFoundCursorPos = false;
|
||||
auto foundOldMutable = false;
|
||||
auto foundOldVisible = false;
|
||||
// Loop through all the rows of the old buffer and reprint them into the new buffer
|
||||
til::CoordType iOldRow = 0;
|
||||
for (; iOldRow < cOldRowsTotal; iOldRow++)
|
||||
const auto lastRowWithText = oldBuffer.GetLastNonSpaceCharacter(lastCharacterViewport).y;
|
||||
|
||||
auto mutableViewportTop = positionInfo ? positionInfo->mutableViewportTop : til::CoordTypeMax;
|
||||
auto visibleViewportTop = positionInfo ? positionInfo->visibleViewportTop : til::CoordTypeMax;
|
||||
|
||||
til::CoordType oldY = 0;
|
||||
til::CoordType newY = 0;
|
||||
til::CoordType newX = 0;
|
||||
til::CoordType newWidth = newBuffer.GetSize().Width();
|
||||
til::CoordType newYLimit = til::CoordTypeMax;
|
||||
|
||||
const auto oldHeight = std::max(lastRowWithText, oldCursorPos.y) + 1;
|
||||
const auto newHeight = newBuffer.GetSize().Height();
|
||||
const auto newWidthU16 = gsl::narrow_cast<uint16_t>(newWidth);
|
||||
|
||||
// Copy oldBuffer into newBuffer until oldBuffer has been fully consumed.
|
||||
for (; oldY < oldHeight && newY < newYLimit; ++oldY)
|
||||
{
|
||||
// Fetch the row and its "right" which is the last printable character.
|
||||
const auto& row = oldBuffer.GetRowByOffset(iOldRow);
|
||||
const auto cOldColsTotal = oldBuffer.GetLineWidth(iOldRow);
|
||||
auto iRight = row.MeasureRight();
|
||||
const auto& oldRow = oldBuffer.GetRowByOffset(oldY);
|
||||
|
||||
// If we're starting a new row, try and preserve the line rendition
|
||||
// from the row in the original buffer.
|
||||
const auto newBufferPos = newCursor.GetPosition();
|
||||
if (newBufferPos.x == 0)
|
||||
// A pair of double height rows should optimally wrap as a union (i.e. after wrapping there should be 4 lines).
|
||||
// But for this initial implementation I chose the alternative approach: Just truncate them.
|
||||
if (oldRow.GetLineRendition() != LineRendition::SingleWidth)
|
||||
{
|
||||
auto& newRow = newBuffer.GetMutableRowByOffset(newBufferPos.y);
|
||||
newRow.SetLineRendition(row.GetLineRendition());
|
||||
}
|
||||
|
||||
// There is a special case here. If the row has a "wrap"
|
||||
// flag on it, but the right isn't equal to the width (one
|
||||
// index past the final valid index in the row) then there
|
||||
// were a bunch trailing of spaces in the row.
|
||||
// (But the measuring functions for each row Left/Right do
|
||||
// not count spaces as "displayable" so they're not
|
||||
// included.)
|
||||
// As such, adjust the "right" to be the width of the row
|
||||
// to capture all these spaces
|
||||
if (row.WasWrapForced())
|
||||
{
|
||||
iRight = cOldColsTotal;
|
||||
|
||||
// And a combined special case.
|
||||
// If we wrapped off the end of the row by adding a
|
||||
// piece of padding because of a double byte LEADING
|
||||
// character, then remove one from the "right" to
|
||||
// leave this padding out of the copy process.
|
||||
if (row.WasDoubleBytePadded())
|
||||
// Since rows with a non-standard line rendition should be truncated it's important
|
||||
// that we pretend as if the previous row ended in a newline, even if it didn't.
|
||||
// This is what this if does: It newlines.
|
||||
if (newX)
|
||||
{
|
||||
iRight--;
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through every character in the current row (up to
|
||||
// the "right" boundary, which is one past the final valid
|
||||
// character)
|
||||
til::CoordType iOldCol = 0;
|
||||
const auto copyRight = iRight;
|
||||
for (; iOldCol < copyRight; iOldCol++)
|
||||
{
|
||||
if (iOldCol == cOldCursorPos.x && iOldRow == cOldCursorPos.y)
|
||||
{
|
||||
cNewCursorPos = newCursor.GetPosition();
|
||||
fFoundCursorPos = true;
|
||||
newX = 0;
|
||||
newY++;
|
||||
}
|
||||
|
||||
// TODO: MSFT: 19446208 - this should just use an iterator and the inserter...
|
||||
const auto glyph = row.GlyphAt(iOldCol);
|
||||
const auto dbcsAttr = row.DbcsAttrAt(iOldCol);
|
||||
const auto textAttr = row.GetAttrByColumn(iOldCol);
|
||||
auto& newRow = newBuffer.GetMutableRowByOffset(newY);
|
||||
|
||||
newBuffer.InsertCharacter(glyph, dbcsAttr, textAttr);
|
||||
}
|
||||
|
||||
// GH#32: Copy the attributes from the rest of the row into this new buffer.
|
||||
// From where we are in the old buffer, to the end of the row, copy the
|
||||
// remaining attributes.
|
||||
// - if the old buffer is smaller than the new buffer, then just copy
|
||||
// what we have, as it was. We already copied all _text_ with colors,
|
||||
// but it's possible for someone to just put some color into the
|
||||
// buffer to the right of that without any text (as just spaces). The
|
||||
// buffer looks weird to the user when we resize and it starts losing
|
||||
// those colors, so we need to copy them over too... as long as there
|
||||
// is space. The last attr in the row will be extended to the end of
|
||||
// the row in the new buffer.
|
||||
// - if the old buffer is WIDER, than we might have wrapped onto a new
|
||||
// line. Use the cursor's position's Y so that we know where the new
|
||||
// row is, and start writing at the cursor position. Again, the attr
|
||||
// in the last column of the old row will be extended to the end of the
|
||||
// row that the text was flowed onto.
|
||||
// - if the text in the old buffer didn't actually fill the whole
|
||||
// line in the new buffer, then we didn't wrap. That's fine. just
|
||||
// copy attributes from the old row till the end of the new row, and
|
||||
// move on.
|
||||
const auto newRowY = newCursor.GetPosition().y;
|
||||
auto& newRow = newBuffer.GetMutableRowByOffset(newRowY);
|
||||
auto newAttrColumn = newCursor.GetPosition().x;
|
||||
const auto newWidth = newBuffer.GetLineWidth(newRowY);
|
||||
// Stop when we get to the end of the buffer width, or the new position
|
||||
// for inserting an attr would be past the right of the new buffer.
|
||||
for (auto copyAttrCol = iOldCol;
|
||||
copyAttrCol < cOldColsTotal && newAttrColumn < newWidth;
|
||||
copyAttrCol++, newAttrColumn++)
|
||||
{
|
||||
// TODO: MSFT: 19446208 - this should just use an iterator and the inserter...
|
||||
const auto textAttr = row.GetAttrByColumn(copyAttrCol);
|
||||
newRow.SetAttrToEnd(newAttrColumn, textAttr);
|
||||
}
|
||||
|
||||
// If we found the old row that the caller was interested in, set the
|
||||
// out value of that parameter to the cursor's current Y position (the
|
||||
// new location of the _end_ of that row in the buffer).
|
||||
if (positionInfo.has_value())
|
||||
{
|
||||
if (!foundOldMutable)
|
||||
// See the comment marked with "REFLOW_RESET".
|
||||
if (newY >= newHeight)
|
||||
{
|
||||
if (iOldRow >= positionInfo.value().get().mutableViewportTop)
|
||||
newRow.Reset(newBuffer._initialAttributes);
|
||||
}
|
||||
|
||||
newRow.CopyFrom(oldRow);
|
||||
newRow.SetWrapForced(false);
|
||||
|
||||
if (oldY == oldCursorPos.y)
|
||||
{
|
||||
newCursorPos = { newRow.AdjustToGlyphStart(oldCursorPos.x), newY };
|
||||
}
|
||||
if (oldY >= mutableViewportTop)
|
||||
{
|
||||
positionInfo->mutableViewportTop = newY;
|
||||
mutableViewportTop = til::CoordTypeMax;
|
||||
}
|
||||
if (oldY >= visibleViewportTop)
|
||||
{
|
||||
positionInfo->visibleViewportTop = newY;
|
||||
visibleViewportTop = til::CoordTypeMax;
|
||||
}
|
||||
|
||||
newY++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Rows don't store any information for what column the last written character is in.
|
||||
// We simply truncate all trailing whitespace in this implementation.
|
||||
auto oldRowLimit = oldRow.MeasureRight();
|
||||
if (oldY == oldCursorPos.y)
|
||||
{
|
||||
// REFLOW_JANK_CURSOR_WRAP:
|
||||
// Pretending as if there's always at least whitespace in front of the cursor has the benefit that
|
||||
// * the cursor retains its distance from any preceding text.
|
||||
// * when a client application starts writing on this new, empty line,
|
||||
// enlarging the buffer unwraps the text onto the preceding line.
|
||||
oldRowLimit = std::max(oldRowLimit, oldCursorPos.x + 1);
|
||||
}
|
||||
|
||||
til::CoordType oldX = 0;
|
||||
|
||||
// Copy oldRow into newBuffer until oldRow has been fully consumed.
|
||||
// We use a do-while loop to ensure that line wrapping occurs and
|
||||
// that attributes are copied over even for seemingly empty rows.
|
||||
do
|
||||
{
|
||||
// This if condition handles line wrapping.
|
||||
// Only if we write past the last column we should wrap and as such this if
|
||||
// condition is in front of the text insertion code instead of behind it.
|
||||
// A SetWrapForced of false implies an explicit newline, which is the default.
|
||||
if (newX >= newWidth)
|
||||
{
|
||||
newBuffer.GetMutableRowByOffset(newY).SetWrapForced(true);
|
||||
newX = 0;
|
||||
newY++;
|
||||
}
|
||||
|
||||
// REFLOW_RESET:
|
||||
// If we shrink the buffer vertically, for instance from 100 rows to 90 rows, we will write 10 rows in the
|
||||
// new buffer twice. We need to reset them before copying text, or otherwise we'll see the previous contents.
|
||||
// We don't need to be smart about this. Reset() is fast and shrinking doesn't occur often.
|
||||
if (newY >= newHeight && newX == 0)
|
||||
{
|
||||
// We need to ensure not to overwrite the row the cursor is on.
|
||||
if (newY >= newYLimit)
|
||||
{
|
||||
positionInfo.value().get().mutableViewportTop = newCursor.GetPosition().y;
|
||||
foundOldMutable = true;
|
||||
break;
|
||||
}
|
||||
newBuffer.GetMutableRowByOffset(newY).Reset(newBuffer._initialAttributes);
|
||||
}
|
||||
|
||||
if (!foundOldVisible)
|
||||
auto& newRow = newBuffer.GetMutableRowByOffset(newY);
|
||||
|
||||
RowCopyTextFromState state{
|
||||
.source = oldRow,
|
||||
.columnBegin = newX,
|
||||
.columnLimit = til::CoordTypeMax,
|
||||
.sourceColumnBegin = oldX,
|
||||
.sourceColumnLimit = oldRowLimit,
|
||||
};
|
||||
newRow.CopyTextFrom(state);
|
||||
|
||||
const auto& oldAttr = oldRow.Attributes();
|
||||
auto& newAttr = newRow.Attributes();
|
||||
const auto attributes = oldAttr.slice(gsl::narrow_cast<uint16_t>(oldX), oldAttr.size());
|
||||
newAttr.replace(gsl::narrow_cast<uint16_t>(newX), newAttr.size(), attributes);
|
||||
newAttr.resize_trailing_extent(newWidthU16);
|
||||
|
||||
if (oldY == oldCursorPos.y && oldCursorPos.x >= oldX)
|
||||
{
|
||||
if (iOldRow >= positionInfo.value().get().visibleViewportTop)
|
||||
{
|
||||
positionInfo.value().get().visibleViewportTop = newCursor.GetPosition().y;
|
||||
foundOldVisible = true;
|
||||
}
|
||||
// In theory AdjustToGlyphStart ensures we don't put the cursor on a trailing wide glyph.
|
||||
// In practice I don't think that this can possibly happen. Better safe than sorry.
|
||||
newCursorPos = { newRow.AdjustToGlyphStart(oldCursorPos.x - oldX + newX), newY };
|
||||
// If there's so much text past the old cursor position that it doesn't fit into new buffer,
|
||||
// then the new cursor position will be "lost", because it's overwritten by unrelated text.
|
||||
// We have two choices how can handle this:
|
||||
// * If the new cursor is at an y < 0, just put the cursor at (0,0)
|
||||
// * Stop writing into the new buffer before we overwrite the new cursor position
|
||||
// This implements the second option. There's no fundamental reason why this is better.
|
||||
newYLimit = newY + newHeight;
|
||||
}
|
||||
if (oldY >= mutableViewportTop)
|
||||
{
|
||||
positionInfo->mutableViewportTop = newY;
|
||||
mutableViewportTop = til::CoordTypeMax;
|
||||
}
|
||||
if (oldY >= visibleViewportTop)
|
||||
{
|
||||
positionInfo->visibleViewportTop = newY;
|
||||
visibleViewportTop = til::CoordTypeMax;
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't have a full row to copy, insert a new
|
||||
// line into the new buffer.
|
||||
// Only do so if we were not forced to wrap. If we did
|
||||
// force a word wrap, then the existing line break was
|
||||
// only because we ran out of space.
|
||||
if (iRight < cOldColsTotal && !row.WasWrapForced())
|
||||
oldX = state.sourceColumnEnd;
|
||||
newX = state.columnEnd;
|
||||
} while (oldX < oldRowLimit);
|
||||
|
||||
// If the row had an explicit newline we also need to newline. :)
|
||||
if (!oldRow.WasWrapForced())
|
||||
{
|
||||
if (!fFoundCursorPos && (iRight == cOldCursorPos.x && iOldRow == cOldCursorPos.y))
|
||||
{
|
||||
cNewCursorPos = newCursor.GetPosition();
|
||||
fFoundCursorPos = true;
|
||||
}
|
||||
// Only do this if it's not the final line in the buffer.
|
||||
// On the final line, we want the cursor to sit
|
||||
// where it is done printing for the cursor
|
||||
// adjustment to follow.
|
||||
if (iOldRow < cOldRowsTotal - 1)
|
||||
{
|
||||
newBuffer.NewlineCursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we are on the final line of the buffer, we have one more check.
|
||||
// We got into this code path because we are at the right most column of a row in the old buffer
|
||||
// that had a hard return (no wrap was forced).
|
||||
// However, as we're inserting, the old row might have just barely fit into the new buffer and
|
||||
// caused a new soft return (wrap was forced) putting the cursor at x=0 on the line just below.
|
||||
// We need to preserve the memory of the hard return at this point by inserting one additional
|
||||
// hard newline, otherwise we've lost that information.
|
||||
// We only do this when the cursor has just barely poured over onto the next line so the hard return
|
||||
// isn't covered by the soft one.
|
||||
// e.g.
|
||||
// The old line was:
|
||||
// |aaaaaaaaaaaaaaaaaaa | with no wrap which means there was a newline after that final a.
|
||||
// The cursor was here ^
|
||||
// And the new line will be:
|
||||
// |aaaaaaaaaaaaaaaaaaa| and show a wrap at the end
|
||||
// | |
|
||||
// ^ and the cursor is now there.
|
||||
// If we leave it like this, we've lost the newline information.
|
||||
// So we insert one more newline so a continued reflow of this buffer by resizing larger will
|
||||
// continue to look as the original output intended with the newline data.
|
||||
// After this fix, it looks like this:
|
||||
// |aaaaaaaaaaaaaaaaaaa| no wrap at the end (preserved hard newline)
|
||||
// | |
|
||||
// ^ and the cursor is now here.
|
||||
const auto coordNewCursor = newCursor.GetPosition();
|
||||
if (coordNewCursor.x == 0 && coordNewCursor.y > 0)
|
||||
{
|
||||
if (newBuffer.GetRowByOffset(coordNewCursor.y - 1).WasWrapForced())
|
||||
{
|
||||
newBuffer.NewlineCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
newX = 0;
|
||||
newY++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2617,85 +2575,40 @@ try
|
||||
// printable character. This is to fix the `color 2f` scenario, where you
|
||||
// change the buffer colors then resize and everything below the last
|
||||
// printable char gets reset. See GH #12567
|
||||
auto newRowY = newCursor.GetPosition().y + 1;
|
||||
const auto newHeight = newBuffer.GetSize().Height();
|
||||
const auto oldHeight = oldBuffer._estimateOffsetOfLastCommittedRow() + 1;
|
||||
for (;
|
||||
iOldRow < oldHeight && newRowY < newHeight;
|
||||
iOldRow++)
|
||||
const auto initializedRowsEnd = oldBuffer._estimateOffsetOfLastCommittedRow() + 1;
|
||||
for (; oldY < initializedRowsEnd && newY < newHeight; oldY++, newY++)
|
||||
{
|
||||
const auto& row = oldBuffer.GetRowByOffset(iOldRow);
|
||||
|
||||
// Optimization: Since all these rows are below the last printable char,
|
||||
// we can reasonably assume that they are filled with just spaces.
|
||||
// That's convenient, we can just copy the attr row from the old buffer
|
||||
// into the new one, and resize the row to match. We'll rely on the
|
||||
// behavior of ATTR_ROW::Resize to trim down when narrower, or extend
|
||||
// the last attr when wider.
|
||||
auto& newRow = newBuffer.GetMutableRowByOffset(newRowY);
|
||||
const auto newWidth = newBuffer.GetLineWidth(newRowY);
|
||||
newRow.TransferAttributes(row.Attributes(), newWidth);
|
||||
|
||||
newRowY++;
|
||||
auto& oldRow = oldBuffer.GetRowByOffset(oldY);
|
||||
auto& newRow = newBuffer.GetMutableRowByOffset(newY);
|
||||
auto& newAttr = newRow.Attributes();
|
||||
newAttr = oldRow.Attributes();
|
||||
newAttr.resize_trailing_extent(newWidthU16);
|
||||
}
|
||||
|
||||
// Since we didn't use IncrementCircularBuffer() we need to compute the proper
|
||||
// _firstRow offset now, in a way that replicates IncrementCircularBuffer().
|
||||
// We need to do the same for newCursorPos.y for basically the same reason.
|
||||
if (newY > newHeight)
|
||||
{
|
||||
newBuffer._firstRow = newY % newHeight;
|
||||
// _firstRow maps from API coordinates that always start at 0,0 in the top left corner of the
|
||||
// terminal's scrollback, to the underlying buffer Y coordinate via `(y + _firstRow) % height`.
|
||||
// Here, we need to un-map the `newCursorPos.y` from the underlying Y coordinate to the API coordinate
|
||||
// and so we do `(y - _firstRow) % height`, but we add `+ newHeight` to avoid getting negative results.
|
||||
newCursorPos.y = (newCursorPos.y - newBuffer._firstRow + newHeight) % newHeight;
|
||||
}
|
||||
|
||||
// Finish copying remaining parameters from the old text buffer to the new one
|
||||
newBuffer.CopyProperties(oldBuffer);
|
||||
newBuffer.CopyHyperlinkMaps(oldBuffer);
|
||||
|
||||
// If we found where to put the cursor while placing characters into the buffer,
|
||||
// just put the cursor there. Otherwise we have to advance manually.
|
||||
if (fFoundCursorPos)
|
||||
{
|
||||
newCursor.SetPosition(cNewCursorPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Advance the cursor to the same offset as before
|
||||
// get the number of newlines and spaces between the old end of text and the old cursor,
|
||||
// then advance that many newlines and chars
|
||||
auto iNewlines = cOldCursorPos.y - cOldLastChar.y;
|
||||
const auto iIncrements = cOldCursorPos.x - cOldLastChar.x;
|
||||
const auto cNewLastChar = newBuffer.GetLastNonSpaceCharacter();
|
||||
|
||||
// If the last row of the new buffer wrapped, there's going to be one less newline needed,
|
||||
// because the cursor is already on the next line
|
||||
if (newBuffer.GetRowByOffset(cNewLastChar.y).WasWrapForced())
|
||||
{
|
||||
iNewlines = std::max(iNewlines - 1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if this buffer didn't wrap, but the old one DID, then the d(columns) of the
|
||||
// old buffer will be one more than in this buffer, so new need one LESS.
|
||||
if (oldBuffer.GetRowByOffset(cOldLastChar.y).WasWrapForced())
|
||||
{
|
||||
iNewlines = std::max(iNewlines - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto r = 0; r < iNewlines; r++)
|
||||
{
|
||||
newBuffer.NewlineCursor();
|
||||
}
|
||||
for (auto c = 0; c < iIncrements - 1; c++)
|
||||
{
|
||||
newBuffer.IncrementCursor();
|
||||
}
|
||||
}
|
||||
|
||||
// Save old cursor size before we delete it
|
||||
const auto ulSize = oldCursor.GetSize();
|
||||
|
||||
// Set size back to real size as it will be taking over the rendering duties.
|
||||
newCursor.SetSize(ulSize);
|
||||
assert(newCursorPos.x >= 0 && newCursorPos.x < newWidth);
|
||||
assert(newCursorPos.y >= 0 && newCursorPos.y < newHeight);
|
||||
newCursor.SetSize(oldCursor.GetSize());
|
||||
newCursor.SetPosition(newCursorPos);
|
||||
|
||||
newBuffer._marks = oldBuffer._marks;
|
||||
newBuffer._trimMarksOutsideBuffer();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
CATCH_RETURN()
|
||||
|
||||
// Method Description:
|
||||
// - Adds or updates a hyperlink in our hyperlink table
|
||||
@@ -2916,14 +2829,10 @@ void TextBuffer::AddMark(const ScrollMark& m)
|
||||
|
||||
void TextBuffer::_trimMarksOutsideBuffer()
|
||||
{
|
||||
const auto height = GetSize().Height();
|
||||
_marks.erase(std::remove_if(_marks.begin(),
|
||||
_marks.end(),
|
||||
[height](const auto& m) {
|
||||
return (m.start.y < 0) ||
|
||||
(m.start.y >= height);
|
||||
}),
|
||||
_marks.end());
|
||||
const til::CoordType height = _height;
|
||||
std::erase_if(_marks, [height](const auto& m) {
|
||||
return (m.start.y < 0) || (m.start.y >= height);
|
||||
});
|
||||
}
|
||||
|
||||
std::wstring_view TextBuffer::CurrentCommand() const
|
||||
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
// Scroll needs access to this to quickly rotate around the buffer.
|
||||
void IncrementCircularBuffer(const TextAttribute& fillAttributes = {});
|
||||
|
||||
til::point GetLastNonSpaceCharacter(std::optional<const Microsoft::Console::Types::Viewport> viewOptional = std::nullopt) const;
|
||||
til::point GetLastNonSpaceCharacter(const Microsoft::Console::Types::Viewport* viewOptional = nullptr) const;
|
||||
|
||||
Cursor& GetCursor() noexcept;
|
||||
const Cursor& GetCursor() const noexcept;
|
||||
@@ -194,7 +194,7 @@ public:
|
||||
|
||||
void Reset() noexcept;
|
||||
|
||||
[[nodiscard]] HRESULT ResizeTraditional(const til::size newSize) noexcept;
|
||||
void ResizeTraditional(const til::size newSize);
|
||||
|
||||
void SetAsActiveBuffer(const bool isActiveBuffer) noexcept;
|
||||
bool IsActiveBuffer() const noexcept;
|
||||
@@ -262,10 +262,7 @@ public:
|
||||
til::CoordType visibleViewportTop{ 0 };
|
||||
};
|
||||
|
||||
static HRESULT Reflow(TextBuffer& oldBuffer,
|
||||
TextBuffer& newBuffer,
|
||||
const std::optional<Microsoft::Console::Types::Viewport> lastCharacterViewport,
|
||||
std::optional<std::reference_wrapper<PositionInformation>> positionInfo);
|
||||
static void Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer, const Microsoft::Console::Types::Viewport* lastCharacterViewport = nullptr, PositionInformation* positionInfo = nullptr);
|
||||
|
||||
std::vector<til::point_span> SearchText(const std::wstring_view& needle, bool caseInsensitive) const;
|
||||
std::vector<til::point_span> SearchText(const std::wstring_view& needle, bool caseInsensitive, til::CoordType rowBeg, til::CoordType rowEnd) const;
|
||||
|
||||
@@ -46,8 +46,6 @@ namespace
|
||||
std::vector<TestBuffer> buffers;
|
||||
};
|
||||
|
||||
static constexpr auto true_due_to_exact_wrap_bug{ true };
|
||||
|
||||
static const TestCase testCases[] = {
|
||||
TestCase{
|
||||
L"No reflow required",
|
||||
@@ -61,7 +59,7 @@ namespace
|
||||
{ L"EFG ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
@@ -72,7 +70,7 @@ namespace
|
||||
{ L"EFG ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 4, 5 },
|
||||
@@ -83,7 +81,7 @@ namespace
|
||||
{ L"EFG ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -99,40 +97,40 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
{
|
||||
{ L"ABCDE", true },
|
||||
{ L"F$ ", false }, // [BUG] EXACT WRAP. $ should be alone on next line.
|
||||
{ L" ", false },
|
||||
{ L"F ", false },
|
||||
{ L"$ ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 1, 1 } // cursor on $
|
||||
{ 0, 2 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 6, 5 }, // grow width back to original
|
||||
{
|
||||
{ L"ABCDEF", true_due_to_exact_wrap_bug },
|
||||
{ L"ABCDEF", false },
|
||||
{ L"$ ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 7, 5 }, // grow width wider than original
|
||||
{
|
||||
{ L"ABCDEF$", true_due_to_exact_wrap_bug }, // EXACT WRAP BUG: $ should be alone on next line
|
||||
{ L" ", false },
|
||||
{ L"ABCDEF ", false },
|
||||
{ L"$ ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 6, 0 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -148,7 +146,7 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 1, 1 } // cursor on $
|
||||
{ 1, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
@@ -159,7 +157,7 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 2, 1 } // cursor on $
|
||||
{ 2, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 6, 5 }, // grow width back to original
|
||||
@@ -170,7 +168,7 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 1, 1 } // cursor on $
|
||||
{ 1, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 7, 5 }, // grow width wider than original
|
||||
@@ -181,7 +179,7 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -197,29 +195,29 @@ namespace
|
||||
{ L"EFG ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 7, 5 }, // reduce width by 1
|
||||
{
|
||||
{ L"AB $", true },
|
||||
{ L" CD", true_due_to_exact_wrap_bug },
|
||||
{ L" ", false },
|
||||
{ L" CD", false }, // CD ends with a newline -> .wrap = false
|
||||
{ L"EFG ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 6, 0 } // cursor on $
|
||||
{ 6, 0 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 8, 5 },
|
||||
{
|
||||
{ L"AB $ ", true },
|
||||
{ L" CD ", false }, // Goes to false because we hit the end of ..CD
|
||||
{ L"EFG ", false }, // [BUG] EFG moves up due to exact wrap bug above
|
||||
{ L" CD ", false },
|
||||
{ L"EFG ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 6, 0 } // cursor on $
|
||||
{ 6, 0 }, // cursor on $
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -236,19 +234,19 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 2, 1 } // cursor on $
|
||||
{ 2, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
{
|
||||
//--012345--
|
||||
{ L"カタ ", true }, // KA TA [FORCED SPACER]
|
||||
{ L"カナ$", true_due_to_exact_wrap_bug }, // KA NA
|
||||
{ L"カナ$", false }, // KA NA
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 4, 1 } // cursor on $
|
||||
{ 4, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 6, 5 }, // grow width back to original
|
||||
@@ -260,7 +258,7 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 2, 1 } // cursor on $
|
||||
{ 2, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 7, 5 }, // grow width wider than original (by one; no visible change!)
|
||||
@@ -272,7 +270,7 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 2, 1 } // cursor on $
|
||||
{ 2, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 8, 5 }, // grow width enough to fit second DBCS
|
||||
@@ -284,7 +282,7 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -300,41 +298,29 @@ namespace
|
||||
{ L"MNOPQR", false },
|
||||
{ L"STUVWX", false },
|
||||
},
|
||||
{ 0, 1 } // cursor on $
|
||||
{ 0, 1 }, // cursor on $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
{
|
||||
{ L"F$ ", false },
|
||||
{ L"GHIJK", true }, // [BUG] We should see GHIJK\n L\n MNOPQ\n R\n
|
||||
{ L"LMNOP", true }, // The wrapping here is irregular
|
||||
{ L"QRSTU", true },
|
||||
{ L"VWX ", false },
|
||||
{ L"$ ", false },
|
||||
{ L"GHIJK", true },
|
||||
{ L"L ", false },
|
||||
{ L"MNOPQ", true },
|
||||
{ L"R ", false },
|
||||
},
|
||||
{ 1, 1 } // [BUG] cursor moves to 1,1 instead of sticking with the $
|
||||
{ 0, 0 },
|
||||
},
|
||||
TestBuffer{
|
||||
{ 6, 5 }, // going back to 6,5, the data lost has been destroyed
|
||||
{
|
||||
//{ L"F$ ", false }, // [BUG] this line is erroneously destroyed too!
|
||||
{ L"GHIJKL", true },
|
||||
{ L"MNOPQR", true },
|
||||
{ L"STUVWX", true },
|
||||
{ L"$ ", false },
|
||||
{ L"GHIJKL", false },
|
||||
{ L"MNOPQR", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false }, // [BUG] this line is added
|
||||
},
|
||||
{ 1, 1 }, // [BUG] cursor does not follow [H], it sticks at 1,1
|
||||
},
|
||||
TestBuffer{
|
||||
{ 7, 5 }, // a number of errors are carried forward from the previous buffer
|
||||
{
|
||||
{ L"GHIJKLM", true },
|
||||
{ L"NOPQRST", true },
|
||||
{ L"UVWX ", false }, // [BUG] This line loses wrap for some reason
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 0, 1 }, // [BUG] The cursor moves to 0, 1 now, sticking with the [N] from before
|
||||
{ 0, 0 },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -353,18 +339,18 @@ namespace
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 1, 1 } // cursor *after* $
|
||||
{ 1, 1 }, // cursor *after* $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
{
|
||||
{ L"ABCDE", true },
|
||||
{ L"F$ ", false }, // [BUG] EXACT WRAP. $ should be alone on next line.
|
||||
{ L" ", false },
|
||||
{ L"F ", false },
|
||||
{ L"$ ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 2, 1 } // cursor follows space after $ to next line
|
||||
{ 1, 2 }, // cursor follows space after $ to next line
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -380,7 +366,7 @@ namespace
|
||||
{ L"STUVWX", true },
|
||||
{ L"YZ0 $ ", false },
|
||||
},
|
||||
{ 5, 4 } // cursor *after* $
|
||||
{ 5, 4 }, // cursor *after* $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
@@ -391,7 +377,7 @@ namespace
|
||||
{ L"UVWXY", true },
|
||||
{ L"Z0 $ ", false },
|
||||
},
|
||||
{ 4, 4 } // cursor follows space after $ to newly introduced bottom line
|
||||
{ 4, 4 }, // cursor follows space after $ to newly introduced bottom line
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -402,40 +388,36 @@ namespace
|
||||
{ 6, 5 },
|
||||
{
|
||||
{ L"ABCDEF", false },
|
||||
// v cursor
|
||||
{ L"$ ", false },
|
||||
// ^ cursor
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 5, 1 } // cursor in space far after $
|
||||
{ 5, 1 }, // The cursor is 5 columns to the right of the $ (last column).
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
{
|
||||
{ L"ABCDE", true },
|
||||
{ L"F$ ", true }, // [BUG] This line is marked wrapped, and I do not know why
|
||||
// v cursor
|
||||
{ L" ", false },
|
||||
// ^ cursor
|
||||
{ L"F ", false },
|
||||
// The reflow implementation marks a wrapped cursor as a forced row-wrap (= the row is padded with whitespace), so that when
|
||||
// the buffer is enlarged again, we restore the original cursor position correctly. That's why it says .cursor={5,1} below.
|
||||
{ L"$ ", true },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 1, 2 } // cursor stays same linear distance from $
|
||||
{ 0, 3 }, // $ is now at 0,2 and the cursor used to be 5 columns to the right. -> 0,3
|
||||
},
|
||||
TestBuffer{
|
||||
{ 6, 5 }, // grow back to original size
|
||||
{
|
||||
{ L"ABCDEF", true_due_to_exact_wrap_bug },
|
||||
// v cursor [BUG] cursor does not retain linear distance from $
|
||||
{ L"ABCDEF", false },
|
||||
{ L"$ ", false },
|
||||
// ^ cursor
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 4, 1 } // cursor stays same linear distance from $
|
||||
{ 5, 1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -446,39 +428,37 @@ namespace
|
||||
{ 6, 5 },
|
||||
{
|
||||
{ L"ABCDEF", false },
|
||||
// v cursor
|
||||
{ L"$ ", false },
|
||||
// ^ cursor
|
||||
{ L"BLAH ", false },
|
||||
{ L"BLAH ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 5, 1 } // cursor in space far after $
|
||||
{ 5, 1 }, // The cursor is 5 columns to the right of the $ (last column).
|
||||
},
|
||||
TestBuffer{
|
||||
{ 5, 5 }, // reduce width by 1
|
||||
{
|
||||
{ L"ABCDE", true },
|
||||
{ L"F$ ", false },
|
||||
{ L"BLAH ", false },
|
||||
{ L"BLAH ", true }, // [BUG] this line wraps, no idea why
|
||||
// v cursor [BUG] cursor erroneously moved to end of all content
|
||||
{ L"F ", false },
|
||||
// The reflow implementation pads the row with the cursor with whitespace.
|
||||
// Search for "REFLOW_JANK_CURSOR_WRAP" to find the corresponding code.
|
||||
{ L"$ ", true },
|
||||
{ L" ", false },
|
||||
// ^ cursor
|
||||
{ L"BLAH ", false },
|
||||
{ L"BLAH ", false },
|
||||
},
|
||||
{ 0, 4 } },
|
||||
{ 0, 2 },
|
||||
},
|
||||
TestBuffer{
|
||||
{ 6, 5 }, // grow back to original size
|
||||
{
|
||||
{ L"ABCDEF", true },
|
||||
{ L"F ", false },
|
||||
{ L"$ ", false },
|
||||
{ L"BLAH ", false },
|
||||
// v cursor [BUG] cursor is pulled up to previous line because it was marked wrapped
|
||||
{ L"BLAH ", false },
|
||||
// ^ cursor
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 5, 3 } },
|
||||
{ 5, 1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
TestCase{
|
||||
@@ -489,27 +469,24 @@ namespace
|
||||
{ 6, 5 },
|
||||
{
|
||||
{ L"ABCDEF", false },
|
||||
// v cursor
|
||||
{ L"$ ", false },
|
||||
// ^ cursor
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
{ L" ", false },
|
||||
},
|
||||
{ 5, 1 } // cursor in space far after $
|
||||
{ 5, 1 }, // The cursor is 5 columns to the right of the $ (last column).
|
||||
},
|
||||
TestBuffer{
|
||||
{ 2, 5 }, // reduce width aggressively
|
||||
{
|
||||
{ L"CD", true },
|
||||
{ L"EF", true },
|
||||
{ L"EF", false },
|
||||
{ L"$ ", true },
|
||||
{ L" ", true },
|
||||
// v cursor
|
||||
{ L" ", false },
|
||||
// ^ cursor
|
||||
},
|
||||
{ 1, 4 } },
|
||||
{ 1, 4 },
|
||||
},
|
||||
},
|
||||
},
|
||||
TestCase{
|
||||
@@ -519,27 +496,24 @@ namespace
|
||||
{ 6, 5 },
|
||||
{
|
||||
{ L"ABCDEF", true },
|
||||
// v cursor
|
||||
{ L"$ ", true },
|
||||
// ^ cursor
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
},
|
||||
{ 5, 1 } // cursor in space far after $
|
||||
{ 5, 1 }, // cursor in space far after $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 2, 5 }, // reduce width aggressively
|
||||
{
|
||||
{ L"EF", true },
|
||||
{ L"$ ", true },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
// v cursor [BUG] cursor does not maintain linear distance from $
|
||||
{ L" ", false },
|
||||
// ^ cursor
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
},
|
||||
{ 1, 4 } },
|
||||
{ 1, 0 },
|
||||
},
|
||||
},
|
||||
},
|
||||
TestCase{
|
||||
@@ -549,14 +523,12 @@ namespace
|
||||
{ 6, 5 },
|
||||
{
|
||||
{ L"ABCDEF", true },
|
||||
// v cursor
|
||||
{ L"$ ", true },
|
||||
// ^ cursor
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" Q", true },
|
||||
},
|
||||
{ 5, 1 } // cursor in space far after $
|
||||
{ 5, 1 }, // cursor in space far after $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 2, 5 }, // reduce width aggressively
|
||||
@@ -564,12 +536,11 @@ namespace
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" Q", true },
|
||||
// v cursor [BUG] cursor jumps to end of world
|
||||
{ L" ", false }, // POTENTIAL [BUG] a whole new blank line is added for the cursor
|
||||
// ^ cursor
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
},
|
||||
{ 1, 4 } },
|
||||
{ 1, 0 },
|
||||
},
|
||||
},
|
||||
},
|
||||
TestCase{
|
||||
@@ -579,27 +550,24 @@ namespace
|
||||
{ 6, 5 },
|
||||
{
|
||||
{ L"ABCDEF", false },
|
||||
// v cursor
|
||||
{ L"$ ", false },
|
||||
// ^ cursor
|
||||
{ L" ", false },
|
||||
{ L" ", true },
|
||||
{ L" Q", true },
|
||||
},
|
||||
{ 5, 1 } // cursor in space far after $
|
||||
{ 5, 1 }, // cursor in space far after $
|
||||
},
|
||||
TestBuffer{
|
||||
{ 2, 5 }, // reduce width aggressively
|
||||
{
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" Q", true },
|
||||
// v cursor [BUG] cursor jumps to different place than fully wrapped case
|
||||
{ L" ", false },
|
||||
// ^ cursor
|
||||
{ L" ", false },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
},
|
||||
{ 0, 4 } },
|
||||
{ 1, 0 },
|
||||
},
|
||||
},
|
||||
},
|
||||
TestCase{
|
||||
@@ -614,24 +582,21 @@ namespace
|
||||
{ L"$ ", false },
|
||||
{ L" Q", true },
|
||||
{ L" ", true },
|
||||
// v cursor
|
||||
{ L" ", true },
|
||||
// ^ cursor
|
||||
},
|
||||
{ 5, 4 } // cursor at end of buffer
|
||||
{ 5, 4 }, // cursor at end of buffer
|
||||
},
|
||||
TestBuffer{
|
||||
{ 2, 5 }, // reduce width aggressively
|
||||
{
|
||||
{ L" ", false },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" ", true },
|
||||
{ L" Q", true },
|
||||
{ L" ", false },
|
||||
// v cursor [BUG] cursor loses linear distance from Q; is this important?
|
||||
{ L" ", false },
|
||||
// ^ cursor
|
||||
},
|
||||
{ 0, 4 } },
|
||||
{ 1, 0 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -761,7 +726,7 @@ class ReflowTests
|
||||
static std::unique_ptr<TextBuffer> _textBufferByReflowingTextBuffer(TextBuffer& originalBuffer, const til::size newSize)
|
||||
{
|
||||
auto buffer = std::make_unique<TextBuffer>(newSize, TextAttribute{ 0x7 }, 0, false, renderer);
|
||||
TextBuffer::Reflow(originalBuffer, *buffer, std::nullopt, std::nullopt);
|
||||
TextBuffer::Reflow(originalBuffer, *buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<ClCompile Include="ReflowTests.cpp" />
|
||||
<ClCompile Include="TextColorTests.cpp" />
|
||||
<ClCompile Include="TextAttributeTests.cpp" />
|
||||
<ClCompile Include="..\precomp.cpp">
|
||||
<ClCompile Include="precomp.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@@ -30,7 +30,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\precomp.h" />
|
||||
<ClInclude Include="precomp.h" />
|
||||
</ItemGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
</Properties>
|
||||
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.19041.0" MaxVersionTested="10.0.22621.0" />
|
||||
<!-- rescap:appLicensing only works on 22000+. Until that's fixed, MinVersion will not let people install it on Windows 10... -->
|
||||
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.22000.0" MaxVersionTested="10.0.22621.0" />
|
||||
</Dependencies>
|
||||
|
||||
<Resources>
|
||||
|
||||
@@ -74,6 +74,8 @@ namespace SettingsModelLocalTests
|
||||
TEST_METHOD(TestInheritedCommand);
|
||||
TEST_METHOD(LoadFragmentsWithMultipleUpdates);
|
||||
|
||||
TEST_METHOD(MigrateReloadEnvVars);
|
||||
|
||||
private:
|
||||
static winrt::com_ptr<implementation::CascadiaSettings> createSettings(const std::string_view& userJSON)
|
||||
{
|
||||
@@ -2020,4 +2022,40 @@ namespace SettingsModelLocalTests
|
||||
// GH#12520: Fragments should be able to override the name of builtin profiles.
|
||||
VERIFY_ARE_EQUAL(L"NewName", loader.userSettings.profiles[0]->Name());
|
||||
}
|
||||
|
||||
void DeserializationTests::MigrateReloadEnvVars()
|
||||
{
|
||||
static constexpr std::string_view settings1Json{ R"(
|
||||
{
|
||||
"defaultProfile": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
|
||||
"compatibility.reloadEnvironmentVariables": false,
|
||||
"profiles": [
|
||||
{
|
||||
"name": "profile0",
|
||||
"guid": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
|
||||
"historySize": 1,
|
||||
"commandline": "cmd.exe"
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"name": "foo",
|
||||
"command": "closePane",
|
||||
"keys": "ctrl+shift+w"
|
||||
}
|
||||
]
|
||||
})" };
|
||||
|
||||
implementation::SettingsLoader loader{ settings1Json, DefaultJson };
|
||||
loader.MergeInboxIntoUserSettings();
|
||||
loader.FinalizeLayering();
|
||||
|
||||
VERIFY_IS_TRUE(loader.FixupUserSettings(), L"Validate that this will indicate we need to write them back to disk");
|
||||
|
||||
const auto settings = winrt::make_self<implementation::CascadiaSettings>(std::move(loader));
|
||||
|
||||
Log::Comment(L"Ensure that the profile defaults have the new setting added");
|
||||
VERIFY_IS_TRUE(settings->ProfileDefaults().HasReloadEnvironmentVariables());
|
||||
VERIFY_IS_FALSE(settings->ProfileDefaults().ReloadEnvironmentVariables());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ namespace SettingsModelLocalTests
|
||||
TEST_METHOD(CascadiaSettings);
|
||||
TEST_METHOD(LegacyFontSettings);
|
||||
|
||||
TEST_METHOD(RoundtripReloadEnvVars);
|
||||
TEST_METHOD(DontRoundtripNoReloadEnvVars);
|
||||
|
||||
private:
|
||||
// Method Description:
|
||||
// - deserializes and reserializes a json string representing a settings object model of type T
|
||||
@@ -513,4 +516,114 @@ namespace SettingsModelLocalTests
|
||||
|
||||
VERIFY_ARE_EQUAL(toString(jsonOutput), toString(result));
|
||||
}
|
||||
|
||||
void SerializationTests::RoundtripReloadEnvVars()
|
||||
{
|
||||
static constexpr std::string_view oldSettingsJson{ R"(
|
||||
{
|
||||
"defaultProfile": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
|
||||
"compatibility.reloadEnvironmentVariables": false,
|
||||
"profiles": [
|
||||
{
|
||||
"name": "profile0",
|
||||
"guid": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
|
||||
"historySize": 1,
|
||||
"commandline": "cmd.exe"
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"name": "foo",
|
||||
"command": "closePane",
|
||||
"keys": "ctrl+shift+w"
|
||||
}
|
||||
]
|
||||
})" };
|
||||
|
||||
static constexpr std::string_view newSettingsJson{ R"(
|
||||
{
|
||||
"defaultProfile": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
|
||||
"profiles":
|
||||
{
|
||||
"defaults":
|
||||
{
|
||||
"compatibility.reloadEnvironmentVariables": false
|
||||
},
|
||||
"list":
|
||||
[
|
||||
{
|
||||
"name": "profile0",
|
||||
"guid": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
|
||||
"historySize": 1,
|
||||
"commandline": "cmd.exe"
|
||||
}
|
||||
]
|
||||
},
|
||||
"actions": [
|
||||
{
|
||||
"name": "foo",
|
||||
"command": "closePane",
|
||||
"keys": "ctrl+shift+w"
|
||||
}
|
||||
]
|
||||
})" };
|
||||
|
||||
implementation::SettingsLoader oldLoader{ oldSettingsJson, DefaultJson };
|
||||
oldLoader.MergeInboxIntoUserSettings();
|
||||
oldLoader.FinalizeLayering();
|
||||
VERIFY_IS_TRUE(oldLoader.FixupUserSettings(), L"Validate that this will indicate we need to write them back to disk");
|
||||
const auto oldSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(oldLoader));
|
||||
const auto oldResult{ oldSettings->ToJson() };
|
||||
|
||||
implementation::SettingsLoader newLoader{ newSettingsJson, DefaultJson };
|
||||
newLoader.MergeInboxIntoUserSettings();
|
||||
newLoader.FinalizeLayering();
|
||||
newLoader.FixupUserSettings();
|
||||
const auto newSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(newLoader));
|
||||
const auto newResult{ newSettings->ToJson() };
|
||||
|
||||
VERIFY_ARE_EQUAL(toString(newResult), toString(oldResult));
|
||||
}
|
||||
|
||||
void SerializationTests::DontRoundtripNoReloadEnvVars()
|
||||
{
|
||||
// Kinda like the above test, but confirming that _nothing_ happens if
|
||||
// we don't have a setting to migrate.
|
||||
|
||||
static constexpr std::string_view oldSettingsJson{ R"(
|
||||
{
|
||||
"defaultProfile": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
|
||||
"profiles": [
|
||||
{
|
||||
"name": "profile0",
|
||||
"guid": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
|
||||
"historySize": 1,
|
||||
"commandline": "cmd.exe"
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"name": "foo",
|
||||
"command": "closePane",
|
||||
"keys": "ctrl+shift+w"
|
||||
}
|
||||
]
|
||||
})" };
|
||||
|
||||
implementation::SettingsLoader oldLoader{ oldSettingsJson, DefaultJson };
|
||||
oldLoader.MergeInboxIntoUserSettings();
|
||||
oldLoader.FinalizeLayering();
|
||||
oldLoader.FixupUserSettings();
|
||||
const auto oldSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(oldLoader));
|
||||
const auto oldResult{ oldSettings->ToJson() };
|
||||
|
||||
Log::Comment(L"Now, create a _new_ settings object from the re-serialization of the first");
|
||||
implementation::SettingsLoader newLoader{ toString(oldResult), DefaultJson };
|
||||
newLoader.MergeInboxIntoUserSettings();
|
||||
newLoader.FinalizeLayering();
|
||||
newLoader.FixupUserSettings();
|
||||
const auto newSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(newLoader));
|
||||
VERIFY_IS_FALSE(newSettings->ProfileDefaults().HasReloadEnvironmentVariables(),
|
||||
L"Ensure that the new settings object didn't find a reloadEnvironmentVariables");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,8 @@ namespace SettingsModelLocalTests
|
||||
"tabRow":
|
||||
{
|
||||
"background": "#FFFF8800",
|
||||
"unfocusedBackground": "#FF8844"
|
||||
"unfocusedBackground": "#FF8844",
|
||||
"iconStyle": "default"
|
||||
},
|
||||
"window":
|
||||
{
|
||||
|
||||
@@ -64,6 +64,7 @@ Author(s):
|
||||
|
||||
// Manually include til after we include Windows.Foundation to give it winrt superpowers
|
||||
#include "til.h"
|
||||
#include <til/winrt.h>
|
||||
|
||||
// Common includes for most tests:
|
||||
#include "../../inc/conattrs.hpp"
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{84848BFA-931D-42CE-9ADF-01EE54DE7890}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>PublicTerminalCore</RootNamespace>
|
||||
<ProjectName>PublicTerminalCore</ProjectName>
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(SolutionDir)src\common.build.pre.props" />
|
||||
<Import Project="$(SolutionDir)src\common.nugetversions.props" />
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HwndTerminal.cpp" />
|
||||
<ClCompile Include="HwndTerminalAutomationPeer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="HwndTerminal.hpp" />
|
||||
<ClInclude Include="HwndTerminalAutomationPeer.hpp" />
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(SolutionDir)src\terminal\input\lib\terminalinput.vcxproj">
|
||||
<Project>{1cf55140-ef6a-4736-a403-957e4f7430bb}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="$(SolutionDir)src\cascadia\TerminalCore\lib\TerminalCore-lib.vcxproj">
|
||||
<Project>{ca5cad1a-abcd-429c-b551-8562ec954746}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="$(SolutionDir)src\types\lib\types.vcxproj">
|
||||
<Project>{18D09A24-8240-42D6-8CB6-236EEE820263}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="$(SolutionDir)src\renderer\atlas\atlas.vcxproj">
|
||||
<Project>{8222900C-8B6C-452A-91AC-BE95DB04B95F}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="$(SolutionDir)src\renderer\base\lib\base.vcxproj">
|
||||
<Project>{af0a096a-8b3a-4949-81ef-7df8f0fee91f}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="$(SolutionDir)src\renderer\dx\lib\dx.vcxproj">
|
||||
<Project>{48d21369-3d7b-4431-9967-24e81292cf62}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\renderer\uia\lib\uia.vcxproj">
|
||||
<Project>{48d21369-3d7b-4431-9967-24e81292cf63}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(SolutionDir)src\common.build.post.props" />
|
||||
<Import Project="$(SolutionDir)src\common.nugetversions.targets" />
|
||||
|
||||
<!-- LATE LINK LINE OVERRIDES. This project must link named forwarders
|
||||
instead of APISet forwarders for easier Windows 7 compatibility. -->
|
||||
<ItemDefinitionGroup>
|
||||
<Link>
|
||||
<AdditionalDependencies>delayimp.lib;Uiautomationcore.lib;onecoreuap.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>uiautomationcore.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
</Project>
|
||||
@@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="$(SolutionDir)tools\ConsoleTypes.natvis" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HwndTerminal.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HwndTerminalAutomationPeer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HwndTerminal.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HwndTerminalAutomationPeer.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,4 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#include "pch.h"
|
||||
@@ -1,12 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN // If this is not defined, windows.h includes commdlg.h which defines FindText globally and conflicts with UIAutomation ITextRangeProvider.
|
||||
#define NOMCX
|
||||
#define NOHELP
|
||||
#define NOCOMM
|
||||
#endif
|
||||
|
||||
#include <LibraryIncludes.h>
|
||||
#include <UIAutomationCore.h>
|
||||
@@ -15,10 +15,12 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
|
||||
|
||||
CommandlineArgs(const winrt::array_view<const winrt::hstring>& args,
|
||||
winrt::hstring currentDirectory,
|
||||
const uint32_t showWindowCommand) :
|
||||
const uint32_t showWindowCommand,
|
||||
winrt::hstring envString) :
|
||||
_args{ args.begin(), args.end() },
|
||||
_cwd{ currentDirectory },
|
||||
_ShowWindowCommand{ showWindowCommand }
|
||||
_ShowWindowCommand{ showWindowCommand },
|
||||
CurrentEnvironment{ envString }
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,6 +29,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
|
||||
void Commandline(const winrt::array_view<const winrt::hstring>& value);
|
||||
winrt::com_array<winrt::hstring> Commandline();
|
||||
|
||||
til::property<winrt::hstring> CurrentEnvironment;
|
||||
|
||||
WINRT_PROPERTY(uint32_t, ShowWindowCommand, SW_NORMAL); // SW_NORMAL is 1, 0 is SW_HIDE
|
||||
|
||||
private:
|
||||
|
||||
@@ -50,7 +50,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
|
||||
_WindowName{ windowInfo.WindowName() },
|
||||
_args{ command.Commandline() },
|
||||
_CurrentDirectory{ command.CurrentDirectory() },
|
||||
_ShowWindowCommand{ command.ShowWindowCommand() } {};
|
||||
_ShowWindowCommand{ command.ShowWindowCommand() },
|
||||
_CurrentEnvironment{ command.CurrentEnvironment() } {};
|
||||
|
||||
WindowRequestedArgs(const winrt::hstring& window, const winrt::hstring& content, const Windows::Foundation::IReference<Windows::Foundation::Rect>& bounds) :
|
||||
_Id{ 0u },
|
||||
@@ -68,6 +69,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
|
||||
WINRT_PROPERTY(winrt::hstring, CurrentDirectory);
|
||||
WINRT_PROPERTY(winrt::hstring, Content);
|
||||
WINRT_PROPERTY(uint32_t, ShowWindowCommand, SW_NORMAL);
|
||||
WINRT_PROPERTY(winrt::hstring, CurrentEnvironment);
|
||||
WINRT_PROPERTY(Windows::Foundation::IReference<Windows::Foundation::Rect>, InitialBounds);
|
||||
|
||||
private:
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Microsoft.Terminal.Remoting
|
||||
String[] Commandline { get; };
|
||||
String CurrentDirectory { get; };
|
||||
UInt32 ShowWindowCommand { get; };
|
||||
String CurrentEnvironment { get; };
|
||||
|
||||
String Content { get; };
|
||||
Windows.Foundation.IReference<Windows.Foundation.Rect> InitialBounds { get; };
|
||||
|
||||
@@ -7,11 +7,12 @@ namespace Microsoft.Terminal.Remoting
|
||||
runtimeclass CommandlineArgs
|
||||
{
|
||||
CommandlineArgs();
|
||||
CommandlineArgs(String[] args, String cwd, UInt32 showWindowCommand);
|
||||
CommandlineArgs(String[] args, String cwd, UInt32 showWindowCommand, String env);
|
||||
|
||||
String[] Commandline { get; set; };
|
||||
String CurrentDirectory { get; };
|
||||
UInt32 ShowWindowCommand { get; };
|
||||
String CurrentEnvironment { get; };
|
||||
};
|
||||
|
||||
runtimeclass RenameRequestArgs
|
||||
|
||||
@@ -349,7 +349,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
|
||||
// If the name wasn't specified, this will be an empty string.
|
||||
p->WindowName(args.WindowName());
|
||||
|
||||
p->ExecuteCommandline(*winrt::make_self<CommandlineArgs>(args.Commandline(), args.CurrentDirectory(), args.ShowWindowCommand()));
|
||||
p->ExecuteCommandline(*winrt::make_self<CommandlineArgs>(args.Commandline(),
|
||||
args.CurrentDirectory(),
|
||||
args.ShowWindowCommand(),
|
||||
args.CurrentEnvironment()));
|
||||
|
||||
_monarch.AddPeasant(*p);
|
||||
|
||||
|
||||
@@ -52,3 +52,4 @@ TRACELOGGING_DECLARE_PROVIDER(g_hRemotingProvider);
|
||||
#include "til.h"
|
||||
|
||||
#include <cppwinrt_utils.h>
|
||||
#include <til/winrt.h>
|
||||
|
||||
@@ -86,14 +86,55 @@ namespace winrt::TerminalApp::implementation
|
||||
co_await wil::resume_foreground(strongThis->Dispatcher());
|
||||
UpdatesAvailable(true);
|
||||
#else // release build, likely has a store context
|
||||
if (auto storeContext{ winrt::Windows::Services::Store::StoreContext::GetDefault() })
|
||||
bool packageManagerAnswered{ false };
|
||||
|
||||
try
|
||||
{
|
||||
const auto updates = co_await storeContext.GetAppAndOptionalStorePackageUpdatesAsync();
|
||||
co_await wil::resume_foreground(strongThis->Dispatcher());
|
||||
const auto numUpdates = updates.Size();
|
||||
if (numUpdates > 0)
|
||||
if (auto currentPackage{ winrt::Windows::ApplicationModel::Package::Current() })
|
||||
{
|
||||
UpdatesAvailable(true);
|
||||
// We need to look up our package in the Package Manager; we cannot use Current
|
||||
winrt::Windows::Management::Deployment::PackageManager pm;
|
||||
if (auto lookedUpPackage{ pm.FindPackageForUser(winrt::hstring{}, currentPackage.Id().FullName()) })
|
||||
{
|
||||
using winrt::Windows::ApplicationModel::PackageUpdateAvailability;
|
||||
auto availabilityResult = co_await lookedUpPackage.CheckUpdateAvailabilityAsync();
|
||||
co_await wil::resume_foreground(strongThis->Dispatcher());
|
||||
auto availability = availabilityResult.Availability();
|
||||
switch (availability)
|
||||
{
|
||||
case PackageUpdateAvailability::Available:
|
||||
case PackageUpdateAvailability::Required:
|
||||
case PackageUpdateAvailability::NoUpdates:
|
||||
UpdatesAvailable(availability != PackageUpdateAvailability::NoUpdates);
|
||||
packageManagerAnswered = true;
|
||||
break;
|
||||
case PackageUpdateAvailability::Error:
|
||||
case PackageUpdateAvailability::Unknown:
|
||||
default:
|
||||
// Do not set packageManagerAnswered, which will trigger the store check.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
} // Do nothing on failure
|
||||
|
||||
if (!packageManagerAnswered)
|
||||
{
|
||||
if (auto storeContext{ winrt::Windows::Services::Store::StoreContext::GetDefault() })
|
||||
{
|
||||
const auto updates = co_await storeContext.GetAppAndOptionalStorePackageUpdatesAsync();
|
||||
co_await wil::resume_foreground(strongThis->Dispatcher());
|
||||
if (updates)
|
||||
{
|
||||
const auto numUpdates = updates.Size();
|
||||
if (numUpdates > 0)
|
||||
{
|
||||
UpdatesAvailable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1434,8 +1434,15 @@ namespace winrt::TerminalApp::implementation
|
||||
scratchPane->GetRoot().KeyDown({ this, &TerminalPage::_KeyDownHandler });
|
||||
|
||||
auto resultPane = std::make_shared<Pane>(*scratchPane);
|
||||
_SplitPane(SplitDirection::Automatic, 0.5f, resultPane);
|
||||
_SplitPane(_GetFocusedTabImpl(), SplitDirection::Automatic, 0.5f, resultPane);
|
||||
args.Handled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalPage::_HandleOpenAbout(const IInspectable& /*sender*/,
|
||||
const ActionEventArgs& args)
|
||||
{
|
||||
_ShowAboutDialog();
|
||||
args.Handled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,6 +571,11 @@ void AppCommandlineArgs::_addNewTerminalArgs(AppCommandlineArgs::NewTerminalSubc
|
||||
|
||||
subcommand.appendCommandLineOption = subcommand.subcommand->add_flag("--appendCommandLine", _appendCommandLineOption, RS_A(L"CmdAppendCommandLineDesc"));
|
||||
|
||||
subcommand.inheritEnvOption = subcommand.subcommand->add_flag(
|
||||
"--inheritEnvironment,!--reloadEnvironment",
|
||||
_inheritEnvironment,
|
||||
RS_A(L"CmdInheritEnvDesc"));
|
||||
|
||||
// Using positionals_at_end allows us to support "wt new-tab -d wsl -d Ubuntu"
|
||||
// without CLI11 thinking that we've specified -d twice.
|
||||
// There's an alternate construction where we make all subcommands "prefix commands",
|
||||
@@ -592,7 +597,8 @@ NewTerminalArgs AppCommandlineArgs::_getNewTerminalArgs(AppCommandlineArgs::NewT
|
||||
{
|
||||
NewTerminalArgs args{};
|
||||
|
||||
if (!_commandline.empty())
|
||||
const auto hasCommandline{ !_commandline.empty() };
|
||||
if (hasCommandline)
|
||||
{
|
||||
std::ostringstream cmdlineBuffer;
|
||||
|
||||
@@ -662,6 +668,13 @@ NewTerminalArgs AppCommandlineArgs::_getNewTerminalArgs(AppCommandlineArgs::NewT
|
||||
args.AppendCommandLine(_appendCommandLineOption);
|
||||
}
|
||||
|
||||
bool inheritEnv = hasCommandline;
|
||||
if (*subcommand.inheritEnvOption)
|
||||
{
|
||||
inheritEnv = _inheritEnvironment;
|
||||
}
|
||||
args.ReloadEnvironmentVariables(!inheritEnv);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ private:
|
||||
CLI::Option* suppressApplicationTitleOption;
|
||||
CLI::Option* colorSchemeOption;
|
||||
CLI::Option* appendCommandLineOption;
|
||||
CLI::Option* inheritEnvOption;
|
||||
};
|
||||
|
||||
struct NewPaneSubcommand : public NewTerminalSubcommand
|
||||
@@ -100,6 +101,7 @@ private:
|
||||
std::string _startingTabColor;
|
||||
std::string _startingColorScheme;
|
||||
bool _suppressApplicationTitle{ false };
|
||||
bool _inheritEnvironment{ false };
|
||||
|
||||
winrt::Microsoft::Terminal::Settings::Model::FocusDirection _moveFocusDirection{ winrt::Microsoft::Terminal::Settings::Model::FocusDirection::None };
|
||||
winrt::Microsoft::Terminal::Settings::Model::FocusDirection _swapPaneDirection{ winrt::Microsoft::Terminal::Settings::Model::FocusDirection::None };
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace TerminalApp
|
||||
event Windows.Foundation.TypedEventHandler<Object, Object> TitleChanged;
|
||||
event Windows.Foundation.TypedEventHandler<Object, Object> TabColorChanged;
|
||||
event Windows.Foundation.TypedEventHandler<Object, Object> TaskbarProgressChanged;
|
||||
event Windows.Foundation.TypedEventHandler<Object, Object> ConnectionStateChanged;
|
||||
event Windows.Foundation.TypedEventHandler<Object, Object> ReadOnlyChanged;
|
||||
event Windows.Foundation.TypedEventHandler<Object, Object> FocusRequested;
|
||||
};
|
||||
|
||||
@@ -962,6 +962,21 @@ Pane::PaneNeighborSearch Pane::_FindPaneAndNeighbor(const std::shared_ptr<Pane>
|
||||
return { nullptr, nullptr, offset };
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Returns true if the connection state of this pane is closed.
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - true if the connection state of this Pane is closed.
|
||||
bool Pane::IsConnectionClosed() const
|
||||
{
|
||||
if (const auto& control{ GetTerminalControl() })
|
||||
{
|
||||
return control.ConnectionState() >= ConnectionState::Closed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Event Description:
|
||||
// - Called when our control gains focus. We'll use this to trigger our GotFocus
|
||||
// callback. The tab that's hosting us should have registered a callback which
|
||||
@@ -1098,7 +1113,7 @@ TermControl Pane::GetLastFocusedTerminalControl()
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - nullptr if this Pane is a parent, otherwise the TermControl of this Pane.
|
||||
TermControl Pane::GetTerminalControl()
|
||||
TermControl Pane::GetTerminalControl() const
|
||||
{
|
||||
if (const auto& terminalPane{ _getTerminalContent() })
|
||||
{
|
||||
@@ -2263,6 +2278,7 @@ std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> Pane::_Split(SplitDirect
|
||||
// Move our control, guid, isDefTermSession into the first one.
|
||||
_firstChild = std::make_shared<Pane>(_content);
|
||||
_content = nullptr;
|
||||
_firstChild->_broadcastEnabled = _broadcastEnabled;
|
||||
}
|
||||
|
||||
_splitState = actualSplitType;
|
||||
@@ -2948,6 +2964,12 @@ void Pane::EnableBroadcast(bool enabled)
|
||||
if (_IsLeaf())
|
||||
{
|
||||
_broadcastEnabled = enabled;
|
||||
if (const auto& termControl{ GetTerminalControl() })
|
||||
{
|
||||
termControl.CursorVisibility(enabled ?
|
||||
CursorDisplayState::Shown :
|
||||
CursorDisplayState::Default);
|
||||
}
|
||||
UpdateVisuals();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -73,8 +73,9 @@ public:
|
||||
|
||||
std::shared_ptr<Pane> GetActivePane();
|
||||
winrt::Microsoft::Terminal::Control::TermControl GetLastFocusedTerminalControl();
|
||||
winrt::Microsoft::Terminal::Control::TermControl GetTerminalControl();
|
||||
winrt::Microsoft::Terminal::Control::TermControl GetTerminalControl() const;
|
||||
winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile();
|
||||
bool IsConnectionClosed() const;
|
||||
|
||||
// Method Description:
|
||||
// - If this is a leaf pane, return its profile.
|
||||
|
||||
@@ -371,6 +371,10 @@
|
||||
<value>Open the tab with tabTitle overriding default title and suppressing title change messages from the application</value>
|
||||
<comment>{Locked="\"tabTitle\""}</comment>
|
||||
</data>
|
||||
<data name="CmdInheritEnvDesc" xml:space="preserve">
|
||||
<value>Inherit the terminal's own environment variables when creating the new tab or pane, rather than creating a fresh environment block. This defaults to set when a "command" is passed. </value>
|
||||
<comment>{Locked="\"command\""}</comment>
|
||||
</data>
|
||||
<data name="CmdColorSchemeArgDesc" xml:space="preserve">
|
||||
<value>Open the tab with the specified color scheme, instead of the profile's set "colorScheme"</value>
|
||||
<comment>{Locked="\"colorScheme\""}</comment>
|
||||
@@ -878,7 +882,11 @@
|
||||
</data>
|
||||
<data name="TerminalPage_PaneMovedAnnouncement_ExistingWindow" xml:space="preserve">
|
||||
<value>Active pane moved to "{0}" tab in "{1}" window</value>
|
||||
<comment>{Locked="{0}"}{Locked="{1}"}This text is read out by screen readers upon a successful pane movement. {0} is the name of the tab the pane was moved to. {1} is the name of the window the pane was moved to.</comment>
|
||||
<comment>{Locked="{0}"}{Locked="{1}"}This text is read out by screen readers upon a successful pane movement. {0} is the name of the tab the pane was moved to. {1} is the name of the window the pane was moved to. Replaced in 1.19 by TerminalPage_PaneMovedAnnouncement_ExistingWindow2</comment>
|
||||
</data>
|
||||
<data name="TerminalPage_PaneMovedAnnouncement_ExistingWindow2" xml:space="preserve">
|
||||
<value>Active pane moved to "{0}" window</value>
|
||||
<comment>{Locked="{0}"}This text is read out by screen readers upon a successful pane movement. {0} is the name of the window the pane was moved to.</comment>
|
||||
</data>
|
||||
<data name="TerminalPage_PaneMovedAnnouncement_NewWindow" xml:space="preserve">
|
||||
<value>Active pane moved to new window</value>
|
||||
@@ -891,4 +899,10 @@
|
||||
<data name="CmdAppendCommandLineDesc" xml:space="preserve">
|
||||
<value>If set, the command will be appended to the profile's default command instead of replacing it.</value>
|
||||
</data>
|
||||
<data name="RestartConnectionText" xml:space="preserve">
|
||||
<value>Restart Connection</value>
|
||||
</data>
|
||||
<data name="RestartConnectionToolTip" xml:space="preserve">
|
||||
<value>Restart the active pane connection</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace winrt::TerminalApp::implementation
|
||||
til::typed_event<> TitleChanged;
|
||||
til::typed_event<> TabColorChanged;
|
||||
til::typed_event<> TaskbarProgressChanged;
|
||||
til::typed_event<> ConnectionStateChanged;
|
||||
til::typed_event<> ReadOnlyChanged;
|
||||
til::typed_event<> FocusRequested;
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
// The TabViewItem Icon needs MUX while the IconSourceElement in the CommandPalette needs WUX...
|
||||
Icon(winrt::hstring{ glyph });
|
||||
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(glyph));
|
||||
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(glyph, false));
|
||||
}
|
||||
|
||||
winrt::Windows::UI::Xaml::Media::Brush SettingsTab::_BackgroundBrush()
|
||||
|
||||
@@ -43,6 +43,12 @@
|
||||
FontSize="12"
|
||||
Glyph=""
|
||||
Visibility="{x:Bind TabStatus.IsReadOnlyActive, Mode=OneWay}" />
|
||||
<FontIcon x:Name="HeaderClosedIcon"
|
||||
Margin="0,0,8,0"
|
||||
FontFamily="{ThemeResource SymbolThemeFontFamily}"
|
||||
FontSize="12"
|
||||
Glyph=""
|
||||
Visibility="{x:Bind TabStatus.IsConnectionClosed, Mode=OneWay}" />
|
||||
<FontIcon x:Name="HeaderBroadcastIcon"
|
||||
Margin="0,0,8,0"
|
||||
FontFamily="{ThemeResource SymbolThemeFontFamily}"
|
||||
|
||||
@@ -176,7 +176,9 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
if (!profile.Icon().empty())
|
||||
{
|
||||
newTabImpl->UpdateIcon(profile.Icon());
|
||||
const auto theme = _settings.GlobalSettings().CurrentTheme();
|
||||
const auto iconStyle = (theme && theme.Tab()) ? theme.Tab().IconStyle() : IconStyle::Default;
|
||||
newTabImpl->UpdateIcon(profile.Icon(), iconStyle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +243,9 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
if (const auto profile = tab.GetFocusedProfile())
|
||||
{
|
||||
tab.UpdateIcon(profile.Icon());
|
||||
const auto theme = _settings.GlobalSettings().CurrentTheme();
|
||||
const auto iconStyle = (theme && theme.Tab()) ? theme.Tab().IconStyle() : IconStyle::Default;
|
||||
tab.UpdateIcon(profile.Icon(), iconStyle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +305,12 @@ namespace winrt::TerminalApp::implementation
|
||||
// In the future, it may be preferable to just duplicate the
|
||||
// current control's live settings (which will include changes
|
||||
// made through VT).
|
||||
_CreateNewTabFromPane(_MakePane(nullptr, tab, nullptr), tab.TabViewIndex() + 1);
|
||||
uint32_t insertPosition = _tabs.Size();
|
||||
if (_settings.GlobalSettings().NewTabPosition() == NewTabPosition::AfterCurrentTab)
|
||||
{
|
||||
insertPosition = tab.TabViewIndex() + 1;
|
||||
}
|
||||
_CreateNewTabFromPane(_MakePane(nullptr, tab, nullptr), insertPosition);
|
||||
|
||||
const auto runtimeTabText{ tab.GetTabText() };
|
||||
if (!runtimeTabText.empty())
|
||||
@@ -506,7 +515,7 @@ namespace winrt::TerminalApp::implementation
|
||||
// * B (tabIndex=1): We'll want to focus tab A (now in index 0)
|
||||
// * C (tabIndex=2): We'll want to focus tab B (now in index 1)
|
||||
// * D (tabIndex=3): We'll want to focus tab C (now in index 2)
|
||||
const auto newSelectedIndex = std::clamp<int32_t>(tabIndex - 1, 0, _tabs.Size());
|
||||
const auto newSelectedIndex = std::clamp<int32_t>(tabIndex - 1, 0, _tabs.Size() - 1);
|
||||
// _UpdatedSelectedTab will do the work of setting up the new tab as
|
||||
// the focused one, and unfocusing all the others.
|
||||
auto newSelectedTab{ _tabs.GetAt(newSelectedIndex) };
|
||||
@@ -673,7 +682,7 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
uint32_t tabIndexFromControl{};
|
||||
const auto items{ _tabView.TabItems() };
|
||||
if (items.IndexOf(tabViewItem, tabIndexFromControl))
|
||||
if (items.IndexOf(tabViewItem, tabIndexFromControl) && tabIndexFromControl < _tabs.Size())
|
||||
{
|
||||
// If IndexOf returns true, we've actually got an index
|
||||
return _tabs.GetAt(tabIndexFromControl);
|
||||
@@ -1030,7 +1039,8 @@ namespace winrt::TerminalApp::implementation
|
||||
// - suggestedNewTabIndex: the new index of the tab, might get clamped to fit int the tabs row boundaries
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void TerminalPage::_TryMoveTab(const uint32_t currentTabIndex, const int32_t suggestedNewTabIndex)
|
||||
void TerminalPage::_TryMoveTab(const uint32_t currentTabIndex,
|
||||
const int32_t suggestedNewTabIndex)
|
||||
{
|
||||
auto newTabIndex = gsl::narrow_cast<uint32_t>(std::clamp<int32_t>(suggestedNewTabIndex, 0, _tabs.Size() - 1));
|
||||
if (currentTabIndex != newTabIndex)
|
||||
@@ -1072,16 +1082,21 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
if (from.has_value() && to.has_value() && to != from)
|
||||
{
|
||||
auto& tabs{ _tabs };
|
||||
auto tab = tabs.GetAt(from.value());
|
||||
tabs.RemoveAt(from.value());
|
||||
tabs.InsertAt(to.value(), tab);
|
||||
_UpdateTabIndices();
|
||||
try
|
||||
{
|
||||
auto& tabs{ _tabs };
|
||||
auto tab = tabs.GetAt(from.value());
|
||||
tabs.RemoveAt(from.value());
|
||||
tabs.InsertAt(to.value(), tab);
|
||||
_UpdateTabIndices();
|
||||
}
|
||||
CATCH_LOG();
|
||||
}
|
||||
|
||||
_rearranging = false;
|
||||
|
||||
if (to.has_value())
|
||||
if (to.has_value() &&
|
||||
*to < gsl::narrow_cast<int32_t>(TabRow().TabView().TabItems().Size()))
|
||||
{
|
||||
// Selecting the dropped tab
|
||||
TabRow().TabView().SelectedIndex(to.value());
|
||||
|
||||
@@ -556,7 +556,8 @@ namespace winrt::TerminalApp::implementation
|
||||
// - <none>
|
||||
winrt::fire_and_forget TerminalPage::ProcessStartupActions(Windows::Foundation::Collections::IVector<ActionAndArgs> actions,
|
||||
const bool initial,
|
||||
const winrt::hstring cwd)
|
||||
const winrt::hstring cwd,
|
||||
const winrt::hstring env)
|
||||
{
|
||||
auto weakThis{ get_weak() };
|
||||
|
||||
@@ -576,6 +577,12 @@ namespace winrt::TerminalApp::implementation
|
||||
_WindowProperties.VirtualWorkingDirectory(originalVirtualCwd);
|
||||
});
|
||||
|
||||
// Literally the same thing with env vars too
|
||||
auto originalVirtualEnv{ _WindowProperties.VirtualEnvVars() };
|
||||
auto restoreEnv = wil::scope_exit([&originalVirtualEnv, this]() {
|
||||
_WindowProperties.VirtualEnvVars(originalVirtualEnv);
|
||||
});
|
||||
|
||||
if (cwd.empty())
|
||||
{
|
||||
// We didn't actually need to change the virtual CWD, so we don't
|
||||
@@ -587,6 +594,15 @@ namespace winrt::TerminalApp::implementation
|
||||
_WindowProperties.VirtualWorkingDirectory(cwd);
|
||||
}
|
||||
|
||||
if (env.empty())
|
||||
{
|
||||
restoreEnv.release();
|
||||
}
|
||||
else
|
||||
{
|
||||
_WindowProperties.VirtualEnvVars(env);
|
||||
}
|
||||
|
||||
if (auto page{ weakThis.get() })
|
||||
{
|
||||
for (const auto& action : actions)
|
||||
@@ -1213,6 +1229,8 @@ namespace winrt::TerminalApp::implementation
|
||||
auto valueSet = TerminalConnection::ConptyConnection::CreateSettings(azBridgePath.native(),
|
||||
L".",
|
||||
L"Azure",
|
||||
false,
|
||||
L"",
|
||||
nullptr,
|
||||
settings.InitialRows(),
|
||||
settings.InitialCols(),
|
||||
@@ -1253,6 +1271,8 @@ namespace winrt::TerminalApp::implementation
|
||||
auto valueSet = TerminalConnection::ConptyConnection::CreateSettings(settings.Commandline(),
|
||||
newWorkingDirectory,
|
||||
settings.StartingTitle(),
|
||||
settings.ReloadEnvironmentVariables(),
|
||||
_WindowProperties.VirtualEnvVars(),
|
||||
environment,
|
||||
settings.InitialRows(),
|
||||
settings.InitialCols(),
|
||||
@@ -1260,8 +1280,6 @@ namespace winrt::TerminalApp::implementation
|
||||
profile.Guid());
|
||||
|
||||
valueSet.Insert(L"passthroughMode", Windows::Foundation::PropertyValue::CreateBoolean(settings.VtPassthrough()));
|
||||
valueSet.Insert(L"reloadEnvironmentVariables",
|
||||
Windows::Foundation::PropertyValue::CreateBoolean(_settings.GlobalSettings().ReloadEnvironmentVariables()));
|
||||
|
||||
if (inheritCursor)
|
||||
{
|
||||
@@ -1665,9 +1683,19 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
term.CompletionsChanged({ get_weak(), &TerminalPage::_ControlCompletionsChangedHandler });
|
||||
}
|
||||
|
||||
term.ContextMenu().Opening({ this, &TerminalPage::_ContextMenuOpened });
|
||||
term.SelectionContextMenu().Opening({ this, &TerminalPage::_SelectionMenuOpened });
|
||||
winrt::weak_ref<TermControl> weakTerm{ term };
|
||||
term.ContextMenu().Opening([weak = get_weak(), weakTerm](auto&& sender, auto&& /*args*/) {
|
||||
if (const auto& page{ weak.get() })
|
||||
{
|
||||
page->_PopulateContextMenu(weakTerm.get(), sender.try_as<MUX::Controls::CommandBarFlyout>(), false);
|
||||
}
|
||||
});
|
||||
term.SelectionContextMenu().Opening([weak = get_weak(), weakTerm](auto&& sender, auto&& /*args*/) {
|
||||
if (const auto& page{ weak.get() })
|
||||
{
|
||||
page->_PopulateContextMenu(weakTerm.get(), sender.try_as<MUX::Controls::CommandBarFlyout>(), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
@@ -1711,6 +1739,11 @@ namespace winrt::TerminalApp::implementation
|
||||
hostingTab.TaskbarProgressChanged({ get_weak(), &TerminalPage::_SetTaskbarProgressHandler });
|
||||
}
|
||||
|
||||
void TerminalPage::_RegisterPaneEvents(const TerminalApp::TerminalPaneContent& paneContent)
|
||||
{
|
||||
paneContent.RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection });
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Helper to manually exit "zoom" when certain actions take place.
|
||||
// Anything that modifies the state of the pane tree should probably
|
||||
@@ -1955,6 +1988,11 @@ namespace winrt::TerminalApp::implementation
|
||||
_settings.GlobalSettings().ConfirmCloseAllTabs() &&
|
||||
!_displayingCloseDialog)
|
||||
{
|
||||
if (_newTabButton && _newTabButton.Flyout())
|
||||
{
|
||||
_newTabButton.Flyout().Hide();
|
||||
}
|
||||
_DismissTabContextMenus();
|
||||
_displayingCloseDialog = true;
|
||||
auto warningResult = co_await _ShowCloseWarningDialog();
|
||||
_displayingCloseDialog = false;
|
||||
@@ -2035,9 +2073,6 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
if (const auto pane{ terminalTab->GetActivePane() })
|
||||
{
|
||||
// Get the tab title _before_ moving things around in case the tabIdx doesn't point to the right one after the move
|
||||
const auto tabTitle = _tabs.GetAt(tabIdx).Title();
|
||||
|
||||
auto startupActions = pane->BuildStartupActions(0, 1, true, true);
|
||||
_DetachPaneFromWindow(pane);
|
||||
_MoveContent(std::move(startupActions.args), windowId, tabIdx);
|
||||
@@ -2056,7 +2091,7 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
autoPeer.RaiseNotificationEvent(Automation::Peers::AutomationNotificationKind::ActionCompleted,
|
||||
Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
|
||||
fmt::format(std::wstring_view{ RS_(L"TerminalPage_PaneMovedAnnouncement_ExistingWindow") }, tabTitle, windowId),
|
||||
fmt::format(std::wstring_view{ RS_(L"TerminalPage_PaneMovedAnnouncement_ExistingWindow2") }, windowId),
|
||||
L"TerminalPageMovePaneToExistingWindow" /* unique name for this notification category */);
|
||||
}
|
||||
}
|
||||
@@ -2073,7 +2108,7 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
// Moving the pane from the current tab might close it, so get the next
|
||||
// tab before its index changes.
|
||||
if (_tabs.Size() > tabIdx)
|
||||
if (tabIdx < _tabs.Size())
|
||||
{
|
||||
auto targetTab = _GetTerminalTabImpl(_tabs.GetAt(tabIdx));
|
||||
// if the selected tab is not a host of terminals (e.g. settings)
|
||||
@@ -2353,7 +2388,17 @@ namespace winrt::TerminalApp::implementation
|
||||
}
|
||||
|
||||
_UnZoomIfNeeded();
|
||||
activeTab->SplitPane(*realSplitType, splitSize, newPane);
|
||||
auto [original, _] = activeTab->SplitPane(*realSplitType, splitSize, newPane);
|
||||
|
||||
// When we split the pane, the Pane itself will create a _new_ Pane
|
||||
// instance for the original content. We need to make sure we also
|
||||
// re-add our event handler to that newly created pane.
|
||||
//
|
||||
// _MakePane will already call this for the newly created pane.
|
||||
if (const auto& paneContent{ original->GetContent().try_as<TerminalPaneContent>() })
|
||||
{
|
||||
_RegisterPaneEvents(*paneContent);
|
||||
}
|
||||
|
||||
// After GH#6586, the control will no longer focus itself
|
||||
// automatically when it's finished being laid out. Manually focus
|
||||
@@ -2605,62 +2650,91 @@ namespace winrt::TerminalApp::implementation
|
||||
// - Does some of this in a background thread, as to not hang/crash the UI thread.
|
||||
// Arguments:
|
||||
// - eventArgs: the PasteFromClipboard event sent from the TermControl
|
||||
fire_and_forget TerminalPage::_PasteFromClipboardHandler(const IInspectable /*sender*/,
|
||||
const PasteFromClipboardEventArgs eventArgs)
|
||||
fire_and_forget TerminalPage::_PasteFromClipboardHandler(const IInspectable /*sender*/, const PasteFromClipboardEventArgs eventArgs)
|
||||
try
|
||||
{
|
||||
const auto data = Clipboard::GetContent();
|
||||
// The old Win32 clipboard API as used below is somewhere in the order of 300-1000x faster than
|
||||
// the WinRT one on average, depending on CPU load. Don't use the WinRT clipboard API if you can.
|
||||
const auto weakThis = get_weak();
|
||||
const auto dispatcher = Dispatcher();
|
||||
const auto globalSettings = _settings.GlobalSettings();
|
||||
winrt::hstring text;
|
||||
|
||||
// This will switch the execution of the function to a background (not
|
||||
// UI) thread. This is IMPORTANT, because the getting the clipboard data
|
||||
// will crash on the UI thread, because the main thread is a STA.
|
||||
// GetClipboardData might block for up to 30s for delay-rendered contents.
|
||||
co_await winrt::resume_background();
|
||||
|
||||
try
|
||||
{
|
||||
hstring text = L"";
|
||||
if (data.Contains(StandardDataFormats::Text()))
|
||||
// According to various reports on the internet, OpenClipboard might
|
||||
// fail to acquire the internal lock, for instance due to rdpclip.exe.
|
||||
for (int attempts = 1;;)
|
||||
{
|
||||
text = co_await data.GetTextAsync();
|
||||
}
|
||||
// Windows Explorer's "Copy address" menu item stores a StorageItem in the clipboard, and no text.
|
||||
else if (data.Contains(StandardDataFormats::StorageItems()))
|
||||
{
|
||||
auto items = co_await data.GetStorageItemsAsync();
|
||||
if (items.Size() > 0)
|
||||
if (OpenClipboard(nullptr))
|
||||
{
|
||||
auto item = items.GetAt(0);
|
||||
text = item.Path();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_settings.GlobalSettings().TrimPaste())
|
||||
{
|
||||
text = { Utils::TrimPaste(text) };
|
||||
if (text.empty())
|
||||
if (attempts > 5)
|
||||
{
|
||||
// Text is all white space, nothing to paste
|
||||
co_return;
|
||||
}
|
||||
|
||||
attempts++;
|
||||
Sleep(10 * attempts);
|
||||
}
|
||||
|
||||
// If the requesting terminal is in bracketed paste mode, then we don't need to warn about a multi-line paste.
|
||||
auto warnMultiLine = _settings.GlobalSettings().WarnAboutMultiLinePaste() &&
|
||||
!eventArgs.BracketedPasteEnabled();
|
||||
if (warnMultiLine)
|
||||
const auto clipboardCleanup = wil::scope_exit([]() {
|
||||
CloseClipboard();
|
||||
});
|
||||
|
||||
const auto data = GetClipboardData(CF_UNICODETEXT);
|
||||
if (!data)
|
||||
{
|
||||
const auto isNewLineLambda = [](auto c) { return c == L'\n' || c == L'\r'; };
|
||||
const auto hasNewLine = std::find_if(text.cbegin(), text.cend(), isNewLineLambda) != text.cend();
|
||||
warnMultiLine = hasNewLine;
|
||||
co_return;
|
||||
}
|
||||
|
||||
constexpr const std::size_t minimumSizeForWarning = 1024 * 5; // 5 KiB
|
||||
const auto warnLargeText = text.size() > minimumSizeForWarning &&
|
||||
_settings.GlobalSettings().WarnAboutLargePaste();
|
||||
|
||||
if (warnMultiLine || warnLargeText)
|
||||
const auto str = static_cast<const wchar_t*>(GlobalLock(data));
|
||||
if (!str)
|
||||
{
|
||||
co_await wil::resume_foreground(Dispatcher());
|
||||
co_return;
|
||||
}
|
||||
|
||||
const auto dataCleanup = wil::scope_exit([&]() {
|
||||
GlobalUnlock(data);
|
||||
});
|
||||
|
||||
const auto maxLength = GlobalSize(data) / sizeof(wchar_t);
|
||||
const auto length = wcsnlen(str, maxLength);
|
||||
text = winrt::hstring{ str, gsl::narrow_cast<uint32_t>(length) };
|
||||
}
|
||||
|
||||
if (globalSettings.TrimPaste())
|
||||
{
|
||||
text = { Utils::TrimPaste(text) };
|
||||
if (text.empty())
|
||||
{
|
||||
// Text is all white space, nothing to paste
|
||||
co_return;
|
||||
}
|
||||
}
|
||||
|
||||
// If the requesting terminal is in bracketed paste mode, then we don't need to warn about a multi-line paste.
|
||||
auto warnMultiLine = globalSettings.WarnAboutMultiLinePaste() && !eventArgs.BracketedPasteEnabled();
|
||||
if (warnMultiLine)
|
||||
{
|
||||
const auto isNewLineLambda = [](auto c) { return c == L'\n' || c == L'\r'; };
|
||||
const auto hasNewLine = std::find_if(text.cbegin(), text.cend(), isNewLineLambda) != text.cend();
|
||||
warnMultiLine = hasNewLine;
|
||||
}
|
||||
|
||||
constexpr const std::size_t minimumSizeForWarning = 1024 * 5; // 5 KiB
|
||||
const auto warnLargeText = text.size() > minimumSizeForWarning && globalSettings.WarnAboutLargePaste();
|
||||
|
||||
if (warnMultiLine || warnLargeText)
|
||||
{
|
||||
co_await wil::resume_foreground(dispatcher);
|
||||
|
||||
if (const auto strongThis = weakThis.get())
|
||||
{
|
||||
// We have to initialize the dialog here to be able to change the text of the text block within it
|
||||
FindName(L"MultiLinePasteDialog").try_as<WUX::Controls::ContentDialog>();
|
||||
ClipboardText().Text(text);
|
||||
@@ -2688,10 +2762,15 @@ namespace winrt::TerminalApp::implementation
|
||||
}
|
||||
}
|
||||
|
||||
eventArgs.HandleClipboardData(text);
|
||||
co_await winrt::resume_background();
|
||||
}
|
||||
CATCH_LOG();
|
||||
|
||||
// This will end up calling ConptyConnection::WriteInput which calls WriteFile which may block for
|
||||
// an indefinite amount of time. Avoid freezes and deadlocks by running this on a background thread.
|
||||
assert(!dispatcher.HasThreadAccess());
|
||||
eventArgs.HandleClipboardData(std::move(text));
|
||||
}
|
||||
CATCH_LOG();
|
||||
|
||||
void TerminalPage::_OpenHyperlinkHandler(const IInspectable /*sender*/, const Microsoft::Terminal::Control::OpenHyperlinkEventArgs eventArgs)
|
||||
{
|
||||
@@ -3104,7 +3183,7 @@ namespace winrt::TerminalApp::implementation
|
||||
original->SetActive();
|
||||
}
|
||||
|
||||
terminalPane.RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection });
|
||||
_RegisterPaneEvents(terminalPane);
|
||||
|
||||
return resultPane;
|
||||
}
|
||||
@@ -4706,6 +4785,21 @@ namespace winrt::TerminalApp::implementation
|
||||
// the settings, change active panes, etc.
|
||||
_activated = activated;
|
||||
_updateThemeColors();
|
||||
|
||||
if (const auto& tab{ _GetFocusedTabImpl() })
|
||||
{
|
||||
if (tab->TabStatus().IsInputBroadcastActive())
|
||||
{
|
||||
tab->GetRootPane()->WalkTree([activated](const auto& p) {
|
||||
if (const auto& control{ p->GetTerminalControl() })
|
||||
{
|
||||
control.CursorVisibility(activated ?
|
||||
Microsoft::Terminal::Control::CursorDisplayState::Shown :
|
||||
Microsoft::Terminal::Control::CursorDisplayState::Default);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
winrt::fire_and_forget TerminalPage::_ControlCompletionsChangedHandler(const IInspectable sender,
|
||||
@@ -4788,26 +4882,14 @@ namespace winrt::TerminalApp::implementation
|
||||
characterSize.Height);
|
||||
}
|
||||
|
||||
void TerminalPage::_ContextMenuOpened(const IInspectable& sender,
|
||||
const IInspectable& /*args*/)
|
||||
{
|
||||
_PopulateContextMenu(sender, false /*withSelection*/);
|
||||
}
|
||||
void TerminalPage::_SelectionMenuOpened(const IInspectable& sender,
|
||||
const IInspectable& /*args*/)
|
||||
{
|
||||
_PopulateContextMenu(sender, true /*withSelection*/);
|
||||
}
|
||||
|
||||
void TerminalPage::_PopulateContextMenu(const IInspectable& sender,
|
||||
void TerminalPage::_PopulateContextMenu(const TermControl& control,
|
||||
const MUX::Controls::CommandBarFlyout& menu,
|
||||
const bool withSelection)
|
||||
{
|
||||
// withSelection can be used to add actions that only appear if there's
|
||||
// selected text, like "search the web". In this initial draft, it's not
|
||||
// actually augmented by the TerminalPage, so it's left commented out.
|
||||
// selected text, like "search the web"
|
||||
|
||||
const auto& menu{ sender.try_as<MUX::Controls::CommandBarFlyout>() };
|
||||
if (!menu)
|
||||
if (!control || !menu)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -4857,6 +4939,11 @@ namespace winrt::TerminalApp::implementation
|
||||
makeItem(RS_(L"PaneClose"), L"\xE89F", ActionAndArgs{ ShortcutAction::ClosePane, nullptr });
|
||||
}
|
||||
|
||||
if (control.ConnectionState() >= ConnectionState::Closed)
|
||||
{
|
||||
makeItem(RS_(L"RestartConnectionText"), L"\xE72C", ActionAndArgs{ ShortcutAction::RestartConnection, nullptr });
|
||||
}
|
||||
|
||||
if (withSelection)
|
||||
{
|
||||
makeItem(RS_(L"SearchWebText"), L"\xF6FA", ActionAndArgs{ ShortcutAction::SearchForText, nullptr });
|
||||
|
||||
@@ -154,7 +154,8 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
winrt::fire_and_forget ProcessStartupActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> actions,
|
||||
const bool initial,
|
||||
const winrt::hstring cwd = L"");
|
||||
const winrt::hstring cwd = L"",
|
||||
const winrt::hstring env = L"");
|
||||
|
||||
TerminalApp::WindowProperties WindowProperties() const noexcept { return _WindowProperties; };
|
||||
|
||||
@@ -344,6 +345,7 @@ namespace winrt::TerminalApp::implementation
|
||||
void _InitializeTab(winrt::com_ptr<TerminalTab> newTabImpl, uint32_t insertPosition = -1);
|
||||
void _RegisterTerminalEvents(Microsoft::Terminal::Control::TermControl term);
|
||||
void _RegisterTabEvents(TerminalTab& hostingTab);
|
||||
void _RegisterPaneEvents(const TerminalApp::TerminalPaneContent& paneContent);
|
||||
|
||||
void _DismissTabContextMenus();
|
||||
void _FocusCurrentTab(const bool focusAlways);
|
||||
@@ -535,9 +537,7 @@ namespace winrt::TerminalApp::implementation
|
||||
const std::optional<til::point>& dragPoint = std::nullopt);
|
||||
void _sendDraggedTabToWindow(const winrt::hstring& windowId, const uint32_t tabIndex, std::optional<til::point> dragPoint);
|
||||
|
||||
void _ContextMenuOpened(const IInspectable& sender, const IInspectable& args);
|
||||
void _SelectionMenuOpened(const IInspectable& sender, const IInspectable& args);
|
||||
void _PopulateContextMenu(const IInspectable& sender, const bool withSelection);
|
||||
void _PopulateContextMenu(const Microsoft::Terminal::Control::TermControl& control, const Microsoft::UI::Xaml::Controls::CommandBarFlyout& sender, const bool withSelection);
|
||||
winrt::Windows::UI::Xaml::Controls::MenuFlyout _CreateRunAsAdminFlyout(int profileIndex);
|
||||
|
||||
winrt::Microsoft::Terminal::Control::TermControl _senderOrActiveControl(const winrt::Windows::Foundation::IInspectable& sender);
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace TerminalApp
|
||||
String WindowIdForDisplay { get; };
|
||||
|
||||
String VirtualWorkingDirectory { get; set; };
|
||||
String VirtualEnvVars { get; set; };
|
||||
|
||||
Boolean IsQuakeWindow();
|
||||
};
|
||||
|
||||
@@ -160,24 +160,45 @@ namespace winrt::TerminalApp::implementation
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void TerminalPaneContent::_ControlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
|
||||
const winrt::Windows::Foundation::IInspectable& /*args*/)
|
||||
winrt::fire_and_forget TerminalPaneContent::_ControlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender,
|
||||
const winrt::Windows::Foundation::IInspectable& args)
|
||||
{
|
||||
const auto newConnectionState = _control.ConnectionState();
|
||||
const auto previousConnectionState = std::exchange(_connectionState, newConnectionState);
|
||||
ConnectionStateChanged.raise(sender, args);
|
||||
auto newConnectionState = ConnectionState::Closed;
|
||||
if (const auto coreState = sender.try_as<ICoreState>())
|
||||
{
|
||||
newConnectionState = coreState.ConnectionState();
|
||||
}
|
||||
|
||||
const auto previousConnectionState = std::exchange(_connectionState, newConnectionState);
|
||||
if (newConnectionState < ConnectionState::Closed)
|
||||
{
|
||||
// Pane doesn't care if the connection isn't entering a terminal state.
|
||||
return;
|
||||
co_return;
|
||||
}
|
||||
|
||||
const auto weakThis = get_weak();
|
||||
co_await wil::resume_foreground(_control.Dispatcher());
|
||||
const auto strongThis = weakThis.get();
|
||||
if (!strongThis)
|
||||
{
|
||||
co_return;
|
||||
}
|
||||
|
||||
// It's possible that this event handler started being executed, scheduled
|
||||
// on the UI thread, another child got created. So our control is
|
||||
// actually no longer _our_ control, and instead could be a descendant.
|
||||
//
|
||||
// When the control's new Pane takes ownership of the control, the new
|
||||
// parent will register its own event handler. That event handler will get
|
||||
// fired after this handler returns, and will properly cleanup state.
|
||||
|
||||
if (previousConnectionState < ConnectionState::Connected && newConnectionState >= ConnectionState::Failed)
|
||||
{
|
||||
// A failure to complete the connection (before it has _connected_) is not covered by "closeOnExit".
|
||||
// This is to prevent a misconfiguration (closeOnExit: always, startingDirectory: garbage) resulting
|
||||
// in Terminal flashing open and immediately closed.
|
||||
return;
|
||||
co_return;
|
||||
}
|
||||
|
||||
if (_profile)
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace winrt::TerminalApp::implementation
|
||||
til::typed_event<> TitleChanged;
|
||||
til::typed_event<> TabColorChanged;
|
||||
til::typed_event<> TaskbarProgressChanged;
|
||||
til::typed_event<> ConnectionStateChanged;
|
||||
til::typed_event<> ReadOnlyChanged;
|
||||
til::typed_event<> FocusRequested;
|
||||
|
||||
@@ -76,7 +77,7 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
winrt::fire_and_forget _playBellSound(winrt::Windows::Foundation::Uri uri);
|
||||
|
||||
void _ControlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
|
||||
winrt::fire_and_forget _ControlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
|
||||
void _ControlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& sender,
|
||||
const winrt::Windows::Foundation::IInspectable& e);
|
||||
void _ControlReadOnlyChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& e);
|
||||
|
||||
@@ -15,6 +15,7 @@ using namespace winrt;
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
using namespace winrt::Windows::UI::Core;
|
||||
using namespace winrt::Microsoft::Terminal::Control;
|
||||
using namespace winrt::Microsoft::Terminal::TerminalConnection;
|
||||
using namespace winrt::Microsoft::Terminal::Settings::Model;
|
||||
using namespace winrt::Microsoft::UI::Xaml::Controls;
|
||||
using namespace winrt::Windows::System;
|
||||
@@ -35,6 +36,7 @@ namespace winrt::TerminalApp::implementation
|
||||
_activePane = nullptr;
|
||||
|
||||
_closePaneMenuItem.Visibility(WUX::Visibility::Collapsed);
|
||||
_restartConnectionMenuItem.Visibility(WUX::Visibility::Collapsed);
|
||||
|
||||
auto firstId = _nextPaneId;
|
||||
|
||||
@@ -283,17 +285,17 @@ namespace winrt::TerminalApp::implementation
|
||||
// - iconPath: The new path string to use as the IconPath for our TabViewItem
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void TerminalTab::UpdateIcon(const winrt::hstring iconPath)
|
||||
void TerminalTab::UpdateIcon(const winrt::hstring iconPath, const winrt::Microsoft::Terminal::Settings::Model::IconStyle iconStyle)
|
||||
{
|
||||
ASSERT_UI_THREAD();
|
||||
|
||||
// Don't reload our icon if it hasn't changed.
|
||||
if (iconPath == _lastIconPath)
|
||||
// Don't reload our icon and iconStyle hasn't changed.
|
||||
if (iconPath == _lastIconPath && iconStyle == _lastIconStyle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastIconPath = iconPath;
|
||||
_lastIconStyle = iconStyle;
|
||||
|
||||
// If the icon is currently hidden, just return here (but only after setting _lastIconPath to the new path
|
||||
// for when we show the icon again)
|
||||
@@ -302,9 +304,18 @@ namespace winrt::TerminalApp::implementation
|
||||
return;
|
||||
}
|
||||
|
||||
// The TabViewItem Icon needs MUX while the IconSourceElement in the CommandPalette needs WUX...
|
||||
Icon(_lastIconPath);
|
||||
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(_lastIconPath));
|
||||
if (iconStyle == IconStyle::Hidden)
|
||||
{
|
||||
// The TabViewItem Icon needs MUX while the IconSourceElement in the CommandPalette needs WUX...
|
||||
Icon({});
|
||||
TabViewItem().IconSource(IconSource{ nullptr });
|
||||
}
|
||||
else
|
||||
{
|
||||
Icon(_lastIconPath);
|
||||
bool isMonochrome = iconStyle == IconStyle::Monochrome;
|
||||
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(_lastIconPath, isMonochrome));
|
||||
}
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
@@ -326,7 +337,7 @@ namespace winrt::TerminalApp::implementation
|
||||
else
|
||||
{
|
||||
Icon(_lastIconPath);
|
||||
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(_lastIconPath));
|
||||
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(_lastIconPath, _lastIconStyle == IconStyle::Monochrome));
|
||||
}
|
||||
_iconHidden = hide;
|
||||
}
|
||||
@@ -500,9 +511,9 @@ namespace winrt::TerminalApp::implementation
|
||||
// could itself be a parent pane/the root node of a tree of panes
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void TerminalTab::SplitPane(SplitDirection splitType,
|
||||
const float splitSize,
|
||||
std::shared_ptr<Pane> pane)
|
||||
std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> TerminalTab::SplitPane(SplitDirection splitType,
|
||||
const float splitSize,
|
||||
std::shared_ptr<Pane> pane)
|
||||
{
|
||||
ASSERT_UI_THREAD();
|
||||
|
||||
@@ -550,6 +561,8 @@ namespace winrt::TerminalApp::implementation
|
||||
// possible that the focus events won't propagate immediately. Updating
|
||||
// the focus here will give the same effect though.
|
||||
_UpdateActivePane(newPane);
|
||||
|
||||
return { original, newPane };
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
@@ -957,6 +970,16 @@ namespace winrt::TerminalApp::implementation
|
||||
}
|
||||
});
|
||||
|
||||
events.ConnectionStateChanged = content.ConnectionStateChanged(
|
||||
winrt::auto_revoke,
|
||||
[dispatcher, weakThis](auto&&, auto&&) -> winrt::fire_and_forget {
|
||||
co_await wil::resume_foreground(dispatcher);
|
||||
if (auto tab{ weakThis.get() })
|
||||
{
|
||||
tab->_UpdateConnectionClosedState();
|
||||
}
|
||||
});
|
||||
|
||||
events.ReadOnlyChanged = content.ReadOnlyChanged(
|
||||
winrt::auto_revoke,
|
||||
[dispatcher, weakThis](auto&&, auto&&) -> winrt::fire_and_forget {
|
||||
@@ -1069,6 +1092,40 @@ namespace winrt::TerminalApp::implementation
|
||||
_TaskbarProgressChangedHandlers(nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Set an indicator on the tab if any pane is in a closed connection state.
|
||||
// - Show/hide the Restart Connection context menu entry depending on active pane's state.
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void TerminalTab::_UpdateConnectionClosedState()
|
||||
{
|
||||
ASSERT_UI_THREAD();
|
||||
|
||||
if (_rootPane)
|
||||
{
|
||||
const bool isClosed = _rootPane->WalkTree([&](const auto& p) {
|
||||
return p->IsConnectionClosed();
|
||||
});
|
||||
|
||||
_tabStatus.IsConnectionClosed(isClosed);
|
||||
}
|
||||
|
||||
if (_activePane)
|
||||
{
|
||||
_restartConnectionMenuItem.Visibility(_activePane->IsConnectionClosed() ?
|
||||
WUX::Visibility::Visible :
|
||||
WUX::Visibility::Collapsed);
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalTab::_RestartActivePaneConnection()
|
||||
{
|
||||
ActionAndArgs restartConnection{ ShortcutAction::RestartConnection, nullptr };
|
||||
_dispatch.DoAction(*this, restartConnection);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Mark the given pane as the active pane in this tab. All other panes
|
||||
// will be marked as inactive. We'll also update our own UI state to
|
||||
@@ -1087,6 +1144,7 @@ namespace winrt::TerminalApp::implementation
|
||||
// Update our own title text to match the newly-active pane.
|
||||
UpdateTitle();
|
||||
_UpdateProgressState();
|
||||
_UpdateConnectionClosedState();
|
||||
|
||||
// We need to move the pane to the top of our mru list
|
||||
// If its already somewhere in the list, remove it first
|
||||
@@ -1380,6 +1438,28 @@ namespace winrt::TerminalApp::implementation
|
||||
Automation::AutomationProperties::SetHelpText(findMenuItem, findToolTip);
|
||||
}
|
||||
|
||||
Controls::MenuFlyoutItem restartConnectionMenuItem = _restartConnectionMenuItem;
|
||||
{
|
||||
// "Restart Connection"
|
||||
Controls::FontIcon restartConnectionSymbol;
|
||||
restartConnectionSymbol.FontFamily(Media::FontFamily{ L"Segoe Fluent Icons, Segoe MDL2 Assets" });
|
||||
restartConnectionSymbol.Glyph(L"\xE72C");
|
||||
|
||||
restartConnectionMenuItem.Click([weakThis](auto&&, auto&&) {
|
||||
if (auto tab{ weakThis.get() })
|
||||
{
|
||||
tab->_RestartActivePaneConnection();
|
||||
}
|
||||
});
|
||||
restartConnectionMenuItem.Text(RS_(L"RestartConnectionText"));
|
||||
restartConnectionMenuItem.Icon(restartConnectionSymbol);
|
||||
|
||||
const auto restartConnectionToolTip = RS_(L"RestartConnectionToolTip");
|
||||
|
||||
WUX::Controls::ToolTipService::SetToolTip(restartConnectionMenuItem, box_value(restartConnectionToolTip));
|
||||
Automation::AutomationProperties::SetHelpText(restartConnectionMenuItem, restartConnectionToolTip);
|
||||
}
|
||||
|
||||
// Build the menu
|
||||
Controls::MenuFlyout contextMenuFlyout;
|
||||
Controls::MenuFlyoutSeparator menuSeparator;
|
||||
@@ -1390,6 +1470,7 @@ namespace winrt::TerminalApp::implementation
|
||||
contextMenuFlyout.Items().Append(moveTabToNewWindowMenuItem);
|
||||
contextMenuFlyout.Items().Append(exportTabMenuItem);
|
||||
contextMenuFlyout.Items().Append(findMenuItem);
|
||||
contextMenuFlyout.Items().Append(restartConnectionMenuItem);
|
||||
contextMenuFlyout.Items().Append(menuSeparator);
|
||||
|
||||
// GH#5750 - When the context menu is dismissed with ESC, toss the focus
|
||||
|
||||
@@ -37,12 +37,12 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
void AttachColorPicker(winrt::TerminalApp::ColorPickupFlyout& colorPicker);
|
||||
|
||||
void SplitPane(winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType,
|
||||
const float splitSize,
|
||||
std::shared_ptr<Pane> newPane);
|
||||
std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> SplitPane(winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType,
|
||||
const float splitSize,
|
||||
std::shared_ptr<Pane> newPane);
|
||||
|
||||
void ToggleSplitOrientation();
|
||||
void UpdateIcon(const winrt::hstring iconPath);
|
||||
void UpdateIcon(const winrt::hstring iconPath, const winrt::Microsoft::Terminal::Settings::Model::IconStyle iconStyle);
|
||||
void HideIcon(const bool hide);
|
||||
|
||||
void ShowBellIndicator(const bool show);
|
||||
@@ -110,7 +110,9 @@ namespace winrt::TerminalApp::implementation
|
||||
std::shared_ptr<Pane> _zoomedPane{ nullptr };
|
||||
|
||||
Windows::UI::Xaml::Controls::MenuFlyoutItem _closePaneMenuItem;
|
||||
Windows::UI::Xaml::Controls::MenuFlyoutItem _restartConnectionMenuItem;
|
||||
|
||||
winrt::Microsoft::Terminal::Settings::Model::IconStyle _lastIconStyle;
|
||||
winrt::hstring _lastIconPath{};
|
||||
std::optional<winrt::Windows::UI::Color> _runtimeTabColor{};
|
||||
winrt::TerminalApp::TabHeaderControl _headerControl{};
|
||||
@@ -127,6 +129,7 @@ namespace winrt::TerminalApp::implementation
|
||||
winrt::TerminalApp::IPaneContent::TitleChanged_revoker TitleChanged;
|
||||
winrt::TerminalApp::IPaneContent::TabColorChanged_revoker TabColorChanged;
|
||||
winrt::TerminalApp::IPaneContent::TaskbarProgressChanged_revoker TaskbarProgressChanged;
|
||||
winrt::TerminalApp::IPaneContent::ConnectionStateChanged_revoker ConnectionStateChanged;
|
||||
winrt::TerminalApp::IPaneContent::ReadOnlyChanged_revoker ReadOnlyChanged;
|
||||
winrt::TerminalApp::IPaneContent::FocusRequested_revoker FocusRequested;
|
||||
|
||||
@@ -174,6 +177,9 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
void _UpdateProgressState();
|
||||
|
||||
void _UpdateConnectionClosedState();
|
||||
void _RestartActivePaneConnection();
|
||||
|
||||
void _DuplicateTab();
|
||||
|
||||
virtual winrt::Windows::UI::Xaml::Media::Brush _BackgroundBrush() override;
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace winrt::TerminalApp::implementation
|
||||
TerminalTabStatus() = default;
|
||||
|
||||
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
|
||||
WINRT_OBSERVABLE_PROPERTY(bool, IsConnectionClosed, _PropertyChangedHandlers);
|
||||
WINRT_OBSERVABLE_PROPERTY(bool, IsPaneZoomed, _PropertyChangedHandlers);
|
||||
WINRT_OBSERVABLE_PROPERTY(bool, IsProgressRingActive, _PropertyChangedHandlers);
|
||||
WINRT_OBSERVABLE_PROPERTY(bool, IsProgressRingIndeterminate, _PropertyChangedHandlers);
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace TerminalApp
|
||||
{
|
||||
TerminalTabStatus();
|
||||
|
||||
Boolean IsConnectionClosed { get; set; };
|
||||
Boolean IsPaneZoomed { get; set; };
|
||||
Boolean IsProgressRingActive { get; set; };
|
||||
Boolean IsProgressRingIndeterminate { get; set; };
|
||||
|
||||
@@ -204,39 +204,19 @@ namespace winrt::TerminalApp::implementation
|
||||
// Pay attention, that even if some command line arguments were parsed (like launch mode),
|
||||
// we will not use the startup actions from settings.
|
||||
// While this simplifies the logic, we might want to reconsider this behavior in the future.
|
||||
if (!_hasCommandLineArguments && _gotSettingsStartupActions)
|
||||
//
|
||||
// Obviously, don't use the `startupActions` from the settings in the
|
||||
// case of a tear-out / reattach. GH#16050
|
||||
if (!_hasCommandLineArguments &&
|
||||
_initialContentArgs.empty() &&
|
||||
_gotSettingsStartupActions)
|
||||
{
|
||||
_root->SetStartupActions(_settingsStartupArgs);
|
||||
}
|
||||
|
||||
_root->SetSettings(_settings, false); // We're on our UI thread right now, so this is safe
|
||||
_root->Loaded({ get_weak(), &TerminalWindow::_OnLoaded });
|
||||
|
||||
_root->Initialized([this](auto&&, auto&&) {
|
||||
// GH#288 - When we finish initialization, if the user wanted us
|
||||
// launched _fullscreen_, toggle fullscreen mode. This will make sure
|
||||
// that the window size is _first_ set up as something sensible, so
|
||||
// leaving fullscreen returns to a reasonable size.
|
||||
const auto launchMode = this->GetLaunchMode();
|
||||
if (_WindowProperties->IsQuakeWindow() || WI_IsFlagSet(launchMode, LaunchMode::FocusMode))
|
||||
{
|
||||
_root->SetFocusMode(true);
|
||||
}
|
||||
|
||||
// The IslandWindow handles (creating) the maximized state
|
||||
// we just want to record it here on the page as well.
|
||||
if (WI_IsFlagSet(launchMode, LaunchMode::MaximizedMode))
|
||||
{
|
||||
_root->Maximized(true);
|
||||
}
|
||||
|
||||
if (WI_IsFlagSet(launchMode, LaunchMode::FullscreenMode) && !_WindowProperties->IsQuakeWindow())
|
||||
{
|
||||
_root->SetFullscreen(true);
|
||||
}
|
||||
|
||||
AppLogic::Current()->NotifyRootInitialized();
|
||||
});
|
||||
_root->Initialized({ get_weak(), &TerminalWindow::_pageInitialized });
|
||||
_root->Create();
|
||||
|
||||
AppLogic::Current()->SettingsChanged({ get_weak(), &TerminalWindow::UpdateSettingsHandler });
|
||||
@@ -255,6 +235,34 @@ namespace winrt::TerminalApp::implementation
|
||||
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
|
||||
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
|
||||
}
|
||||
|
||||
void TerminalWindow::_pageInitialized(const IInspectable&, const IInspectable&)
|
||||
{
|
||||
// GH#288 - When we finish initialization, if the user wanted us
|
||||
// launched _fullscreen_, toggle fullscreen mode. This will make sure
|
||||
// that the window size is _first_ set up as something sensible, so
|
||||
// leaving fullscreen returns to a reasonable size.
|
||||
const auto launchMode = this->GetLaunchMode();
|
||||
if (_WindowProperties->IsQuakeWindow() || WI_IsFlagSet(launchMode, LaunchMode::FocusMode))
|
||||
{
|
||||
_root->SetFocusMode(true);
|
||||
}
|
||||
|
||||
// The IslandWindow handles (creating) the maximized state
|
||||
// we just want to record it here on the page as well.
|
||||
if (WI_IsFlagSet(launchMode, LaunchMode::MaximizedMode))
|
||||
{
|
||||
_root->Maximized(true);
|
||||
}
|
||||
|
||||
if (WI_IsFlagSet(launchMode, LaunchMode::FullscreenMode) && !_WindowProperties->IsQuakeWindow())
|
||||
{
|
||||
_root->SetFullscreen(true);
|
||||
}
|
||||
|
||||
AppLogic::Current()->NotifyRootInitialized();
|
||||
}
|
||||
|
||||
void TerminalWindow::Quit()
|
||||
{
|
||||
if (_root)
|
||||
@@ -775,6 +783,10 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
_ShowLoadWarningsDialog(args.Warnings());
|
||||
}
|
||||
else if (args.Result() == S_OK)
|
||||
{
|
||||
DismissDialog();
|
||||
}
|
||||
_RefreshThemeRoutine();
|
||||
}
|
||||
}
|
||||
@@ -1024,9 +1036,12 @@ namespace winrt::TerminalApp::implementation
|
||||
// Return Value:
|
||||
// - the result of the first command who's parsing returned a non-zero code,
|
||||
// or 0. (see TerminalWindow::_ParseArgs)
|
||||
int32_t TerminalWindow::SetStartupCommandline(array_view<const winrt::hstring> args, winrt::hstring cwd)
|
||||
int32_t TerminalWindow::SetStartupCommandline(array_view<const winrt::hstring> args,
|
||||
winrt::hstring cwd,
|
||||
winrt::hstring env)
|
||||
{
|
||||
_WindowProperties->SetInitialCwd(std::move(cwd));
|
||||
_WindowProperties->VirtualEnvVars(std::move(env));
|
||||
|
||||
// This is called in AppHost::ctor(), before we've created the window
|
||||
// (or called TerminalWindow::Initialize)
|
||||
@@ -1081,7 +1096,8 @@ namespace winrt::TerminalApp::implementation
|
||||
// - the result of the first command who's parsing returned a non-zero code,
|
||||
// or 0. (see TerminalWindow::_ParseArgs)
|
||||
int32_t TerminalWindow::ExecuteCommandline(array_view<const winrt::hstring> args,
|
||||
const winrt::hstring& cwd)
|
||||
const winrt::hstring& cwd,
|
||||
const winrt::hstring& env)
|
||||
{
|
||||
::TerminalApp::AppCommandlineArgs appArgs;
|
||||
auto result = appArgs.ParseArgs(args);
|
||||
@@ -1089,7 +1105,7 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
auto actions = winrt::single_threaded_vector<ActionAndArgs>(std::move(appArgs.GetStartupActions()));
|
||||
|
||||
_root->ProcessStartupActions(actions, false, cwd);
|
||||
_root->ProcessStartupActions(actions, false, cwd, env);
|
||||
|
||||
if (appArgs.IsHandoffListener())
|
||||
{
|
||||
|
||||
@@ -56,6 +56,8 @@ namespace winrt::TerminalApp::implementation
|
||||
// Used for setting the initial CWD, before we have XAML set up for property change notifications.
|
||||
void SetInitialCwd(winrt::hstring cwd) { _VirtualWorkingDirectory = std::move(cwd); };
|
||||
|
||||
til::property<winrt::hstring> VirtualEnvVars;
|
||||
|
||||
private:
|
||||
winrt::hstring _WindowName{};
|
||||
uint64_t _WindowId{ 0 };
|
||||
@@ -77,9 +79,9 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
bool HasCommandlineArguments() const noexcept;
|
||||
|
||||
int32_t SetStartupCommandline(array_view<const winrt::hstring> actions, winrt::hstring cwd);
|
||||
int32_t SetStartupCommandline(array_view<const winrt::hstring> actions, winrt::hstring cwd, winrt::hstring env);
|
||||
void SetStartupContent(const winrt::hstring& content, const Windows::Foundation::IReference<Windows::Foundation::Rect>& contentBounds);
|
||||
int32_t ExecuteCommandline(array_view<const winrt::hstring> actions, const winrt::hstring& cwd);
|
||||
int32_t ExecuteCommandline(array_view<const winrt::hstring> actions, const winrt::hstring& cwd, const winrt::hstring& env);
|
||||
void SetSettingsStartupArgs(const std::vector<winrt::Microsoft::Terminal::Settings::Model::ActionAndArgs>& actions);
|
||||
winrt::hstring ParseCommandlineMessage();
|
||||
bool ShouldExitEarly();
|
||||
@@ -200,6 +202,7 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
void _RefreshThemeRoutine();
|
||||
void _OnLoaded(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
|
||||
void _pageInitialized(const IInspectable& sender, const IInspectable& eventArgs);
|
||||
void _OpenSettingsUI();
|
||||
|
||||
winrt::Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> _contentStringToActions(const winrt::hstring& content,
|
||||
|
||||
@@ -53,9 +53,9 @@ namespace TerminalApp
|
||||
|
||||
Boolean HasCommandlineArguments();
|
||||
|
||||
Int32 SetStartupCommandline(String[] commands, String cwd);
|
||||
Int32 SetStartupCommandline(String[] commands, String cwd, String env);
|
||||
void SetStartupContent(String json, Windows.Foundation.IReference<Windows.Foundation.Rect> bounds);
|
||||
Int32 ExecuteCommandline(String[] commands, String cwd);
|
||||
Int32 ExecuteCommandline(String[] commands, String cwd, String env);
|
||||
String ParseCommandlineMessage { get; };
|
||||
Boolean ShouldExitEarly { get; };
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <winrt/Windows.Media.h>
|
||||
#include <winrt/Windows.Media.Core.h>
|
||||
#include <winrt/Windows.Media.Playback.h>
|
||||
#include <winrt/Windows.Management.Deployment.h>
|
||||
|
||||
#include <winrt/Microsoft.UI.Xaml.Controls.h>
|
||||
#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <conpty-static.h>
|
||||
#include <til/string.h>
|
||||
#include <til/env.h>
|
||||
#include <winternl.h>
|
||||
|
||||
#include "CTerminalHandoff.h"
|
||||
@@ -90,14 +89,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
||||
});
|
||||
|
||||
// Populate the environment map with the current environment.
|
||||
if (_reloadEnvironmentVariables)
|
||||
{
|
||||
environment.regenerate();
|
||||
}
|
||||
else
|
||||
{
|
||||
environment = til::env::from_current_environment();
|
||||
}
|
||||
environment = _initialEnv;
|
||||
|
||||
{
|
||||
// Convert connection Guid to string and ignore the enclosing '{}'.
|
||||
@@ -235,7 +227,9 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
||||
Windows::Foundation::Collections::ValueSet ConptyConnection::CreateSettings(const winrt::hstring& cmdline,
|
||||
const winrt::hstring& startingDirectory,
|
||||
const winrt::hstring& startingTitle,
|
||||
const Windows::Foundation::Collections::IMapView<hstring, hstring>& environment,
|
||||
bool reloadEnvironmentVariables,
|
||||
const winrt::hstring& initialEnvironment,
|
||||
const Windows::Foundation::Collections::IMapView<hstring, hstring>& environmentOverrides,
|
||||
uint32_t rows,
|
||||
uint32_t columns,
|
||||
const winrt::guid& guid,
|
||||
@@ -246,23 +240,35 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
||||
vs.Insert(L"commandline", Windows::Foundation::PropertyValue::CreateString(cmdline));
|
||||
vs.Insert(L"startingDirectory", Windows::Foundation::PropertyValue::CreateString(startingDirectory));
|
||||
vs.Insert(L"startingTitle", Windows::Foundation::PropertyValue::CreateString(startingTitle));
|
||||
vs.Insert(L"reloadEnvironmentVariables", Windows::Foundation::PropertyValue::CreateBoolean(reloadEnvironmentVariables));
|
||||
vs.Insert(L"initialRows", Windows::Foundation::PropertyValue::CreateUInt32(rows));
|
||||
vs.Insert(L"initialCols", Windows::Foundation::PropertyValue::CreateUInt32(columns));
|
||||
vs.Insert(L"guid", Windows::Foundation::PropertyValue::CreateGuid(guid));
|
||||
vs.Insert(L"profileGuid", Windows::Foundation::PropertyValue::CreateGuid(profileGuid));
|
||||
|
||||
if (environment)
|
||||
if (environmentOverrides)
|
||||
{
|
||||
Windows::Foundation::Collections::ValueSet env{};
|
||||
for (const auto& [k, v] : environment)
|
||||
for (const auto& [k, v] : environmentOverrides)
|
||||
{
|
||||
env.Insert(k, Windows::Foundation::PropertyValue::CreateString(v));
|
||||
}
|
||||
vs.Insert(L"environment", env);
|
||||
}
|
||||
|
||||
if (!initialEnvironment.empty())
|
||||
{
|
||||
vs.Insert(L"initialEnvironment", Windows::Foundation::PropertyValue::CreateString(initialEnvironment));
|
||||
}
|
||||
return vs;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T unbox_prop_or(const Windows::Foundation::Collections::ValueSet& blob, std::wstring_view key, T defaultValue)
|
||||
{
|
||||
return winrt::unbox_value_or<T>(blob.TryLookup(key).try_as<Windows::Foundation::IPropertyValue>(), defaultValue);
|
||||
}
|
||||
|
||||
void ConptyConnection::Initialize(const Windows::Foundation::Collections::ValueSet& settings)
|
||||
{
|
||||
if (settings)
|
||||
@@ -271,26 +277,47 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
||||
// auto bad = unbox_value_or<hstring>(settings.TryLookup(L"foo").try_as<IPropertyValue>(), nullptr);
|
||||
// It'll just return null
|
||||
|
||||
_commandline = winrt::unbox_value_or<winrt::hstring>(settings.TryLookup(L"commandline").try_as<Windows::Foundation::IPropertyValue>(), _commandline);
|
||||
_startingDirectory = winrt::unbox_value_or<winrt::hstring>(settings.TryLookup(L"startingDirectory").try_as<Windows::Foundation::IPropertyValue>(), _startingDirectory);
|
||||
_startingTitle = winrt::unbox_value_or<winrt::hstring>(settings.TryLookup(L"startingTitle").try_as<Windows::Foundation::IPropertyValue>(), _startingTitle);
|
||||
_rows = winrt::unbox_value_or<uint32_t>(settings.TryLookup(L"initialRows").try_as<Windows::Foundation::IPropertyValue>(), _rows);
|
||||
_cols = winrt::unbox_value_or<uint32_t>(settings.TryLookup(L"initialCols").try_as<Windows::Foundation::IPropertyValue>(), _cols);
|
||||
_guid = winrt::unbox_value_or<winrt::guid>(settings.TryLookup(L"guid").try_as<Windows::Foundation::IPropertyValue>(), _guid);
|
||||
_commandline = unbox_prop_or<winrt::hstring>(settings, L"commandline", _commandline);
|
||||
_startingDirectory = unbox_prop_or<winrt::hstring>(settings, L"startingDirectory", _startingDirectory);
|
||||
_startingTitle = unbox_prop_or<winrt::hstring>(settings, L"startingTitle", _startingTitle);
|
||||
_rows = unbox_prop_or<uint32_t>(settings, L"initialRows", _rows);
|
||||
_cols = unbox_prop_or<uint32_t>(settings, L"initialCols", _cols);
|
||||
_guid = unbox_prop_or<winrt::guid>(settings, L"guid", _guid);
|
||||
_environment = settings.TryLookup(L"environment").try_as<Windows::Foundation::Collections::ValueSet>();
|
||||
if constexpr (Feature_VtPassthroughMode::IsEnabled())
|
||||
{
|
||||
_passthroughMode = winrt::unbox_value_or<bool>(settings.TryLookup(L"passthroughMode").try_as<Windows::Foundation::IPropertyValue>(), _passthroughMode);
|
||||
_passthroughMode = unbox_prop_or<bool>(settings, L"passthroughMode", _passthroughMode);
|
||||
}
|
||||
_inheritCursor = winrt::unbox_value_or<bool>(settings.TryLookup(L"inheritCursor").try_as<Windows::Foundation::IPropertyValue>(), _inheritCursor);
|
||||
_reloadEnvironmentVariables = winrt::unbox_value_or<bool>(settings.TryLookup(L"reloadEnvironmentVariables").try_as<Windows::Foundation::IPropertyValue>(),
|
||||
_reloadEnvironmentVariables);
|
||||
_profileGuid = winrt::unbox_value_or<winrt::guid>(settings.TryLookup(L"profileGuid").try_as<Windows::Foundation::IPropertyValue>(), _profileGuid);
|
||||
}
|
||||
_inheritCursor = unbox_prop_or<bool>(settings, L"inheritCursor", _inheritCursor);
|
||||
_profileGuid = unbox_prop_or<winrt::guid>(settings, L"profileGuid", _profileGuid);
|
||||
|
||||
if (_guid == guid{})
|
||||
{
|
||||
_guid = Utils::CreateGuid();
|
||||
const auto& initialEnvironment{ unbox_prop_or<winrt::hstring>(settings, L"initialEnvironment", L"") };
|
||||
|
||||
const bool reloadEnvironmentVariables = unbox_prop_or<bool>(settings, L"reloadEnvironmentVariables", false);
|
||||
|
||||
if (reloadEnvironmentVariables)
|
||||
{
|
||||
_initialEnv.regenerate();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!initialEnvironment.empty())
|
||||
{
|
||||
_initialEnv = til::env{ initialEnvironment.c_str() };
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we were not explicitly provided an "initial" env block to
|
||||
// treat as our original one, then just use our actual current
|
||||
// env block.
|
||||
_initialEnv = til::env::from_current_environment();
|
||||
}
|
||||
}
|
||||
|
||||
if (_guid == guid{})
|
||||
{
|
||||
_guid = Utils::CreateGuid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,5 +761,4 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
||||
co_await winrt::resume_background(); // move to background
|
||||
connection.reset(); // explicitly destruct
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "ConnectionStateHolder.h"
|
||||
|
||||
#include "ITerminalHandoff.h"
|
||||
#include <til/env.h>
|
||||
|
||||
namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
||||
{
|
||||
@@ -49,7 +50,9 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
||||
static Windows::Foundation::Collections::ValueSet CreateSettings(const winrt::hstring& cmdline,
|
||||
const winrt::hstring& startingDirectory,
|
||||
const winrt::hstring& startingTitle,
|
||||
const Windows::Foundation::Collections::IMapView<hstring, hstring>& environment,
|
||||
bool reloadEnvironmentVariables,
|
||||
const winrt::hstring& initialEnvironment,
|
||||
const Windows::Foundation::Collections::IMapView<hstring, hstring>& environmentOverrides,
|
||||
uint32_t rows,
|
||||
uint32_t columns,
|
||||
const winrt::guid& guid,
|
||||
@@ -91,7 +94,8 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
||||
std::array<char, 4096> _buffer{};
|
||||
bool _passthroughMode{};
|
||||
bool _inheritCursor{ false };
|
||||
bool _reloadEnvironmentVariables{};
|
||||
|
||||
til::env _initialEnv{};
|
||||
guid _profileGuid{};
|
||||
|
||||
struct StartupInfoFromDefTerm
|
||||
|
||||
@@ -28,7 +28,9 @@ namespace Microsoft.Terminal.TerminalConnection
|
||||
static Windows.Foundation.Collections.ValueSet CreateSettings(String cmdline,
|
||||
String startingDirectory,
|
||||
String startingTitle,
|
||||
IMapView<String, String> environment,
|
||||
Boolean reloadEnvironmentVariables,
|
||||
String initialEnvironment,
|
||||
IMapView<String, String> environmentOverrides,
|
||||
UInt32 rows,
|
||||
UInt32 columns,
|
||||
Guid guid,
|
||||
|
||||
@@ -86,6 +86,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
{
|
||||
_settings = winrt::make_self<implementation::ControlSettings>(settings, unfocusedAppearance);
|
||||
_terminal = std::make_shared<::Microsoft::Terminal::Core::Terminal>();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
_setupDispatcherAndCallbacks();
|
||||
|
||||
@@ -197,7 +198,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
[weakTerminal = std::weak_ptr{ _terminal }]() {
|
||||
if (const auto t = weakTerminal.lock())
|
||||
{
|
||||
auto lock = t->LockForWriting();
|
||||
const auto lock = t->LockForWriting();
|
||||
t->UpdatePatternsUnderLock();
|
||||
}
|
||||
});
|
||||
@@ -282,6 +283,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// Get our current size in rows/cols, and hook them up to
|
||||
// this connection too.
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
const auto vp = _terminal->GetViewport();
|
||||
const auto width = vp.Width();
|
||||
const auto height = vp.Height();
|
||||
@@ -318,7 +320,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
_compositionScale = compositionScale;
|
||||
|
||||
{ // scope for terminalLock
|
||||
auto terminalLock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
if (_initializedTerminal.load(std::memory_order_relaxed))
|
||||
{
|
||||
@@ -427,6 +429,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
{
|
||||
if (_initializedTerminal.load(std::memory_order_relaxed))
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_renderer->EnablePainting();
|
||||
}
|
||||
}
|
||||
@@ -489,6 +492,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
_handleControlC();
|
||||
}
|
||||
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
return _terminal->SendCharEvent(ch, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@@ -517,18 +521,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// modifier key. We'll wait for a real keystroke to dismiss the
|
||||
// GH #7395 - don't update selection when taking PrintScreen
|
||||
// selection.
|
||||
return HasSelection() && ::Microsoft::Terminal::Core::Terminal::IsInputKey(vkey);
|
||||
return _terminal->IsSelectionActive() && ::Microsoft::Terminal::Core::Terminal::IsInputKey(vkey);
|
||||
}
|
||||
|
||||
bool ControlCore::TryMarkModeKeybinding(const WORD vkey,
|
||||
const ::Microsoft::Terminal::Core::ControlKeyStates mods)
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
|
||||
if (_shouldTryUpdateSelection(vkey) && _terminal->SelectionMode() == ::Terminal::SelectionInteractionMode::Mark)
|
||||
{
|
||||
if (vkey == 'A' && !mods.IsAltPressed() && !mods.IsShiftPressed() && mods.IsCtrlPressed())
|
||||
{
|
||||
// Ctrl + A --> Select all
|
||||
auto lock = _terminal->LockForWriting();
|
||||
_terminal->SelectAll();
|
||||
_updateSelectionUI();
|
||||
return true;
|
||||
@@ -536,7 +541,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
else if (vkey == VK_TAB && !mods.IsAltPressed() && !mods.IsCtrlPressed() && _settings->DetectURLs())
|
||||
{
|
||||
// [Shift +] Tab --> next/previous hyperlink
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto direction = mods.IsShiftPressed() ? ::Terminal::SearchDirection::Backward : ::Terminal::SearchDirection::Forward;
|
||||
_terminal->SelectHyperlink(direction);
|
||||
_updateSelectionUI();
|
||||
@@ -545,14 +549,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
else if (vkey == VK_RETURN && mods.IsCtrlPressed() && !mods.IsAltPressed() && !mods.IsShiftPressed())
|
||||
{
|
||||
// Ctrl + Enter --> Open URL
|
||||
auto lock = _terminal->LockForReading();
|
||||
if (const auto uri = _terminal->GetHyperlinkAtBufferPosition(_terminal->GetSelectionAnchor()); !uri.empty())
|
||||
{
|
||||
lock.unlock();
|
||||
_OpenHyperlinkHandlers(*this, winrt::make<OpenHyperlinkEventArgs>(winrt::hstring{ uri }));
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto selectedText = _terminal->GetTextBuffer().GetPlainText(_terminal->GetSelectionAnchor(), _terminal->GetSelectionEnd());
|
||||
lock.unlock();
|
||||
_OpenHyperlinkHandlers(*this, winrt::make<OpenHyperlinkEventArgs>(winrt::hstring{ selectedText }));
|
||||
}
|
||||
return true;
|
||||
@@ -560,7 +565,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
else if (vkey == VK_RETURN && !mods.IsCtrlPressed() && !mods.IsAltPressed())
|
||||
{
|
||||
// [Shift +] Enter --> copy text
|
||||
// Don't lock here! CopySelectionToClipboard already locks for you!
|
||||
CopySelectionToClipboard(mods.IsShiftPressed(), nullptr);
|
||||
_terminal->ClearSelection();
|
||||
_updateSelectionUI();
|
||||
@@ -575,7 +579,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
else if (const auto updateSlnParams{ _terminal->ConvertKeyEventToUpdateSelectionParams(mods, vkey) })
|
||||
{
|
||||
// try to update the selection
|
||||
auto lock = _terminal->LockForWriting();
|
||||
_terminal->UpdateSelection(updateSlnParams->first, updateSlnParams->second, mods);
|
||||
_updateSelectionUI();
|
||||
return true;
|
||||
@@ -599,6 +602,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
const ControlKeyStates modifiers,
|
||||
const bool keyDown)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
// Update the selection, if it's present
|
||||
// GH#8522, GH#3758 - Only modify the selection on key _down_. If we
|
||||
// modify on key up, then there's chance that we'll immediately dismiss
|
||||
@@ -608,7 +613,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// try to update the selection
|
||||
if (const auto updateSlnParams{ _terminal->ConvertKeyEventToUpdateSelectionParams(modifiers, vkey) })
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
_terminal->UpdateSelection(updateSlnParams->first, updateSlnParams->second, modifiers);
|
||||
_updateSelectionUI();
|
||||
return true;
|
||||
@@ -646,17 +650,18 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
const short wheelDelta,
|
||||
const TerminalInput::MouseButtonState state)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
|
||||
}
|
||||
|
||||
void ControlCore::UserScrollViewport(const int viewTop)
|
||||
{
|
||||
// Clear the regex pattern tree so the renderer does not try to render them while scrolling
|
||||
_terminal->ClearPatternTree();
|
||||
|
||||
// This is a scroll event that wasn't initiated by the terminal
|
||||
// itself - it was initiated by the mouse wheel, or the scrollbar.
|
||||
_terminal->UserScrollViewport(viewTop);
|
||||
{
|
||||
// This is a scroll event that wasn't initiated by the terminal
|
||||
// itself - it was initiated by the mouse wheel, or the scrollbar.
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->UserScrollViewport(viewTop);
|
||||
}
|
||||
|
||||
const auto shared = _shared.lock_shared();
|
||||
if (shared->updatePatternLocations)
|
||||
@@ -696,6 +701,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// cleartype -> grayscale if the BG is transparent / acrylic.
|
||||
if (_renderEngine)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_renderEngine->EnableTransparentBackground(_isBackgroundTransparent());
|
||||
_renderer->NotifyPaintFrame();
|
||||
}
|
||||
@@ -707,7 +713,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
void ControlCore::ToggleShaderEffects()
|
||||
{
|
||||
const auto path = _settings->PixelShaderPath();
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
// Originally, this action could be used to enable the retro effects
|
||||
// even when they're set to `false` in the settings. If the user didn't
|
||||
// specify a custom pixel shader, manually enable the legacy retro
|
||||
@@ -755,7 +761,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
decltype(_terminal->GetHyperlinkIntervalFromViewportPosition({})) newInterval{ std::nullopt };
|
||||
if (terminalPosition.has_value())
|
||||
{
|
||||
auto lock = _terminal->LockForReading(); // Lock for the duration of our reads.
|
||||
const auto lock = _terminal->LockForReading();
|
||||
newId = _terminal->GetHyperlinkIdAtViewportPosition(*terminalPosition);
|
||||
newInterval = _terminal->GetHyperlinkIntervalFromViewportPosition(*terminalPosition);
|
||||
}
|
||||
@@ -770,7 +776,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// wouldn't be able to ask us about the hyperlink text/position
|
||||
// without deadlocking us.
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
_lastHoveredId = newId;
|
||||
_lastHoveredInterval = newInterval;
|
||||
@@ -785,16 +791,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
winrt::hstring ControlCore::GetHyperlink(const Core::Point pos) const
|
||||
{
|
||||
// Lock for the duration of our reads.
|
||||
auto lock = _terminal->LockForReading();
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return winrt::hstring{ _terminal->GetHyperlinkAtViewportPosition(til::point{ pos }) };
|
||||
}
|
||||
|
||||
winrt::hstring ControlCore::HoveredUriText() const
|
||||
{
|
||||
auto lock = _terminal->LockForReading(); // Lock for the duration of our reads.
|
||||
if (_lastHoveredCell.has_value())
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
auto uri{ _terminal->GetHyperlinkAtViewportPosition(*_lastHoveredCell) };
|
||||
uri.resize(std::min<size_t>(1024u, uri.size())); // Truncate for display
|
||||
return winrt::hstring{ uri };
|
||||
@@ -814,7 +819,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
{
|
||||
_settings = winrt::make_self<implementation::ControlSettings>(settings, newAppearance);
|
||||
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
_cellWidth = CSSLengthPercentage::FromString(_settings->CellWidth().c_str());
|
||||
_cellHeight = CSSLengthPercentage::FromString(_settings->CellHeight().c_str());
|
||||
@@ -856,7 +861,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - INVARIANT: This method can only be called if the caller DOES NOT HAVE writing lock on the terminal.
|
||||
void ControlCore::ApplyAppearance(const bool& focused)
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
const auto& newAppearance{ focused ? _settings->FocusedAppearance() : _settings->UnfocusedAppearance() };
|
||||
// Update the terminal core with its new Core settings
|
||||
_terminal->UpdateAppearance(*newAppearance);
|
||||
@@ -1101,7 +1106,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
_panelHeight = height;
|
||||
_compositionScale = scale;
|
||||
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
if (scaleChanged)
|
||||
{
|
||||
// _updateFont relies on the new _compositionScale set above
|
||||
@@ -1112,7 +1117,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void ControlCore::SetSelectionAnchor(const til::point position)
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->SetSelectionAnchor(position);
|
||||
}
|
||||
|
||||
@@ -1123,7 +1128,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// to throw it all in a struct and pass it along.
|
||||
Control::SelectionData ControlCore::SelectionInfo() const
|
||||
{
|
||||
auto lock = _terminal->LockForReading();
|
||||
const auto lock = _terminal->LockForReading();
|
||||
Control::SelectionData info;
|
||||
|
||||
const auto start{ _terminal->SelectionStartForRendering() };
|
||||
@@ -1146,15 +1151,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - position: the point in terminal coordinates (in cells, not pixels)
|
||||
void ControlCore::SetEndSelectionPoint(const til::point position)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
if (!_terminal->IsSelectionActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Have to take the lock because the renderer will not draw correctly if
|
||||
// you move its endpoints while it is generating a frame.
|
||||
auto lock = _terminal->LockForWriting();
|
||||
|
||||
til::point terminalPosition{
|
||||
std::clamp(position.x, 0, _terminal->GetViewport().Width() - 1),
|
||||
std::clamp(position.y, 0, _terminal->GetViewport().Height() - 1)
|
||||
@@ -1182,6 +1185,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
bool ControlCore::CopySelectionToClipboard(bool singleLine,
|
||||
const Windows::Foundation::IReference<CopyFormat>& formats)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
// no selection --> nothing to copy
|
||||
if (!_terminal->IsSelectionActive())
|
||||
{
|
||||
@@ -1231,21 +1236,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void ControlCore::SelectAll()
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->SelectAll();
|
||||
_updateSelectionUI();
|
||||
}
|
||||
|
||||
void ControlCore::ClearSelection()
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->ClearSelection();
|
||||
_updateSelectionUI();
|
||||
}
|
||||
|
||||
bool ControlCore::ToggleBlockSelection()
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
if (_terminal->IsSelectionActive())
|
||||
{
|
||||
_terminal->SetBlockSelection(!_terminal->IsBlockSelection());
|
||||
@@ -1260,7 +1265,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void ControlCore::ToggleMarkMode()
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->ToggleMarkMode();
|
||||
_updateSelectionUI();
|
||||
}
|
||||
@@ -1272,6 +1277,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
bool ControlCore::SwitchSelectionEndpoint()
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
if (_terminal->IsSelectionActive())
|
||||
{
|
||||
_terminal->SwitchSelectionEndpoint();
|
||||
@@ -1283,6 +1289,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
bool ControlCore::ExpandSelectionToWord()
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
if (_terminal->IsSelectionActive())
|
||||
{
|
||||
_terminal->ExpandSelectionToWord();
|
||||
@@ -1297,6 +1304,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// before sending it over the terminal's connection.
|
||||
void ControlCore::PasteText(const winrt::hstring& hstr)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->WritePastedText(hstr);
|
||||
_terminal->ClearSelection();
|
||||
_updateSelectionUI();
|
||||
@@ -1346,21 +1354,25 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
hstring ControlCore::Title()
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return hstring{ _terminal->GetConsoleTitle() };
|
||||
}
|
||||
|
||||
hstring ControlCore::WorkingDirectory() const
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return hstring{ _terminal->GetWorkingDirectory() };
|
||||
}
|
||||
|
||||
bool ControlCore::BracketedPasteEnabled() const noexcept
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->IsXtermBracketedPasteModeEnabled();
|
||||
}
|
||||
|
||||
Windows::Foundation::IReference<winrt::Windows::UI::Color> ControlCore::TabColor() noexcept
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
auto coreColor = _terminal->GetTabColor();
|
||||
return coreColor.has_value() ? Windows::Foundation::IReference<winrt::Windows::UI::Color>{ static_cast<winrt::Windows::UI::Color>(coreColor.value()) } :
|
||||
nullptr;
|
||||
@@ -1368,11 +1380,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
til::color ControlCore::ForegroundColor() const
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->GetRenderSettings().GetColorAlias(ColorAlias::DefaultForeground);
|
||||
}
|
||||
|
||||
til::color ControlCore::BackgroundColor() const
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->GetRenderSettings().GetColorAlias(ColorAlias::DefaultBackground);
|
||||
}
|
||||
|
||||
@@ -1382,6 +1396,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - The taskbar state of this control
|
||||
const size_t ControlCore::TaskbarState() const noexcept
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->GetTaskbarState();
|
||||
}
|
||||
|
||||
@@ -1391,11 +1406,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - The taskbar progress of this control
|
||||
const size_t ControlCore::TaskbarProgress() const noexcept
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->GetTaskbarProgress();
|
||||
}
|
||||
|
||||
int ControlCore::ScrollOffset()
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->GetScrollOffset();
|
||||
}
|
||||
|
||||
@@ -1406,6 +1423,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - The height of the terminal in lines of text
|
||||
int ControlCore::ViewHeight() const
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->GetViewport().Height();
|
||||
}
|
||||
|
||||
@@ -1416,6 +1434,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - The height of the terminal in lines of text
|
||||
int ControlCore::BufferHeight() const
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->GetBufferHeight();
|
||||
}
|
||||
|
||||
@@ -1463,12 +1482,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the regex pattern tree so the renderer does not try to render them while scrolling
|
||||
// We're **NOT** taking the lock here unlike _scrollbarChangeHandler because
|
||||
// we are already under lock (since this usually happens as a result of writing).
|
||||
// TODO GH#9617: refine locking around pattern tree
|
||||
_terminal->ClearPatternTree();
|
||||
|
||||
// Start the throttled update of our scrollbar.
|
||||
auto update{ winrt::make<ScrollPositionChangedArgs>(viewTop,
|
||||
viewHeight,
|
||||
@@ -1527,6 +1540,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
bool ControlCore::HasSelection() const
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->IsSelectionActive();
|
||||
}
|
||||
|
||||
@@ -1538,6 +1552,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
Windows::Foundation::Collections::IVector<winrt::hstring> ControlCore::SelectedText(bool trimTrailingWhitespace) const
|
||||
{
|
||||
// RetrieveSelectedTextFromBuffer will lock while it's reading
|
||||
const auto lock = _terminal->LockForReading();
|
||||
const auto internalResult{ _terminal->RetrieveSelectedTextFromBuffer(trimTrailingWhitespace).text };
|
||||
|
||||
auto result = winrt::single_threaded_vector<winrt::hstring>();
|
||||
@@ -1565,11 +1580,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - <none>
|
||||
void ControlCore::Search(const winrt::hstring& text, const bool goForward, const bool caseSensitive)
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
if (_searcher.ResetIfStale(*GetRenderData(), text, !goForward, !caseSensitive))
|
||||
{
|
||||
_searcher.MovePastCurrentSelection();
|
||||
_searcher.MoveToCurrentSelection();
|
||||
_cachedSearchResultRows = {};
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1600,12 +1616,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
Windows::Foundation::Collections::IVector<int32_t> ControlCore::SearchResultRows()
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
if (_searcher.ResetIfStale(*GetRenderData()))
|
||||
const auto lock = _terminal->LockForReading();
|
||||
|
||||
if (!_cachedSearchResultRows)
|
||||
{
|
||||
auto results = std::vector<int32_t>();
|
||||
|
||||
auto lastRow = til::CoordTypeMin;
|
||||
|
||||
for (const auto& match : _searcher.Results())
|
||||
{
|
||||
const auto row{ match.start.y };
|
||||
@@ -1615,6 +1632,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
lastRow = row;
|
||||
}
|
||||
}
|
||||
|
||||
_cachedSearchResultRows = winrt::single_threaded_vector<int32_t>(std::move(results));
|
||||
}
|
||||
|
||||
@@ -1690,7 +1708,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void ControlCore::BlinkAttributeTick()
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
auto& renderSettings = _terminal->GetRenderSettings();
|
||||
renderSettings.ToggleBlinkRendition(*_renderer);
|
||||
@@ -1698,13 +1716,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void ControlCore::BlinkCursor()
|
||||
{
|
||||
if (!_terminal->IsCursorBlinkingAllowed() &&
|
||||
_terminal->IsCursorVisible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// SetCursorOn will take the write lock for you.
|
||||
_terminal->SetCursorOn(!_terminal->IsCursorOn());
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->BlinkCursor();
|
||||
}
|
||||
|
||||
bool ControlCore::CursorOn() const
|
||||
@@ -1714,22 +1727,26 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void ControlCore::CursorOn(const bool isCursorOn)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->SetCursorOn(isCursorOn);
|
||||
}
|
||||
|
||||
void ControlCore::ResumeRendering()
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_renderer->ResetErrorStateAndResume();
|
||||
}
|
||||
|
||||
bool ControlCore::IsVtMouseModeEnabled() const
|
||||
{
|
||||
return _terminal != nullptr && _terminal->IsTrackingMouseInput();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
return _terminal->IsTrackingMouseInput();
|
||||
}
|
||||
bool ControlCore::ShouldSendAlternateScroll(const unsigned int uiButton,
|
||||
const int32_t delta) const
|
||||
{
|
||||
return _terminal != nullptr && _terminal->ShouldSendAlternateScroll(uiButton, delta);
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
return _terminal->ShouldSendAlternateScroll(uiButton, delta);
|
||||
}
|
||||
|
||||
Core::Point ControlCore::CursorPosition() const
|
||||
@@ -1740,7 +1757,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
return { 0, 0 };
|
||||
}
|
||||
|
||||
auto lock = _terminal->LockForReading();
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return _terminal->GetViewportRelativeCursorPosition().to_core_point();
|
||||
}
|
||||
|
||||
@@ -1756,7 +1773,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
const bool isOnOriginalPosition,
|
||||
bool& selectionNeedsToBeCopied)
|
||||
{
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
// handle ALT key
|
||||
_terminal->SetBlockSelection(altEnabled);
|
||||
|
||||
@@ -1782,14 +1799,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// the selection (we need to reset selection on double-click or
|
||||
// triple-click, so it captures the word or the line, rather than
|
||||
// extending the selection)
|
||||
if (HasSelection() && (!shiftEnabled || isOnOriginalPosition))
|
||||
if (_terminal->IsSelectionActive() && (!shiftEnabled || isOnOriginalPosition))
|
||||
{
|
||||
// Reset the selection
|
||||
_terminal->ClearSelection();
|
||||
selectionNeedsToBeCopied = false; // there's no selection, so there's nothing to update
|
||||
}
|
||||
|
||||
if (shiftEnabled && HasSelection())
|
||||
if (shiftEnabled && _terminal->IsSelectionActive())
|
||||
{
|
||||
// If shift is pressed and there is a selection we extend it using
|
||||
// the selection mode (expand the "end" selection point)
|
||||
@@ -1878,6 +1895,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - Updates the renderer's representation of the selection as well as the selection marker overlay in TermControl
|
||||
void ControlCore::_updateSelectionUI()
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_renderer->TriggerSelection();
|
||||
// only show the markers if we're doing a keyboard selection or in mark mode
|
||||
const bool showMarkers{ _terminal->SelectionMode() >= ::Microsoft::Terminal::Core::Terminal::SelectionInteractionMode::Keyboard };
|
||||
@@ -1887,10 +1905,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
void ControlCore::AttachUiaEngine(::Microsoft::Console::Render::IRenderEngine* const pEngine)
|
||||
{
|
||||
// _renderer will always exist since it's introduced in the ctor
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_renderer->AddRenderEngine(pEngine);
|
||||
}
|
||||
void ControlCore::DetachUiaEngine(::Microsoft::Console::Render::IRenderEngine* const pEngine)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_renderer->RemoveRenderEngine(pEngine);
|
||||
}
|
||||
|
||||
@@ -1918,7 +1938,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
{
|
||||
try
|
||||
{
|
||||
_terminal->Write(hstr);
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->Write(hstr);
|
||||
}
|
||||
|
||||
// Start the throttled update of where our hyperlinks are.
|
||||
const auto shared = _shared.lock_shared();
|
||||
@@ -1959,6 +1982,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
{
|
||||
if (clearType == Control::ClearBufferType::Scrollback || clearType == Control::ClearBufferType::All)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->EraseScrollback();
|
||||
}
|
||||
|
||||
@@ -1976,7 +2000,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
hstring ControlCore::ReadEntireBuffer() const
|
||||
{
|
||||
auto terminalLock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
const auto& textBuffer = _terminal->GetTextBuffer();
|
||||
|
||||
@@ -2004,7 +2028,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// Get all of our recent commands. This will only really work if the user has enabled shell integration.
|
||||
Control::CommandHistoryContext ControlCore::CommandHistory() const
|
||||
{
|
||||
auto terminalLock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
const auto& textBuffer = _terminal->GetTextBuffer();
|
||||
|
||||
std::vector<winrt::hstring> commands;
|
||||
@@ -2089,6 +2113,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
s = _terminal->GetColorScheme();
|
||||
}
|
||||
|
||||
@@ -2112,8 +2137,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - <none>
|
||||
void ControlCore::ColorScheme(const Core::Scheme& scheme)
|
||||
{
|
||||
auto l{ _terminal->LockForWriting() };
|
||||
|
||||
_settings->FocusedAppearance()->DefaultForeground(scheme.Foreground);
|
||||
_settings->FocusedAppearance()->DefaultBackground(scheme.Background);
|
||||
_settings->FocusedAppearance()->CursorColor(scheme.CursorColor);
|
||||
@@ -2136,10 +2159,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
_settings->FocusedAppearance()->SetColorTableEntry(14, scheme.BrightCyan);
|
||||
_settings->FocusedAppearance()->SetColorTableEntry(15, scheme.BrightWhite);
|
||||
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->ApplyScheme(scheme);
|
||||
|
||||
_renderEngine->SetSelectionBackground(til::color{ _settings->SelectionBackground() });
|
||||
|
||||
_renderer->TriggerRedrawAll(true);
|
||||
}
|
||||
|
||||
@@ -2211,6 +2233,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// focused.
|
||||
const auto previous = std::exchange(_isReadOnly, false);
|
||||
const auto restore = wil::scope_exit([&]() { _isReadOnly = previous; });
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->FocusChanged(focused);
|
||||
}
|
||||
|
||||
@@ -2245,31 +2268,26 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
Windows::Foundation::Collections::IVector<Control::ScrollMark> ControlCore::ScrollMarks() const
|
||||
{
|
||||
auto internalMarks{ _terminal->GetScrollMarks() };
|
||||
auto v = winrt::single_threaded_observable_vector<Control::ScrollMark>();
|
||||
const auto lock = _terminal->LockForReading();
|
||||
const auto& internalMarks = _terminal->GetScrollMarks();
|
||||
std::vector<Control::ScrollMark> v;
|
||||
|
||||
v.reserve(internalMarks.size());
|
||||
|
||||
for (const auto& mark : internalMarks)
|
||||
{
|
||||
Control::ScrollMark m{};
|
||||
|
||||
// sneaky: always evaluate the color of the mark to a real value
|
||||
// before shoving it into the optional. If the mark doesn't have a
|
||||
// specific color set, we'll use the value from the color table
|
||||
// that's appropriate for this category of mark. If we do have a
|
||||
// color set, then great we'll use that. The TermControl can then
|
||||
// always use the value in the Mark regardless if it was actually
|
||||
// set or not.
|
||||
m.Color = OptionalFromColor(_terminal->GetColorForMark(mark));
|
||||
m.Start = mark.start.to_core_point();
|
||||
m.End = mark.end.to_core_point();
|
||||
|
||||
v.Append(m);
|
||||
v.emplace_back(
|
||||
mark.start.to_core_point(),
|
||||
mark.end.to_core_point(),
|
||||
OptionalFromColor(_terminal->GetColorForMark(mark)));
|
||||
}
|
||||
|
||||
return v;
|
||||
return winrt::single_threaded_vector(std::move(v));
|
||||
}
|
||||
|
||||
void ControlCore::AddMark(const Control::ScrollMark& mark)
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
::ScrollMark m{};
|
||||
|
||||
if (mark.Color.HasValue)
|
||||
@@ -2277,7 +2295,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
m.color = til::color{ mark.Color.Color };
|
||||
}
|
||||
|
||||
if (HasSelection())
|
||||
if (_terminal->IsSelectionActive())
|
||||
{
|
||||
m.start = til::point{ _terminal->GetSelectionAnchor() };
|
||||
m.end = til::point{ _terminal->GetSelectionEnd() };
|
||||
@@ -2291,11 +2309,22 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// set the start & end to the cursor position.
|
||||
_terminal->AddMark(m, m.start, m.end, true);
|
||||
}
|
||||
void ControlCore::ClearMark() { _terminal->ClearMark(); }
|
||||
void ControlCore::ClearAllMarks() { _terminal->ClearAllMarks(); }
|
||||
|
||||
void ControlCore::ClearMark()
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->ClearMark();
|
||||
}
|
||||
|
||||
void ControlCore::ClearAllMarks()
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->ClearAllMarks();
|
||||
}
|
||||
|
||||
void ControlCore::ScrollToMark(const Control::ScrollToMarkDirection& direction)
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
const auto currentOffset = ScrollOffset();
|
||||
const auto& marks{ _terminal->GetScrollMarks() };
|
||||
|
||||
@@ -2402,15 +2431,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
const auto bufferSize{ _terminal->GetTextBuffer().GetSize() };
|
||||
bufferSize.DecrementInBounds(s.end);
|
||||
|
||||
auto lock = _terminal->LockForWriting();
|
||||
_terminal->SelectNewRegion(s.start, s.end);
|
||||
_renderer->TriggerSelection();
|
||||
}
|
||||
|
||||
void ControlCore::SelectCommand(const bool goUp)
|
||||
{
|
||||
const til::point start = HasSelection() ? (goUp ? _terminal->GetSelectionAnchor() : _terminal->GetSelectionEnd()) :
|
||||
_terminal->GetTextBuffer().GetCursor().GetPosition();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
const til::point start = _terminal->IsSelectionActive() ? (goUp ? _terminal->GetSelectionAnchor() : _terminal->GetSelectionEnd()) :
|
||||
_terminal->GetTextBuffer().GetCursor().GetPosition();
|
||||
|
||||
std::optional<::ScrollMark> nearest{ std::nullopt };
|
||||
const auto& marks{ _terminal->GetScrollMarks() };
|
||||
@@ -2449,8 +2479,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void ControlCore::SelectOutput(const bool goUp)
|
||||
{
|
||||
const til::point start = HasSelection() ? (goUp ? _terminal->GetSelectionAnchor() : _terminal->GetSelectionEnd()) :
|
||||
_terminal->GetTextBuffer().GetCursor().GetPosition();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
const til::point start = _terminal->IsSelectionActive() ? (goUp ? _terminal->GetSelectionAnchor() : _terminal->GetSelectionEnd()) :
|
||||
_terminal->GetTextBuffer().GetCursor().GetPosition();
|
||||
|
||||
std::optional<::ScrollMark> nearest{ std::nullopt };
|
||||
const auto& marks{ _terminal->GetScrollMarks() };
|
||||
@@ -2483,7 +2515,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void ControlCore::ColorSelection(const Control::SelectionColor& fg, const Control::SelectionColor& bg, Core::MatchMode matchMode)
|
||||
{
|
||||
if (HasSelection())
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
if (_terminal->IsSelectionActive())
|
||||
{
|
||||
const auto pForeground = winrt::get_self<implementation::SelectionColor>(fg);
|
||||
const auto pBackground = winrt::get_self<implementation::SelectionColor>(bg);
|
||||
@@ -2521,6 +2555,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
{
|
||||
// viewportRelativeCharacterPosition is relative to the current
|
||||
// viewport, so adjust for that:
|
||||
const auto lock = _terminal->LockForReading();
|
||||
_contextMenuBufferPosition = _terminal->GetViewport().Origin() + viewportRelativeCharacterPosition;
|
||||
}
|
||||
|
||||
@@ -2529,6 +2564,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
bool (*filter)(const ::ScrollMark&),
|
||||
til::point_span (*getSpan)(const ::ScrollMark&))
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
// Do nothing if the caller didn't give us a way to get the span to select for this mark.
|
||||
if (!getSpan)
|
||||
{
|
||||
@@ -2575,6 +2612,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
const til::point& pos,
|
||||
bool (*filter)(const ::ScrollMark&))
|
||||
{
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
// Don't show this if the click was on the selection
|
||||
if (_terminal->IsSelectionActive() &&
|
||||
_terminal->GetSelectionAnchor() <= pos &&
|
||||
|
||||
@@ -224,22 +224,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// - Initiate a paste operation.
|
||||
void ControlInteractivity::RequestPasteTextFromClipboard()
|
||||
{
|
||||
// attach ControlInteractivity::_sendPastedTextToConnection() as the
|
||||
// clipboardDataHandler. This is called when the clipboard data is
|
||||
// loaded.
|
||||
auto clipboardDataHandler = std::bind(&ControlInteractivity::_sendPastedTextToConnection, this, std::placeholders::_1);
|
||||
auto pasteArgs = winrt::make_self<PasteFromClipboardEventArgs>(clipboardDataHandler, _core->BracketedPasteEnabled());
|
||||
auto args = winrt::make<PasteFromClipboardEventArgs>(
|
||||
[core = _core](const winrt::hstring& wstr) {
|
||||
core->PasteText(wstr);
|
||||
},
|
||||
_core->BracketedPasteEnabled());
|
||||
|
||||
// send paste event up to TermApp
|
||||
_PasteFromClipboardHandlers(*this, *pasteArgs);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Pre-process text pasted (presumably from the clipboard)
|
||||
// before sending it over the terminal's connection.
|
||||
void ControlInteractivity::_sendPastedTextToConnection(std::wstring_view wstr)
|
||||
{
|
||||
_core->PasteText(winrt::hstring{ wstr });
|
||||
_PasteFromClipboardHandlers(*this, std::move(args));
|
||||
}
|
||||
|
||||
void ControlInteractivity::PointerPressed(Control::MouseButtonState buttonState,
|
||||
|
||||
@@ -155,7 +155,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
bool _canSendVTMouseInput(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers);
|
||||
bool _shouldSendAlternateScroll(const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, const int32_t delta);
|
||||
|
||||
void _sendPastedTextToConnection(std::wstring_view wstr);
|
||||
til::point _getTerminalPosition(const til::point pixelPosition);
|
||||
|
||||
bool _sendMouseEventHelper(const til::point terminalPosition,
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
struct PasteFromClipboardEventArgs : public PasteFromClipboardEventArgsT<PasteFromClipboardEventArgs>
|
||||
{
|
||||
public:
|
||||
PasteFromClipboardEventArgs(std::function<void(std::wstring_view)> clipboardDataHandler, bool bracketedPasteEnabled) :
|
||||
PasteFromClipboardEventArgs(std::function<void(const hstring&)> clipboardDataHandler, bool bracketedPasteEnabled) :
|
||||
m_clipboardDataHandler(clipboardDataHandler),
|
||||
_BracketedPasteEnabled{ bracketedPasteEnabled } {}
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
WINRT_PROPERTY(bool, BracketedPasteEnabled, false);
|
||||
|
||||
private:
|
||||
std::function<void(std::wstring_view)> m_clipboardDataHandler;
|
||||
std::function<void(const hstring&)> m_clipboardDataHandler;
|
||||
};
|
||||
|
||||
struct OpenHyperlinkEventArgs : public OpenHyperlinkEventArgsT<OpenHyperlinkEventArgs>
|
||||
|
||||
@@ -43,13 +43,13 @@ try
|
||||
return DefWindowProc(hwnd, WM_NCCREATE, wParam, lParam);
|
||||
}
|
||||
#pragma warning(suppress : 26490) // Win32 APIs can only store void*, have to use reinterpret_cast
|
||||
auto terminal = reinterpret_cast<HwndTerminal*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
|
||||
const auto publicTerminal = reinterpret_cast<HwndTerminal*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
|
||||
|
||||
if (terminal)
|
||||
if (publicTerminal)
|
||||
{
|
||||
if (_IsMouseMessage(uMsg))
|
||||
{
|
||||
if (terminal->_CanSendVTMouseInput() && terminal->_SendMouseEvent(uMsg, wParam, lParam))
|
||||
if (publicTerminal->_CanSendVTMouseInput() && publicTerminal->_SendMouseEvent(uMsg, wParam, lParam))
|
||||
{
|
||||
// GH#6401: Capturing the mouse ensures that we get drag/release events
|
||||
// even if the user moves outside the window.
|
||||
@@ -81,14 +81,14 @@ try
|
||||
case WM_GETOBJECT:
|
||||
if (lParam == UiaRootObjectId)
|
||||
{
|
||||
return UiaReturnRawElementProvider(hwnd, wParam, lParam, terminal->_GetUiaProvider());
|
||||
return UiaReturnRawElementProvider(hwnd, wParam, lParam, publicTerminal->_GetUiaProvider());
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
LOG_IF_FAILED(terminal->_StartSelection(lParam));
|
||||
LOG_IF_FAILED(publicTerminal->_StartSelection(lParam));
|
||||
return 0;
|
||||
case WM_LBUTTONUP:
|
||||
terminal->_singleClickTouchdownPos = std::nullopt;
|
||||
publicTerminal->_singleClickTouchdownPos = std::nullopt;
|
||||
[[fallthrough]];
|
||||
case WM_MBUTTONUP:
|
||||
case WM_RBUTTONUP:
|
||||
@@ -97,30 +97,31 @@ try
|
||||
case WM_MOUSEMOVE:
|
||||
if (WI_IsFlagSet(wParam, MK_LBUTTON))
|
||||
{
|
||||
LOG_IF_FAILED(terminal->_MoveSelection(lParam));
|
||||
LOG_IF_FAILED(publicTerminal->_MoveSelection(lParam));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
if (const auto& termCore{ terminal->_terminal }; termCore && termCore->IsSelectionActive())
|
||||
if (publicTerminal->_terminal && publicTerminal->_terminal->IsSelectionActive())
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto bufferData = termCore->RetrieveSelectedTextFromBuffer(false);
|
||||
LOG_IF_FAILED(terminal->_CopyTextToSystemClipboard(bufferData, true));
|
||||
TerminalClearSelection(terminal);
|
||||
const auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
const auto bufferData = publicTerminal->_terminal->RetrieveSelectedTextFromBuffer(false);
|
||||
LOG_IF_FAILED(publicTerminal->_CopyTextToSystemClipboard(bufferData, true));
|
||||
publicTerminal->_ClearSelection();
|
||||
}
|
||||
CATCH_LOG();
|
||||
}
|
||||
else
|
||||
{
|
||||
terminal->_PasteTextFromClipboard();
|
||||
publicTerminal->_PasteTextFromClipboard();
|
||||
}
|
||||
return 0;
|
||||
case WM_DESTROY:
|
||||
// Release Terminal's hwnd so Teardown doesn't try to destroy it again
|
||||
terminal->_hwnd.release();
|
||||
terminal->Teardown();
|
||||
publicTerminal->_hwnd.release();
|
||||
publicTerminal->Teardown();
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
@@ -195,6 +196,8 @@ HwndTerminal::~HwndTerminal()
|
||||
HRESULT HwndTerminal::Initialize()
|
||||
{
|
||||
_terminal = std::make_unique<::Microsoft::Terminal::Core::Terminal>();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
auto renderThread = std::make_unique<::Microsoft::Console::Render::RenderThread>();
|
||||
auto* const localPointerToThread = renderThread.get();
|
||||
auto& renderSettings = _terminal->GetRenderSettings();
|
||||
@@ -304,7 +307,6 @@ void HwndTerminal::_UpdateFont(int newDpi)
|
||||
return;
|
||||
}
|
||||
_currentDpi = newDpi;
|
||||
auto lock = _terminal->LockForWriting();
|
||||
|
||||
// TODO: MSFT:20895307 If the font doesn't exist, this doesn't
|
||||
// actually fail. We need a way to gracefully fallback.
|
||||
@@ -323,10 +325,10 @@ IRawElementProviderSimple* HwndTerminal::_GetUiaProvider() noexcept
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
auto lock = _terminal->LockForWriting();
|
||||
LOG_IF_FAILED(::Microsoft::WRL::MakeAndInitialize<HwndTerminalAutomationPeer>(&_uiaProvider, this->GetRenderData(), this));
|
||||
_uiaEngine = std::make_unique<::Microsoft::Console::Render::UiaEngine>(_uiaProvider.Get());
|
||||
LOG_IF_FAILED(_uiaEngine->Enable());
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_renderer->AddRenderEngine(_uiaEngine.get());
|
||||
}
|
||||
catch (...)
|
||||
@@ -344,7 +346,7 @@ HRESULT HwndTerminal::Refresh(const til::size windowSize, _Out_ til::size* dimen
|
||||
RETURN_HR_IF_NULL(E_NOT_VALID_STATE, _terminal);
|
||||
RETURN_HR_IF_NULL(E_INVALIDARG, dimensions);
|
||||
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
_terminal->ClearSelection();
|
||||
|
||||
@@ -381,37 +383,45 @@ void HwndTerminal::SendOutput(std::wstring_view data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->Write(data);
|
||||
}
|
||||
|
||||
HRESULT _stdcall CreateTerminal(HWND parentHwnd, _Out_ void** hwnd, _Out_ void** terminal)
|
||||
{
|
||||
auto _terminal = std::make_unique<HwndTerminal>(parentHwnd);
|
||||
RETURN_IF_FAILED(_terminal->Initialize());
|
||||
auto publicTerminal = std::make_unique<HwndTerminal>(parentHwnd);
|
||||
|
||||
*hwnd = _terminal->GetHwnd();
|
||||
*terminal = _terminal.release();
|
||||
RETURN_IF_FAILED(publicTerminal->Initialize());
|
||||
|
||||
*hwnd = publicTerminal->GetHwnd();
|
||||
*terminal = publicTerminal.release();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void _stdcall TerminalRegisterScrollCallback(void* terminal, void __stdcall callback(int, int, int))
|
||||
try
|
||||
{
|
||||
auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
publicTerminal->RegisterScrollCallback(callback);
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
void _stdcall TerminalRegisterWriteCallback(void* terminal, const void __stdcall callback(wchar_t*))
|
||||
try
|
||||
{
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
publicTerminal->RegisterWriteCallback(callback);
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
void _stdcall TerminalSendOutput(void* terminal, LPCWSTR data)
|
||||
try
|
||||
{
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
publicTerminal->SendOutput(data);
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
/// <summary>
|
||||
/// Triggers a terminal resize using the new width and height in pixel.
|
||||
@@ -446,13 +456,18 @@ HRESULT _stdcall TerminalTriggerResize(_In_ void* terminal, _In_ til::CoordType
|
||||
/// <param name="dimensionsInPixels">Out parameter with the new size of the renderer.</param>
|
||||
/// <returns>HRESULT of the attempted resize.</returns>
|
||||
HRESULT _stdcall TerminalTriggerResizeWithDimension(_In_ void* terminal, _In_ til::size dimensionsInCharacters, _Out_ til::size* dimensionsInPixels)
|
||||
try
|
||||
{
|
||||
RETURN_HR_IF_NULL(E_INVALIDARG, dimensionsInPixels);
|
||||
|
||||
const auto publicTerminal = static_cast<const HwndTerminal*>(terminal);
|
||||
|
||||
const auto viewInCharacters = Viewport::FromDimensions(dimensionsInCharacters);
|
||||
const auto viewInPixels = publicTerminal->_renderEngine->GetViewportInPixels(viewInCharacters);
|
||||
Viewport viewInPixels;
|
||||
{
|
||||
const auto viewInCharacters = Viewport::FromDimensions(dimensionsInCharacters);
|
||||
const auto lock = publicTerminal->_terminal->LockForReading();
|
||||
viewInPixels = publicTerminal->_renderEngine->GetViewportInPixels(viewInCharacters);
|
||||
}
|
||||
|
||||
dimensionsInPixels->width = viewInPixels.Width();
|
||||
dimensionsInPixels->height = viewInPixels.Height();
|
||||
@@ -461,6 +476,7 @@ HRESULT _stdcall TerminalTriggerResizeWithDimension(_In_ void* terminal, _In_ ti
|
||||
|
||||
return TerminalTriggerResize(terminal, viewInPixels.Width(), viewInPixels.Height(), &unused);
|
||||
}
|
||||
CATCH_RETURN()
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the amount of rows and columns that fit in the provided width and height.
|
||||
@@ -471,10 +487,12 @@ HRESULT _stdcall TerminalTriggerResizeWithDimension(_In_ void* terminal, _In_ ti
|
||||
/// <param name="dimensions">Out parameter containing the columns and rows that fit the new size.</param>
|
||||
/// <returns>HRESULT of the calculation.</returns>
|
||||
HRESULT _stdcall TerminalCalculateResize(_In_ void* terminal, _In_ til::CoordType width, _In_ til::CoordType height, _Out_ til::size* dimensions)
|
||||
try
|
||||
{
|
||||
const auto publicTerminal = static_cast<const HwndTerminal*>(terminal);
|
||||
|
||||
const auto viewInPixels = Viewport::FromDimensions({ width, height });
|
||||
const auto lock = publicTerminal->_terminal->LockForReading();
|
||||
const auto viewInCharacters = publicTerminal->_renderEngine->GetViewportInCharacters(viewInPixels);
|
||||
|
||||
dimensions->width = viewInCharacters.Width();
|
||||
@@ -482,20 +500,27 @@ HRESULT _stdcall TerminalCalculateResize(_In_ void* terminal, _In_ til::CoordTyp
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
CATCH_RETURN()
|
||||
|
||||
void _stdcall TerminalDpiChanged(void* terminal, int newDpi)
|
||||
try
|
||||
{
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
const auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
publicTerminal->_UpdateFont(newDpi);
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
void _stdcall TerminalUserScroll(void* terminal, int viewTop)
|
||||
try
|
||||
{
|
||||
if (const auto publicTerminal = static_cast<const HwndTerminal*>(terminal); publicTerminal && publicTerminal->_terminal)
|
||||
{
|
||||
const auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
publicTerminal->_terminal->UserScrollViewport(viewTop);
|
||||
}
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
const unsigned int HwndTerminal::_NumberOfClicks(til::point point, std::chrono::steady_clock::time_point timestamp) noexcept
|
||||
{
|
||||
@@ -522,7 +547,7 @@ try
|
||||
GET_Y_LPARAM(lParam),
|
||||
};
|
||||
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
const auto altPressed = GetKeyState(VK_MENU) < 0;
|
||||
const til::size fontSize{ this->_actualFont.GetSize() };
|
||||
|
||||
@@ -566,7 +591,7 @@ try
|
||||
GET_Y_LPARAM(lParam),
|
||||
};
|
||||
|
||||
auto lock = _terminal->LockForWriting();
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
const til::size fontSize{ this->_actualFont.GetSize() };
|
||||
|
||||
RETURN_HR_IF(E_NOT_VALID_STATE, fontSize.area() == 0); // either dimension = 0, area == 0
|
||||
@@ -596,45 +621,57 @@ try
|
||||
}
|
||||
CATCH_RETURN();
|
||||
|
||||
void HwndTerminal::_ClearSelection() noexcept
|
||||
try
|
||||
void HwndTerminal::_ClearSelection()
|
||||
{
|
||||
if (!_terminal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto lock{ _terminal->LockForWriting() };
|
||||
_terminal->ClearSelection();
|
||||
_renderer->TriggerSelection();
|
||||
}
|
||||
CATCH_LOG();
|
||||
|
||||
void _stdcall TerminalClearSelection(void* terminal)
|
||||
try
|
||||
{
|
||||
auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
const auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
publicTerminal->_ClearSelection();
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
bool _stdcall TerminalIsSelectionActive(void* terminal)
|
||||
try
|
||||
{
|
||||
if (const auto publicTerminal = static_cast<const HwndTerminal*>(terminal); publicTerminal && publicTerminal->_terminal)
|
||||
{
|
||||
const auto lock = publicTerminal->_terminal->LockForReading();
|
||||
return publicTerminal->_terminal->IsSelectionActive();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_CAUGHT_EXCEPTION();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returns the selected text in the terminal.
|
||||
const wchar_t* _stdcall TerminalGetSelection(void* terminal)
|
||||
try
|
||||
{
|
||||
auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
if (!publicTerminal || !publicTerminal->_terminal)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto bufferData = publicTerminal->_terminal->RetrieveSelectedTextFromBuffer(false);
|
||||
publicTerminal->_ClearSelection();
|
||||
TextBuffer::TextAndColor bufferData;
|
||||
{
|
||||
const auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
bufferData = publicTerminal->_terminal->RetrieveSelectedTextFromBuffer(false);
|
||||
publicTerminal->_ClearSelection();
|
||||
}
|
||||
|
||||
// convert text: vector<string> --> string
|
||||
std::wstring selectedText;
|
||||
@@ -646,6 +683,11 @@ const wchar_t* _stdcall TerminalGetSelection(void* terminal)
|
||||
auto returnText = wil::make_cotaskmem_string_nothrow(selectedText.c_str());
|
||||
return returnText.release();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_CAUGHT_EXCEPTION();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static ControlKeyStates getControlKeyState() noexcept
|
||||
{
|
||||
@@ -683,6 +725,7 @@ bool HwndTerminal::_CanSendVTMouseInput() const noexcept
|
||||
{
|
||||
// Only allow the transit of mouse events if shift isn't pressed.
|
||||
const auto shiftPressed = GetKeyState(VK_SHIFT) < 0;
|
||||
const auto lock = _terminal->LockForReading();
|
||||
return !shiftPressed && _focused && _terminal && _terminal->IsTrackingMouseInput();
|
||||
}
|
||||
|
||||
@@ -715,6 +758,7 @@ try
|
||||
WI_IsFlagSet(GetKeyState(VK_RBUTTON), KeyPressed)
|
||||
};
|
||||
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
return _terminal->SendMouseEvent(cursorPosition / fontSize, uMsg, getControlKeyState(), wheelDelta, state);
|
||||
}
|
||||
catch (...)
|
||||
@@ -740,6 +784,7 @@ try
|
||||
{
|
||||
_uiaProvider->RecordKeyEvent(vkey);
|
||||
}
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->SendKeyEvent(vkey, scanCode, modifiers, keyDown);
|
||||
}
|
||||
CATCH_LOG();
|
||||
@@ -751,7 +796,10 @@ try
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (_terminal->IsSelectionActive())
|
||||
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
|
||||
if (_terminal->IsSelectionActive())
|
||||
{
|
||||
_ClearSelection();
|
||||
if (ch == UNICODE_ESC)
|
||||
@@ -778,16 +826,20 @@ try
|
||||
CATCH_LOG();
|
||||
|
||||
void _stdcall TerminalSendKeyEvent(void* terminal, WORD vkey, WORD scanCode, WORD flags, bool keyDown)
|
||||
try
|
||||
{
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
publicTerminal->_SendKeyEvent(vkey, scanCode, flags, keyDown);
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
void _stdcall TerminalSendCharEvent(void* terminal, wchar_t ch, WORD scanCode, WORD flags)
|
||||
try
|
||||
{
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
publicTerminal->_SendCharEvent(ch, scanCode, flags);
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
void _stdcall DestroyTerminal(void* terminal)
|
||||
{
|
||||
@@ -803,8 +855,9 @@ void _stdcall TerminalSetTheme(void* terminal, TerminalTheme theme, LPCWSTR font
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
const auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
|
||||
auto& renderSettings = publicTerminal->_terminal->GetRenderSettings();
|
||||
renderSettings.SetColorTableEntry(TextColor::DEFAULT_FOREGROUND, theme.DefaultForeground);
|
||||
@@ -818,13 +871,13 @@ void _stdcall TerminalSetTheme(void* terminal, TerminalTheme theme, LPCWSTR font
|
||||
// It's using gsl::at to check the index is in bounds, but the analyzer still calls this array-to-pointer-decay
|
||||
[[gsl::suppress(bounds .3)]] renderSettings.SetColorTableEntry(tableIndex, gsl::at(theme.ColorTable, tableIndex));
|
||||
}
|
||||
|
||||
publicTerminal->_terminal->SetCursorStyle(static_cast<DispatchTypes::CursorStyle>(theme.CursorStyle));
|
||||
|
||||
publicTerminal->_desiredFont = { fontFamily, 0, DEFAULT_FONT_WEIGHT, static_cast<float>(fontSize), CP_UTF8 };
|
||||
publicTerminal->_UpdateFont(newDpi);
|
||||
}
|
||||
|
||||
publicTerminal->_terminal->SetCursorStyle(static_cast<DispatchTypes::CursorStyle>(theme.CursorStyle));
|
||||
|
||||
publicTerminal->_desiredFont = { fontFamily, 0, DEFAULT_FONT_WEIGHT, static_cast<float>(fontSize), CP_UTF8 };
|
||||
publicTerminal->_UpdateFont(newDpi);
|
||||
|
||||
// When the font changes the terminal dimensions need to be recalculated since the available row and column
|
||||
// space will have changed.
|
||||
RECT windowRect;
|
||||
@@ -836,29 +889,35 @@ void _stdcall TerminalSetTheme(void* terminal, TerminalTheme theme, LPCWSTR font
|
||||
}
|
||||
|
||||
void _stdcall TerminalBlinkCursor(void* terminal)
|
||||
{
|
||||
const auto publicTerminal = static_cast<const HwndTerminal*>(terminal);
|
||||
if (!publicTerminal || !publicTerminal->_terminal || (!publicTerminal->_terminal->IsCursorBlinkingAllowed() && publicTerminal->_terminal->IsCursorVisible()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
publicTerminal->_terminal->SetCursorOn(!publicTerminal->_terminal->IsCursorOn());
|
||||
}
|
||||
|
||||
void _stdcall TerminalSetCursorVisible(void* terminal, const bool visible)
|
||||
try
|
||||
{
|
||||
const auto publicTerminal = static_cast<const HwndTerminal*>(terminal);
|
||||
if (!publicTerminal || !publicTerminal->_terminal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
publicTerminal->_terminal->BlinkCursor();
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
void _stdcall TerminalSetCursorVisible(void* terminal, const bool visible)
|
||||
try
|
||||
{
|
||||
const auto publicTerminal = static_cast<const HwndTerminal*>(terminal);
|
||||
if (!publicTerminal || !publicTerminal->_terminal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const auto lock = publicTerminal->_terminal->LockForWriting();
|
||||
publicTerminal->_terminal->SetCursorOn(visible);
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
void __stdcall TerminalSetFocus(void* terminal)
|
||||
{
|
||||
auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
publicTerminal->_focused = true;
|
||||
if (auto uiaEngine = publicTerminal->_uiaEngine.get())
|
||||
{
|
||||
@@ -868,7 +927,7 @@ void __stdcall TerminalSetFocus(void* terminal)
|
||||
|
||||
void __stdcall TerminalKillFocus(void* terminal)
|
||||
{
|
||||
auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
const auto publicTerminal = static_cast<HwndTerminal*>(terminal);
|
||||
publicTerminal->_focused = false;
|
||||
if (auto uiaEngine = publicTerminal->_uiaEngine.get())
|
||||
{
|
||||
@@ -923,7 +982,11 @@ try
|
||||
{
|
||||
const auto& fontData = _actualFont;
|
||||
const int iFontHeightPoints = fontData.GetUnscaledSize().height; // this renderer uses points already
|
||||
const auto bgColor = _terminal->GetAttributeColors({}).second;
|
||||
COLORREF bgColor;
|
||||
{
|
||||
const auto lock = _terminal->LockForReading();
|
||||
bgColor = _terminal->GetAttributeColors({}).second;
|
||||
}
|
||||
|
||||
auto HTMLToPlaceOnClip = TextBuffer::GenHTML(rows, iFontHeightPoints, fontData.GetFaceName(), bgColor);
|
||||
_CopyToSystemClipboard(HTMLToPlaceOnClip, L"HTML Format");
|
||||
@@ -993,30 +1056,16 @@ void HwndTerminal::_PasteTextFromClipboard() noexcept
|
||||
return;
|
||||
}
|
||||
|
||||
auto pwstr = static_cast<PCWCH>(GlobalLock(ClipboardDataHandle));
|
||||
|
||||
_StringPaste(pwstr);
|
||||
if (const auto pwstr = static_cast<PCWCH>(GlobalLock(ClipboardDataHandle)))
|
||||
{
|
||||
_WriteTextToConnection(pwstr);
|
||||
}
|
||||
|
||||
GlobalUnlock(ClipboardDataHandle);
|
||||
|
||||
CloseClipboard();
|
||||
}
|
||||
|
||||
void HwndTerminal::_StringPaste(const wchar_t* const pData) noexcept
|
||||
{
|
||||
if (pData == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
std::wstring text(pData);
|
||||
_WriteTextToConnection(text);
|
||||
}
|
||||
CATCH_LOG();
|
||||
}
|
||||
|
||||
til::size HwndTerminal::GetFontSize() const noexcept
|
||||
{
|
||||
return _actualFont.GetSize();
|
||||
@@ -1045,6 +1094,7 @@ void HwndTerminal::ChangeViewport(const til::inclusive_rect& NewWindow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const auto lock = _terminal->LockForWriting();
|
||||
_terminal->UserScrollViewport(NewWindow.top);
|
||||
}
|
||||
|
||||
@@ -112,14 +112,13 @@ private:
|
||||
HRESULT _CopyTextToSystemClipboard(const TextBuffer::TextAndColor& rows, const bool fAlsoCopyFormatting);
|
||||
HRESULT _CopyToSystemClipboard(std::string stringToCopy, LPCWSTR lpszFormat);
|
||||
void _PasteTextFromClipboard() noexcept;
|
||||
void _StringPaste(const wchar_t* const pData) noexcept;
|
||||
|
||||
const unsigned int _NumberOfClicks(til::point clickPos, std::chrono::steady_clock::time_point clickTime) noexcept;
|
||||
HRESULT _StartSelection(LPARAM lParam) noexcept;
|
||||
HRESULT _MoveSelection(LPARAM lParam) noexcept;
|
||||
IRawElementProviderSimple* _GetUiaProvider() noexcept;
|
||||
|
||||
void _ClearSelection() noexcept;
|
||||
void _ClearSelection();
|
||||
|
||||
bool _CanSendVTMouseInput() const noexcept;
|
||||
bool _SendMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam) noexcept;
|
||||
@@ -4,11 +4,9 @@
|
||||
#include "pch.h"
|
||||
#include "TermControl.h"
|
||||
|
||||
#include <unicode.hpp>
|
||||
#include <LibraryResources.h>
|
||||
|
||||
#include "TermControlAutomationPeer.h"
|
||||
#include "../../types/inc/GlyphWidth.hpp"
|
||||
#include "../../renderer/atlas/AtlasEngine.h"
|
||||
|
||||
#include "TermControl.g.cpp"
|
||||
@@ -275,6 +273,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void TermControl::_throttledUpdateScrollbar(const ScrollBarUpdate& update)
|
||||
{
|
||||
if (!_initializedTerminal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumptions:
|
||||
// * we're already not closing
|
||||
// * caller already checked weak ptr to make sure we're still alive
|
||||
@@ -296,56 +299,102 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
if (_showMarksInScrollbar)
|
||||
{
|
||||
// Update scrollbar marks
|
||||
ScrollBarCanvas().Children().Clear();
|
||||
const auto marks{ _core.ScrollMarks() };
|
||||
const auto fullHeight{ ScrollBarCanvas().ActualHeight() };
|
||||
const auto totalBufferRows{ update.newMaximum + update.newViewportSize };
|
||||
const auto scaleFactor = DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel();
|
||||
const auto scrollBarWidthInDIP = scrollBar.ActualWidth();
|
||||
const auto scrollBarHeightInDIP = scrollBar.ActualHeight();
|
||||
const auto scrollBarWidthInPx = gsl::narrow_cast<int32_t>(lrint(scrollBarWidthInDIP * scaleFactor));
|
||||
const auto scrollBarHeightInPx = gsl::narrow_cast<int32_t>(lrint(scrollBarHeightInDIP * scaleFactor));
|
||||
|
||||
auto drawPip = [&](const auto row, const auto rightAlign, const auto& brush) {
|
||||
Windows::UI::Xaml::Shapes::Rectangle r;
|
||||
r.Fill(brush);
|
||||
r.Width(16.0f / 3.0f); // pip width - 1/3rd of the scrollbar width.
|
||||
r.Height(2);
|
||||
const auto fractionalHeight = row / totalBufferRows;
|
||||
const auto relativePos = fractionalHeight * fullHeight;
|
||||
ScrollBarCanvas().Children().Append(r);
|
||||
Windows::UI::Xaml::Controls::Canvas::SetTop(r, relativePos);
|
||||
if (rightAlign)
|
||||
const auto canvas = FindName(L"ScrollBarCanvas").as<Controls::Image>();
|
||||
auto source = canvas.Source().try_as<Media::Imaging::WriteableBitmap>();
|
||||
|
||||
if (!source || scrollBarWidthInPx != source.PixelWidth() || scrollBarHeightInPx != source.PixelHeight())
|
||||
{
|
||||
source = Media::Imaging::WriteableBitmap{ scrollBarWidthInPx, scrollBarHeightInPx };
|
||||
canvas.Source(source);
|
||||
canvas.Width(scrollBarWidthInDIP);
|
||||
canvas.Height(scrollBarHeightInDIP);
|
||||
}
|
||||
|
||||
const auto buffer = source.PixelBuffer();
|
||||
const auto data = buffer.data();
|
||||
const auto stride = scrollBarWidthInPx * sizeof(til::color);
|
||||
|
||||
// The bitmap has the size of the entire scrollbar, but we want the marks to only show in the range the "thumb"
|
||||
// (the scroll indicator) can move. That's why we need to add an offset to the start of the drawable bitmap area
|
||||
// (to offset the decrease button) and subtract twice that (to offset the increase button as well).
|
||||
//
|
||||
// The WinUI standard scrollbar defines a Margin="2,0,2,0" for the "VerticalPanningThumb" and a Padding="0,4,0,0"
|
||||
// for the "VerticalDecrementTemplate" (and similar for the increment), but it seems neither of those is correct,
|
||||
// because a padding for 3 DIPs seem to be the exact right amount to add.
|
||||
const auto increaseDecreaseButtonHeight = scrollBarWidthInPx + lround(3 * scaleFactor);
|
||||
const auto drawableDataStart = data + stride * increaseDecreaseButtonHeight;
|
||||
const auto drawableRange = scrollBarHeightInPx - 2 * increaseDecreaseButtonHeight;
|
||||
|
||||
// Protect the remaining code against negative offsets. This normally can't happen
|
||||
// and this code just exists so it doesn't crash if I'm ever wrong about this.
|
||||
// (The window has a min. size that ensures that there's always a scrollbar thumb.)
|
||||
if (drawableRange < 0)
|
||||
{
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// The scrollbar bitmap is divided into 3 evenly sized stripes:
|
||||
// Left: Regular marks
|
||||
// Center: nothing
|
||||
// Right: Search marks
|
||||
const auto pipWidth = (scrollBarWidthInPx + 1) / 3;
|
||||
const auto pipHeight = lround(1 * scaleFactor);
|
||||
|
||||
const auto maxOffsetY = drawableRange - pipHeight;
|
||||
const auto offsetScale = maxOffsetY / gsl::narrow_cast<float>(update.newMaximum + update.newViewportSize);
|
||||
// A helper to turn a TextBuffer row offset into a bitmap offset.
|
||||
const auto dataAt = [&](til::CoordType row) [[msvc::forceinline]] {
|
||||
const auto y = std::clamp<long>(lrintf(row * offsetScale), 0, maxOffsetY);
|
||||
return drawableDataStart + stride * y;
|
||||
};
|
||||
// A helper to draw a single pip (mark) at the given location.
|
||||
const auto drawPip = [&](uint8_t* beg, til::color color) [[msvc::forceinline]] {
|
||||
const auto end = beg + pipHeight * stride;
|
||||
for (; beg < end; beg += stride)
|
||||
{
|
||||
Windows::UI::Xaml::Controls::Canvas::SetLeft(r, 16.0f * .66f);
|
||||
// Coincidentally a til::color has the same RGBA format as the bitmap.
|
||||
#pragma warning(suppress : 26490) // Don't use reinterpret_cast (type.1).
|
||||
std::fill_n(reinterpret_cast<til::color*>(beg), pipWidth, color);
|
||||
}
|
||||
};
|
||||
|
||||
for (const auto m : marks)
|
||||
memset(data, 0, buffer.Length());
|
||||
|
||||
if (const auto marks = _core.ScrollMarks())
|
||||
{
|
||||
Windows::UI::Xaml::Shapes::Rectangle r;
|
||||
Media::SolidColorBrush brush{};
|
||||
// Sneaky: technically, a mark doesn't need to have a color set,
|
||||
// it might want to just use the color from the palette for that
|
||||
// kind of mark. Fortunately, ControlCore is kind enough to
|
||||
// pre-evaluate that for us, and shove the real value into the
|
||||
// Color member, regardless if the mark has a literal value set.
|
||||
brush.Color(static_cast<til::color>(m.Color.Color));
|
||||
drawPip(m.Start.Y, false, brush);
|
||||
for (const auto& m : marks)
|
||||
{
|
||||
const auto row = m.Start.Y;
|
||||
const til::color color{ m.Color.Color };
|
||||
const auto base = dataAt(row);
|
||||
drawPip(base, color);
|
||||
}
|
||||
}
|
||||
|
||||
if (_searchBox)
|
||||
if (_searchBox && _searchBox->Visibility() == Visibility::Visible)
|
||||
{
|
||||
const auto searchMatches{ _core.SearchResultRows() };
|
||||
if (searchMatches &&
|
||||
searchMatches.Size() > 0 &&
|
||||
_searchBox->Visibility() == Visibility::Visible)
|
||||
if (const auto searchMatches = _core.SearchResultRows())
|
||||
{
|
||||
const til::color fgColor{ _core.ForegroundColor() };
|
||||
Media::SolidColorBrush searchMarkBrush{};
|
||||
searchMarkBrush.Color(fgColor);
|
||||
for (const auto m : searchMatches)
|
||||
const til::color color{ _core.ForegroundColor() };
|
||||
const auto rightAlignedOffset = (scrollBarWidthInPx - pipWidth) * sizeof(til::color);
|
||||
|
||||
for (const auto row : searchMatches)
|
||||
{
|
||||
drawPip(m, true, searchMarkBrush);
|
||||
const auto base = dataAt(row) + rightAlignedOffset;
|
||||
drawPip(base, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
source.Invalidate();
|
||||
canvas.Visibility(Visibility::Visible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,14 +669,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// achieve the intended effect.
|
||||
ScrollBar().IndicatorMode(Controls::Primitives::ScrollingIndicatorMode::None);
|
||||
ScrollBar().Visibility(Visibility::Collapsed);
|
||||
ScrollMarksGrid().Visibility(Visibility::Collapsed);
|
||||
}
|
||||
else // (default or Visible)
|
||||
{
|
||||
// Default behavior
|
||||
ScrollBar().IndicatorMode(Controls::Primitives::ScrollingIndicatorMode::MouseIndicator);
|
||||
ScrollBar().Visibility(Visibility::Visible);
|
||||
ScrollMarksGrid().Visibility(Visibility::Visible);
|
||||
}
|
||||
|
||||
_interactivity.UpdateSettings();
|
||||
@@ -640,8 +687,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
}
|
||||
|
||||
_showMarksInScrollbar = settings.ShowMarks();
|
||||
// Clear out all the current marks
|
||||
ScrollBarCanvas().Children().Clear();
|
||||
// Hide all scrollbar marks since they might be disabled now.
|
||||
if (const auto canvas = ScrollBarCanvas())
|
||||
{
|
||||
canvas.Visibility(Visibility::Collapsed);
|
||||
}
|
||||
// When we hot reload the settings, the core will send us a scrollbar
|
||||
// update. If we enabled scrollbar marks, then great, when we handle
|
||||
// that message, we'll redraw them.
|
||||
@@ -733,17 +783,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
if (acrylic == nullptr)
|
||||
{
|
||||
acrylic = Media::AcrylicBrush{};
|
||||
|
||||
if (_core.Settings().EnableUnfocusedAcrylic())
|
||||
{
|
||||
acrylic.BackgroundSource(Media::AcrylicBackgroundSource::Backdrop);
|
||||
}
|
||||
else
|
||||
{
|
||||
acrylic.BackgroundSource(Media::AcrylicBackgroundSource::HostBackdrop);
|
||||
}
|
||||
}
|
||||
|
||||
const auto backdropStyle =
|
||||
_core.Settings().EnableUnfocusedAcrylic() ? Media::AcrylicBackgroundSource::Backdrop : Media::AcrylicBackgroundSource::HostBackdrop;
|
||||
acrylic.BackgroundSource(backdropStyle);
|
||||
|
||||
// see GH#1082: Initialize background color so we don't get a
|
||||
// fade/flash when _BackgroundColorChanged is called
|
||||
acrylic.FallbackColor(bgColor);
|
||||
@@ -1056,8 +1101,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
// _cursorTimer doesn't exist, and it would never turn on the
|
||||
// cursor. To mitigate, we'll initialize the cursor's 'on' state
|
||||
// with `_focused` here.
|
||||
_core.CursorOn(_focused || DisplayCursorWhileBlurred);
|
||||
if (DisplayCursorWhileBlurred)
|
||||
_core.CursorOn(_focused || _displayCursorWhileBlurred());
|
||||
if (_displayCursorWhileBlurred())
|
||||
{
|
||||
_cursorTimer->Start();
|
||||
}
|
||||
@@ -1973,7 +2018,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
TSFInputControl().NotifyFocusLeave();
|
||||
}
|
||||
|
||||
if (_cursorTimer && !DisplayCursorWhileBlurred)
|
||||
if (_cursorTimer && !_displayCursorWhileBlurred())
|
||||
{
|
||||
_cursorTimer->Stop();
|
||||
_core.CursorOn(false);
|
||||
@@ -3161,51 +3206,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
_core.ClearHoveredCell();
|
||||
}
|
||||
|
||||
// Attackers abuse Unicode characters that happen to look similar to ASCII characters. Cyrillic for instance has
|
||||
// its own glyphs for а, с, е, о, р, х, and у that look practically identical to their ASCII counterparts.
|
||||
// This is called an "IDN homoglyph attack".
|
||||
//
|
||||
// But outright showing Punycode URIs only is similarly flawed as they can end up looking similar to valid ASCII URIs.
|
||||
// xn--cnn.com for instance looks confusingly similar to cnn.com, but actually represents U+407E.
|
||||
//
|
||||
// An optimal solution would detect any URI that contains homoglyphs and show them in their Punycode form.
|
||||
// Such a detector however is not quite trivial and requires constant maintenance, which this project's
|
||||
// maintainers aren't currently well equipped to handle. As such we do the next best thing and show the
|
||||
// Punycode encoding side-by-side with the Unicode string for any IDN.
|
||||
static winrt::hstring sanitizeURI(winrt::hstring uri)
|
||||
{
|
||||
if (uri.empty())
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
wchar_t punycodeBuffer[256];
|
||||
wchar_t unicodeBuffer[256];
|
||||
|
||||
// These functions return int, but are documented to only return positive numbers.
|
||||
// Better make sure though. It allows us to pass punycodeLength right into IdnToUnicode.
|
||||
const auto punycodeLength = std::max(0, IdnToAscii(0, uri.data(), gsl::narrow<int>(uri.size()), &punycodeBuffer[0], 256));
|
||||
const auto unicodeLength = std::max(0, IdnToUnicode(0, &punycodeBuffer[0], punycodeLength, &unicodeBuffer[0], 256));
|
||||
|
||||
if (punycodeLength <= 0 || unicodeLength <= 0)
|
||||
{
|
||||
return RS_(L"InvalidUri");
|
||||
}
|
||||
|
||||
const std::wstring_view punycode{ &punycodeBuffer[0], gsl::narrow_cast<size_t>(punycodeLength) };
|
||||
const std::wstring_view unicode{ &unicodeBuffer[0], gsl::narrow_cast<size_t>(unicodeLength) };
|
||||
|
||||
// IdnToAscii/IdnToUnicode return the input string as is if it's all
|
||||
// plain ASCII. But we don't know if the input URI is Punycode or not.
|
||||
// --> It's non-Punycode and ASCII if it round-trips.
|
||||
if (uri == punycode && uri == unicode)
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
return winrt::hstring{ fmt::format(FMT_COMPILE(L"{}\n({})"), punycode, unicode) };
|
||||
}
|
||||
|
||||
void TermControl::_hoveredHyperlinkChanged(const IInspectable& /*sender*/, const IInspectable& /*args*/)
|
||||
{
|
||||
const auto lastHoveredCell = _core.HoveredCell();
|
||||
@@ -3214,12 +3214,48 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
return;
|
||||
}
|
||||
|
||||
const auto uriText = sanitizeURI(_core.HoveredUriText());
|
||||
auto uriText = _core.HoveredUriText();
|
||||
if (uriText.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Attackers abuse Unicode characters that happen to look similar to ASCII characters. Cyrillic for instance has
|
||||
// its own glyphs for а, с, е, о, р, х, and у that look practically identical to their ASCII counterparts.
|
||||
// This is called an "IDN homoglyph attack".
|
||||
//
|
||||
// But outright showing Punycode URIs only is similarly flawed as they can end up looking similar to valid ASCII URIs.
|
||||
// xn--cnn.com for instance looks confusingly similar to cnn.com, but actually represents U+407E.
|
||||
//
|
||||
// An optimal solution would detect any URI that contains homoglyphs and show them in their Punycode form.
|
||||
// Such a detector however is not quite trivial and requires constant maintenance, which this project's
|
||||
// maintainers aren't currently well equipped to handle. As such we do the next best thing and show the
|
||||
// Punycode encoding side-by-side with the Unicode string for any IDN.
|
||||
try
|
||||
{
|
||||
// DisplayUri/Iri drop authentication credentials, which is probably great, but AbsoluteCanonicalUri()
|
||||
// is the only getter that returns a punycode encoding of the URL. AbsoluteUri() is the only possible
|
||||
// counterpart, but as the name indicates, we'll end up hitting the != below for any non-canonical URL.
|
||||
//
|
||||
// This issue can be fixed by using the IUrl API from urlmon.h directly, which the WinRT API simply wraps.
|
||||
// IUrl is a very complex system with a ton of useful functionality, but we don't rely on it (neither WinRT),
|
||||
// so we could alternatively use its underlying API in wininet.h (InternetCrackUrlW, etc.).
|
||||
// That API however is rather difficult to use for such seldom executed code.
|
||||
const Windows::Foundation::Uri uri{ uriText };
|
||||
const auto unicode = uri.AbsoluteUri();
|
||||
const auto punycode = uri.AbsoluteCanonicalUri();
|
||||
|
||||
if (punycode != unicode)
|
||||
{
|
||||
const auto text = fmt::format(FMT_COMPILE(L"{}\n({})"), punycode, unicode);
|
||||
uriText = winrt::hstring{ text };
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
uriText = RS_(L"InvalidUri");
|
||||
}
|
||||
|
||||
const auto panel = SwapChainPanel();
|
||||
const auto scale = panel.CompositionScaleX();
|
||||
const auto offset = panel.ActualOffset();
|
||||
@@ -3665,4 +3701,45 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
SelectionContextMenu().Hide();
|
||||
_core.ContextMenuSelectOutput();
|
||||
}
|
||||
|
||||
// Should the text cursor be displayed, even when the control isn't focused?
|
||||
// n.b. "blur" is the opposite of "focus".
|
||||
bool TermControl::_displayCursorWhileBlurred() const noexcept
|
||||
{
|
||||
return CursorVisibility() == Control::CursorDisplayState::Shown;
|
||||
}
|
||||
Control::CursorDisplayState TermControl::CursorVisibility() const noexcept
|
||||
{
|
||||
return _cursorVisibility;
|
||||
}
|
||||
void TermControl::CursorVisibility(Control::CursorDisplayState cursorVisibility)
|
||||
{
|
||||
_cursorVisibility = cursorVisibility;
|
||||
if (!_initializedTerminal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_displayCursorWhileBlurred())
|
||||
{
|
||||
// If we should be ALWAYS displaying the cursor, turn it on and start blinking.
|
||||
_core.CursorOn(true);
|
||||
if (_cursorTimer.has_value())
|
||||
{
|
||||
_cursorTimer->Start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, if we're unfocused, then turn the cursor off and stop
|
||||
// blinking. (if we're focused, then we're already doing the right
|
||||
// thing)
|
||||
const auto focused = FocusState() != FocusState::Unfocused;
|
||||
if (!focused && _cursorTimer.has_value())
|
||||
{
|
||||
_cursorTimer->Stop();
|
||||
}
|
||||
_core.CursorOn(focused);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +160,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
TerminalConnection::ITerminalConnection Connection();
|
||||
void Connection(const TerminalConnection::ITerminalConnection& connection);
|
||||
|
||||
Control::CursorDisplayState CursorVisibility() const noexcept;
|
||||
void CursorVisibility(Control::CursorDisplayState cursorVisibility);
|
||||
|
||||
// -------------------------------- WinRT Events ---------------------------------
|
||||
// clang-format off
|
||||
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
|
||||
@@ -194,9 +197,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Xaml::Media::Brush, BackgroundBrush, _PropertyChangedHandlers, nullptr);
|
||||
|
||||
public:
|
||||
til::property<bool> DisplayCursorWhileBlurred{ false };
|
||||
|
||||
private:
|
||||
friend struct TermControlT<TermControl>; // friend our parent so it can bind private event handlers
|
||||
|
||||
@@ -258,6 +258,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
Windows::Foundation::Collections::IObservableVector<Windows::UI::Xaml::Controls::ICommandBarElement> _originalSelectedPrimaryElements{ nullptr };
|
||||
Windows::Foundation::Collections::IObservableVector<Windows::UI::Xaml::Controls::ICommandBarElement> _originalSelectedSecondaryElements{ nullptr };
|
||||
|
||||
Control::CursorDisplayState _cursorVisibility{ Control::CursorDisplayState::Default };
|
||||
|
||||
inline bool _IsClosing() const noexcept
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
@@ -376,6 +378,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
void _SelectCommandHandler(const IInspectable& sender, const IInspectable& args);
|
||||
void _SelectOutputHandler(const IInspectable& sender, const IInspectable& args);
|
||||
bool _displayCursorWhileBlurred() const noexcept;
|
||||
|
||||
struct Revokers
|
||||
{
|
||||
|
||||
@@ -12,6 +12,12 @@ import "ControlCore.idl";
|
||||
namespace Microsoft.Terminal.Control
|
||||
{
|
||||
|
||||
enum CursorDisplayState
|
||||
{
|
||||
Default,
|
||||
Shown
|
||||
};
|
||||
|
||||
[default_interface] runtimeclass TermControl : Windows.UI.Xaml.Controls.UserControl,
|
||||
IDirectKeyListener,
|
||||
IMouseWheelListener,
|
||||
@@ -121,7 +127,7 @@ namespace Microsoft.Terminal.Control
|
||||
// opacity set by the settings should call this instead.
|
||||
Double BackgroundOpacity { get; };
|
||||
|
||||
Boolean DisplayCursorWhileBlurred;
|
||||
CursorDisplayState CursorVisibility;
|
||||
|
||||
Windows.UI.Xaml.Media.Brush BackgroundBrush { get; };
|
||||
|
||||
|
||||
@@ -1322,28 +1322,14 @@
|
||||
ValueChanged="_ScrollbarChangeHandler"
|
||||
ViewportSize="10" />
|
||||
|
||||
<Grid x:Name="ScrollMarksGrid"
|
||||
Grid.Column="1"
|
||||
Width="{StaticResource ScrollBarSize}"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Stretch">
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Grid.Row="0"
|
||||
Height="{StaticResource ScrollBarSize}" />
|
||||
<Canvas x:Name="ScrollBarCanvas"
|
||||
Grid.Row="1"
|
||||
Width="{StaticResource ScrollBarSize}"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Stretch" />
|
||||
<Border Grid.Row="2"
|
||||
Height="{StaticResource ScrollBarSize}" />
|
||||
</Grid>
|
||||
<Image x:Name="ScrollBarCanvas"
|
||||
Grid.Column="1"
|
||||
Width="{StaticResource ScrollBarSize}"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Stretch"
|
||||
x:Load="False"
|
||||
IsHitTestVisible="False"
|
||||
Visibility="Collapsed" />
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@
|
||||
<DependentUpon>TSFInputControl.xaml</DependentUpon>
|
||||
</ClInclude>
|
||||
<ClInclude Include="XamlUiaTextRange.h" />
|
||||
<ClInclude Include="HwndTerminal.hpp" />
|
||||
<ClInclude Include="HwndTerminalAutomationPeer.hpp" />
|
||||
</ItemGroup>
|
||||
<!-- ========================= Cpp Files ======================== -->
|
||||
<ItemGroup>
|
||||
@@ -111,6 +113,8 @@
|
||||
<DependentUpon>InteractivityAutomationPeer.idl</DependentUpon>
|
||||
</ClCompile>
|
||||
<ClCompile Include="XamlUiaTextRange.cpp" />
|
||||
<ClCompile Include="HwndTerminal.cpp" />
|
||||
<ClCompile Include="HwndTerminalAutomationPeer.cpp" />
|
||||
</ItemGroup>
|
||||
<!-- ========================= idl Files ======================== -->
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
EXPORTS
|
||||
DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE
|
||||
DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE
|
||||
; WinRT ABI
|
||||
DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE
|
||||
DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE
|
||||
|
||||
; Flat C ABI
|
||||
CreateTerminal
|
||||
DestroyTerminal
|
||||
TerminalBlinkCursor
|
||||
TerminalCalculateResize
|
||||
TerminalClearSelection
|
||||
TerminalDpiChanged
|
||||
TerminalGetSelection
|
||||
TerminalIsSelectionActive
|
||||
TerminalKillFocus
|
||||
TerminalRegisterScrollCallback
|
||||
TerminalRegisterWriteCallback
|
||||
TerminalSendCharEvent
|
||||
TerminalSendKeyEvent
|
||||
TerminalSendOutput
|
||||
TerminalSetCursorVisible
|
||||
TerminalSetFocus
|
||||
TerminalSetTheme
|
||||
TerminalTriggerResize
|
||||
TerminalTriggerResizeWithDimension
|
||||
TerminalUserScroll
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user