Initial release of the Windows Terminal source code

This commit introduces all of the Windows Terminal and Console Host source,
under the MIT license.
This commit is contained in:
Dustin Howett 2019-05-02 15:29:04 -07:00
commit d4d59fa339
1165 changed files with 182749 additions and 0 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* -text
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

245
.gitignore vendored Normal file
View File

@ -0,0 +1,245 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
objfre/
objchk/
# Visual Studio 2015 cache/options directory
.vs/
# Visual Studio Code cache/options directory
.vscode/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
## TODO: Comment the next line if you want to checkin your
## web deploy settings but do note that will include unencrypted
## passwords
#*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
*.opendb
*.db
# Windows Build System files
build*.dbb
build*.err
build*.evt
build*.log
build*.prf
build*.trc
build*.rec
build*.wrn
build*.metadata
# .razzlerc.cmd file - used by dev environment
tools/.razzlerc.*
# message compiler output
MSG*.bin
/*.exe
# python
*.pyc
**Generated Files/
**/Merged/*
**/Unmerged/*
profiles.json
*.metaproj

6
.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "dep/gsl"]
path = dep/gsl
url = https://github.com/Microsoft/gsl
[submodule "dep/wil"]
path = dep/wil
url = https://github.com/Microsoft/wil

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation. All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

14
NuGet.Config Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
<!-- Add repositories here to the list of available repositories -->
<!-- Dependencies that we must carry because they're not on public nuget feeds right now. -->
<add key="Static Package Dependencies" value="dep\packages" />
<!-- Internal NuGet feeds that may not be accessible outside Microsoft corporate network -->
<!--<add key="TAEF - internal" value="https://microsoft.pkgs.visualstudio.com/DefaultCollection/_packaging/Taef/nuget/v3/index.json" />
<add key="OpenConsole - Internal" value="https://microsoft.pkgs.visualstudio.com/_packaging/OpenConsole/nuget/v3/index.json" />-->
</packageSources>
</configuration>

1164
OpenConsole.sln Normal file

File diff suppressed because it is too large Load Diff

45
README.md Normal file
View File

@ -0,0 +1,45 @@
# Welcome to the Console Project!
This project is currently controlled by the Windows Developer Platform Tools & Runtimes' Open Source Software team (*WDG > DEP > DART > OSS*).
Our team can be reached at `dartcon@microsoft.com`.
The code is stored at <https://microsoft.visualstudio.com/Dart/_git/OpenConsole>.
The area path within the Microsoft.VisualStudio.com database for our Work Items is `OS\CORE-OS Core\DEP-Developer Ecosystem Platform\DART-Developer Tools and Runtimes\Open Source Software\Console`.
## Jumping In
To get started, feel free to read up on some of our documentation on the way we get things done and hop in.
Make a branch off of `dev/main` for yourself of the pattern `dev/myalias/foo` and feel free to push it to the server to get automatic builds and unit test runs.
Choose a bit of code to clean up, try to add a new feature, or improve something that you try to use every day.
When you are ready, use the [web portal](https://microsoft.visualstudio.com/Dart/_git/OpenConsole/pullrequests) to send a pull request into our `dev/main` branch and we'll be happy to help you get your code in line with the rest of the console.
## Building
OpenConsole uses submodules for some of its dependencies. To make sure submodules are restored or updated:
```
git submodule update --init --recursive
```
OpenConsole.sln may be built from within Visual Studio or from the command line using msbuild. To build from the command line:
```
nuget.exe restore OpenConsole.sln
msbuild.exe OpenConsole.sln
```
We provide a set of convienence scripts in the /tools directory to help automate the process of building and running tests.
## Assorted Notes
Here's some assorted notes on the way we do things. If you learn something about how we do things, feel free to contribute to any of our documentation files anywhere in the repository (or make some new ones!) This is a work in progress as we try to learn what we'll need to train people on in order to be effective contributors to our project. We're pretty blind to these things after staring at this code for so long... so mind the gaps and ask us plenty of questions!
* [Coding Style](./doc/STYLE.md)
* [Code Organization](./doc/ORGANIZATION.md)
* [Exceptions in our legacy codebase](./doc/EXCEPTIONS.md)
* [Helpful smart pointers and macros for interfacing with Windows in WIL](./doc/WIL.md)

View File

@ -0,0 +1,5 @@
<SignConfigXML>
<job platform="" configuration="" certSubject="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" jobname="EngFunSimpleSign" approvers="">
<file src="__INPATHROOT__\Microsoft.WindowsTerminal_8wekyb3d8bbwe.msixbundle" signType="136020001" dest="__OUTPATHROOT__\Microsoft.WindowsTerminal_8wekyb3d8bbwe.msixbundle" />
</job>
</SignConfigXML>

View File

@ -0,0 +1,57 @@
Param(
[Parameter(Mandatory,
HelpMessage="Base name for input .appx files")]
[string]
$ProjectName,
[Parameter(Mandatory,
HelpMessage="Appx Bundle Version")]
[version]
$BundleVersion,
[Parameter(Mandatory,
HelpMessage="Path under which to locate appx/msix files")]
[string]
$InputPath,
[Parameter(Mandatory,
HelpMessage="Output Path")]
[string]
$OutputPath,
[Parameter(HelpMessage="Path to makeappx.exe")]
[ValidateScript({Test-Path $_ -Type Leaf})]
[string]
$MakeAppxPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\MakeAppx.exe"
)
If ($null -Eq (Get-Item $MakeAppxPath -EA:SilentlyContinue)) {
Write-Error "Could not find MakeAppx.exe at `"$MakeAppxPath`".`nMake sure that -MakeAppxPath points to a valid SDK."
Exit 1
}
# Enumerates a set of appx files beginning with a project name
# and generates a temporary file containing a bundle content map.
Function Create-AppxBundleMapping {
Param(
[Parameter(Mandatory)]
[string]
$InputPath,
[Parameter(Mandatory)]
[string]
$ProjectName
)
$lines = @("[Files]")
Get-ChildItem -Path:$InputPath -Recurse -Filter:*$ProjectName* -Include *.appx, *.msix | % {
$lines += ("`"{0}`" `"{1}`"" -f ($_.FullName, $_.Name))
}
$outputFile = New-TemporaryFile
$lines | Out-File -Encoding:ASCII $outputFile
$outputFile
}
$NewMapping = Create-AppxBundleMapping -InputPath:$InputPath -ProjectName:$ProjectName
& $MakeAppxPath bundle /v /bv $BundleVersion.ToString() /f $NewMapping.FullName /p $OutputPath

13
common.openconsole.props Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
This props file is a workaround for the fact that for wapproj projects,
the $(SolutionDir) is never evaluated correctly. So, instead we're using this
file to define $(OpenConsoleDir), which should be used in place of $(SolutionDir)
-->
<PropertyGroup Condition="'$(OpenConsoleDir)'==''">
<OpenConsoleDir>$(MSBuildThisFileDirectory)</OpenConsoleDir>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,31 @@
{
"PrefixFilters": [
"."
],
"ContainsFilters": [
"/.",
"/.git/",
"/obj/",
"/bin/",
"/TestResults/",
"/packages/",
"/ipch/",
"/dep/",
"/.vs/"
],
"SuffixFilters": [
".dbb",
".evt",
".log",
".metadata",
".prf",
".trc",
".user",
".tmp",
".TMP",
".db",
".wrn",
".rec",
".err"
]
}

24
dep/Console/conapi.h Normal file
View File

@ -0,0 +1,24 @@
/*++
Copyright (c) Microsoft Corporation
Module Name:
- conapi.h
Abstract:
- This module contains the internal structures and definitions used by the console server.
Author:
- Therese Stowell (ThereseS) 12-Nov-1990
Revision History:
--*/
#pragma once
// these should be in precomp but aren't being picked up...
#include <unordered_map>
#define STATUS_SHARING_VIOLATION ((NTSTATUS)0xC0000043L)
#include "conmsgl1.h"
#include "conmsgl2.h"
#include "conmsgl3.h"

214
dep/Console/condrv.h Normal file
View File

@ -0,0 +1,214 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
condrv.h
Abstract:
This module contains the declarations shared by the console driver and the
user-mode components that use it.
Author:
Wedson Almeida Filho (wedsonaf) 24-Sep-2009
Environment:
Kernel and user modes.
--*/
#pragma once
#include "..\NT\ntioapi_x.h"
//
// Messages that can be received by servers, used in CD_IO_DESCRIPTOR::Function.
//
#define CONSOLE_IO_CONNECT 0x01
#define CONSOLE_IO_DISCONNECT 0x02
#define CONSOLE_IO_CREATE_OBJECT 0x03
#define CONSOLE_IO_CLOSE_OBJECT 0x04
#define CONSOLE_IO_RAW_WRITE 0x05
#define CONSOLE_IO_RAW_READ 0x06
#define CONSOLE_IO_USER_DEFINED 0x07
#define CONSOLE_IO_RAW_FLUSH 0x08
//
// Header of all IOs submitted to a server.
//
typedef struct _CD_IO_DESCRIPTOR {
LUID Identifier;
ULONG_PTR Process;
ULONG_PTR Object;
ULONG Function;
ULONG InputSize;
ULONG OutputSize;
ULONG Reserved;
} CD_IO_DESCRIPTOR, *PCD_IO_DESCRIPTOR;
//
// Types of objects, used in CREATE_OBJECT_INFORMATION::ObjectType.
//
#define CD_IO_OBJECT_TYPE_CURRENT_INPUT 0x01
#define CD_IO_OBJECT_TYPE_CURRENT_OUTPUT 0x02
#define CD_IO_OBJECT_TYPE_NEW_OUTPUT 0x03
#define CD_IO_OBJECT_TYPE_GENERIC 0x04
//
// Payload of the CONSOLE_IO_CREATE_OBJECT io.
//
typedef struct _CD_CREATE_OBJECT_INFORMATION {
ULONG ObjectType;
ULONG ShareMode;
ACCESS_MASK DesiredAccess;
} CD_CREATE_OBJECT_INFORMATION, *PCD_CREATE_OBJECT_INFORMATION;
//
// Create EA buffers.
//
#define CD_BROKER_EA_NAME "broker"
#define CD_SERVER_EA_NAME "server"
#define CD_ATTACH_EA_NAME "attach"
typedef struct _CD_CREATE_SERVER {
HANDLE BrokerHandle;
LUID BrokerRequest;
} CD_CREATE_SERVER, *PCD_CREATE_SERVER;
typedef struct _CD_ATTACH_INFORMATION {
HANDLE ProcessId;
} CD_ATTACH_INFORMATION, *PCD_ATTACH_INFORMATION;
typedef struct _CD_ATTACH_INFORMATION64 {
PVOID64 ProcessId;
} CD_ATTACH_INFORMATION64, *PCD_ATTACH_INFORMATION64;
//
// Information passed to the driver by a server when a connection is accepted.
//
typedef struct _CD_CONNECTION_INFORMATION {
ULONG_PTR Process;
ULONG_PTR Input;
ULONG_PTR Output;
} CD_CONNECTION_INFORMATION, *PCD_CONNECTION_INFORMATION;
//
// Ioctls.
//
typedef struct _CD_IO_BUFFER {
ULONG Size;
PVOID Buffer;
} CD_IO_BUFFER, *PCD_IO_BUFFER;
typedef struct _CD_IO_BUFFER64 {
ULONG Size;
PVOID64 Buffer;
} CD_IO_BUFFER64, *PCD_IO_BUFFER64;
typedef struct _CD_USER_DEFINED_IO {
HANDLE Client;
ULONG InputCount;
ULONG OutputCount;
CD_IO_BUFFER Buffers[ANYSIZE_ARRAY];
} CD_USER_DEFINED_IO, *PCD_USER_DEFINED_IO;
typedef struct _CD_USER_DEFINED_IO64 {
PVOID64 Client;
ULONG InputCount;
ULONG OutputCount;
CD_IO_BUFFER64 Buffers[ANYSIZE_ARRAY];
} CD_USER_DEFINED_IO64, *PCD_USER_DEFINED_IO64;
typedef struct _CD_IO_BUFFER_DESCRIPTOR {
PVOID Data;
ULONG Size;
ULONG Offset;
} CD_IO_BUFFER_DESCRIPTOR, *PCD_IO_BUFFER_DESCRIPTOR;
typedef struct _CD_IO_COMPLETE {
LUID Identifier;
IO_STATUS_BLOCK IoStatus;
CD_IO_BUFFER_DESCRIPTOR Write;
} CD_IO_COMPLETE, *PCD_IO_COMPLETE;
typedef struct _CD_IO_OPERATION {
LUID Identifier;
CD_IO_BUFFER_DESCRIPTOR Buffer;
} CD_IO_OPERATION, *PCD_IO_OPERATION;
typedef struct _CD_IO_SERVER_INFORMATION {
HANDLE InputAvailableEvent;
} CD_IO_SERVER_INFORMATION, *PCD_IO_SERVER_INFORMATION;
typedef struct _CD_IO_DISPLAY_SIZE {
ULONG Width;
ULONG Height;
} CD_IO_DISPLAY_SIZE, *PCD_IO_DISPLAY_SIZE;
typedef struct _CD_IO_CHARACTER {
WCHAR Character;
USHORT Atribute;
} CD_IO_CHARACTER, *PCD_IO_CHARACTER;
typedef struct _CD_IO_ROW_INFORMATION {
SHORT Index;
PCD_IO_CHARACTER Old;
PCD_IO_CHARACTER New;
} CD_IO_ROW_INFORMATION, *PCD_IO_ROW_INFORMATION;
typedef struct _CD_IO_CURSOR_INFORMATION {
USHORT Column;
USHORT Row;
ULONG Height;
BOOLEAN IsVisible;
} CD_IO_CURSOR_INFORMATION, *PCD_IO_CURSOR_INFORMATION;
#define IOCTL_CONDRV_READ_IO \
CTL_CODE(FILE_DEVICE_CONSOLE, 1, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_COMPLETE_IO \
CTL_CODE(FILE_DEVICE_CONSOLE, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_READ_INPUT \
CTL_CODE(FILE_DEVICE_CONSOLE, 3, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_WRITE_OUTPUT \
CTL_CODE(FILE_DEVICE_CONSOLE, 4, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_ISSUE_USER_IO \
CTL_CODE(FILE_DEVICE_CONSOLE, 5, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_DISCONNECT_PIPE \
CTL_CODE(FILE_DEVICE_CONSOLE, 6, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_SET_SERVER_INFORMATION \
CTL_CODE(FILE_DEVICE_CONSOLE, 7, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_GET_SERVER_PID \
CTL_CODE(FILE_DEVICE_CONSOLE, 8, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_GET_DISPLAY_SIZE \
CTL_CODE(FILE_DEVICE_CONSOLE, 9, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_UPDATE_DISPLAY \
CTL_CODE(FILE_DEVICE_CONSOLE, 10, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_SET_CURSOR \
CTL_CODE(FILE_DEVICE_CONSOLE, 11, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_ALLOW_VIA_UIACCESS \
CTL_CODE(FILE_DEVICE_CONSOLE, 12, METHOD_NEITHER, FILE_ANY_ACCESS)
#define IOCTL_CONDRV_LAUNCH_SERVER \
CTL_CODE(FILE_DEVICE_CONSOLE, 13, METHOD_NEITHER, FILE_ANY_ACCESS)

156
dep/Console/conmsgl1.h Normal file
View File

@ -0,0 +1,156 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
conmsgl1.h
Abstract:
This include file defines the layer 1 message formats used to communicate
between the client and server portions of the CONSOLE portion of the
Windows subsystem.
Author:
Therese Stowell (thereses) 10-Nov-1990
Revision History:
Wedson Almeida Filho (wedsonaf) 23-May-2010
Modified the messages for use with the console driver.
--*/
#pragma once
#define CONSOLE_FIRST_API_NUMBER(Layer) \
(Layer << 24) \
typedef struct _CONSOLE_SERVER_MSG {
ULONG IconId;
ULONG HotKey;
ULONG StartupFlags;
USHORT FillAttribute;
USHORT ShowWindow;
COORD ScreenBufferSize;
COORD WindowSize;
COORD WindowOrigin;
ULONG ProcessGroupId;
BOOLEAN ConsoleApp;
BOOLEAN WindowVisible;
USHORT TitleLength;
WCHAR Title[MAX_PATH + 1];
USHORT ApplicationNameLength;
WCHAR ApplicationName[128];
USHORT CurrentDirectoryLength;
WCHAR CurrentDirectory[MAX_PATH + 1];
} CONSOLE_SERVER_MSG, *PCONSOLE_SERVER_MSG;
typedef struct _CONSOLE_BROKER_DATA {
WCHAR DesktopName[MAX_PATH];
} CONSOLE_BROKER_MSG, *PCONSOLE_BROKER_MSG;
typedef struct _CONSOLE_GETCP_MSG {
OUT ULONG CodePage;
IN BOOLEAN Output;
} CONSOLE_GETCP_MSG, *PCONSOLE_GETCP_MSG;
typedef struct _CONSOLE_MODE_MSG {
IN OUT ULONG Mode;
} CONSOLE_MODE_MSG, *PCONSOLE_MODE_MSG;
typedef struct _CONSOLE_GETNUMBEROFINPUTEVENTS_MSG {
OUT ULONG ReadyEvents;
} CONSOLE_GETNUMBEROFINPUTEVENTS_MSG, *PCONSOLE_GETNUMBEROFINPUTEVENTS_MSG;
typedef struct _CONSOLE_GETCONSOLEINPUT_MSG {
OUT ULONG NumRecords;
IN USHORT Flags;
IN BOOLEAN Unicode;
} CONSOLE_GETCONSOLEINPUT_MSG, *PCONSOLE_GETCONSOLEINPUT_MSG;
typedef struct _CONSOLE_READCONSOLE_MSG {
IN BOOLEAN Unicode;
IN BOOLEAN ProcessControlZ;
IN USHORT ExeNameLength;
IN ULONG InitialNumBytes;
IN ULONG CtrlWakeupMask;
OUT ULONG ControlKeyState;
OUT ULONG NumBytes;
} CONSOLE_READCONSOLE_MSG, *PCONSOLE_READCONSOLE_MSG;
typedef struct _CONSOLE_WRITECONSOLE_MSG {
OUT ULONG NumBytes;
IN BOOLEAN Unicode;
} CONSOLE_WRITECONSOLE_MSG, *PCONSOLE_WRITECONSOLE_MSG;
typedef struct _CONSOLE_LANGID_MSG {
OUT LANGID LangId;
} CONSOLE_LANGID_MSG, *PCONSOLE_LANGID_MSG;
typedef struct _CONSOLE_MAPBITMAP_MSG {
OUT HANDLE Mutex;
OUT PVOID Bitmap;
} CONSOLE_MAPBITMAP_MSG, *PCONSOLE_MAPBITMAP_MSG;
typedef struct _CONSOLE_MAPBITMAP_MSG64 {
OUT PVOID64 Mutex;
OUT PVOID64 Bitmap;
} CONSOLE_MAPBITMAP_MSG64, *PCONSOLE_MAPBITMAP_MSG64;
typedef enum _CONSOLE_API_NUMBER_L1 {
ConsolepGetCP = CONSOLE_FIRST_API_NUMBER(1),
ConsolepGetMode,
ConsolepSetMode,
ConsolepGetNumberOfInputEvents,
ConsolepGetConsoleInput,
ConsolepReadConsole,
ConsolepWriteConsole,
ConsolepNotifyLastClose,
ConsolepGetLangId,
ConsolepMapBitmap,
} CONSOLE_API_NUMBER_L1, *PCONSOLE_API_NUMBER_L1;
typedef struct _CONSOLE_MSG_HEADER {
ULONG ApiNumber;
ULONG ApiDescriptorSize;
} CONSOLE_MSG_HEADER, *PCONSOLE_MSG_HEADER;
typedef union _CONSOLE_MSG_BODY_L1 {
CONSOLE_GETCP_MSG GetConsoleCP;
CONSOLE_MODE_MSG GetConsoleMode;
CONSOLE_MODE_MSG SetConsoleMode;
CONSOLE_GETNUMBEROFINPUTEVENTS_MSG GetNumberOfConsoleInputEvents;
CONSOLE_GETCONSOLEINPUT_MSG GetConsoleInput;
CONSOLE_READCONSOLE_MSG ReadConsole;
CONSOLE_WRITECONSOLE_MSG WriteConsole;
CONSOLE_LANGID_MSG GetConsoleLangId;
#if defined(BUILD_WOW6432) && !defined(BUILD_WOW3232)
CONSOLE_MAPBITMAP_MSG64 MapBitmap;
#else
CONSOLE_MAPBITMAP_MSG MapBitmap;
#endif
} CONSOLE_MSG_BODY_L1, *PCONSOLE_MSG_BODY_L1;
#ifndef __cplusplus
typedef struct _CONSOLE_MSG_L1 {
CONSOLE_MSG_HEADER Header;
union {
CONSOLE_MSG_BODY_L1;
} u;
} CONSOLE_MSG_L1, *PCONSOLE_MSG_L1;
#else
typedef struct _CONSOLE_MSG_L1 :
public CONSOLE_MSG_HEADER
{
CONSOLE_MSG_BODY_L1 u;
} CONSOLE_MSG_L1, *PCONSOLE_MSG_L1;
#endif // __cplusplus

207
dep/Console/conmsgl2.h Normal file
View File

@ -0,0 +1,207 @@
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
conmsgl2.h
Abstract:
This include file defines the layer 2 message formats used to communicate
between the client and server portions of the CONSOLE portion of the
Windows subsystem.
Author:
Therese Stowell (thereses) 10-Nov-1990
Revision History:
Wedson Almeida Filho (wedsonaf) 23-May-2010
Modified the messages for use with the console driver.
--*/
#pragma once
typedef struct _CONSOLE_CREATESCREENBUFFER_MSG {
IN ULONG Flags;
IN ULONG BitmapInfoLength;
IN ULONG Usage;
} CONSOLE_CREATESCREENBUFFER_MSG, *PCONSOLE_CREATESCREENBUFFER_MSG;
#define CONSOLE_ASCII 0x1
#define CONSOLE_REAL_UNICODE 0x2
#define CONSOLE_ATTRIBUTE 0x3
#define CONSOLE_FALSE_UNICODE 0x4
typedef struct _CONSOLE_FILLCONSOLEOUTPUT_MSG {
IN COORD WriteCoord;
IN ULONG ElementType;
IN USHORT Element;
IN OUT ULONG Length;
} CONSOLE_FILLCONSOLEOUTPUT_MSG, *PCONSOLE_FILLCONSOLEOUTPUT_MSG;
typedef struct _CONSOLE_CTRLEVENT_MSG {
IN ULONG CtrlEvent;
IN ULONG ProcessGroupId;
} CONSOLE_CTRLEVENT_MSG, *PCONSOLE_CTRLEVENT_MSG;
typedef struct _CONSOLE_SETCP_MSG {
IN ULONG CodePage;
IN BOOLEAN Output;
} CONSOLE_SETCP_MSG, *PCONSOLE_SETCP_MSG;
typedef struct _CONSOLE_GETCURSORINFO_MSG {
OUT ULONG CursorSize;
OUT BOOLEAN Visible;
} CONSOLE_GETCURSORINFO_MSG, *PCONSOLE_GETCURSORINFO_MSG;
typedef struct _CONSOLE_SETCURSORINFO_MSG {
IN ULONG CursorSize;
IN BOOLEAN Visible;
} CONSOLE_SETCURSORINFO_MSG, *PCONSOLE_SETCURSORINFO_MSG;
typedef struct _CONSOLE_SCREENBUFFERINFO_MSG {
IN OUT COORD Size;
IN OUT COORD CursorPosition;
IN OUT COORD ScrollPosition;
IN OUT USHORT Attributes;
IN OUT COORD CurrentWindowSize;
IN OUT COORD MaximumWindowSize;
IN OUT USHORT PopupAttributes;
IN OUT BOOLEAN FullscreenSupported;
IN OUT COLORREF ColorTable[16];
} CONSOLE_SCREENBUFFERINFO_MSG, *PCONSOLE_SCREENBUFFERINFO_MSG;
typedef struct _CONSOLE_SETSCREENBUFFERSIZE_MSG {
IN COORD Size;
} CONSOLE_SETSCREENBUFFERSIZE_MSG, *PCONSOLE_SETSCREENBUFFERSIZE_MSG;
typedef struct _CONSOLE_SETCURSORPOSITION_MSG {
IN COORD CursorPosition;
} CONSOLE_SETCURSORPOSITION_MSG, *PCONSOLE_SETCURSORPOSITION_MSG;
typedef struct _CONSOLE_GETLARGESTWINDOWSIZE_MSG {
OUT COORD Size;
} CONSOLE_GETLARGESTWINDOWSIZE_MSG, *PCONSOLE_GETLARGESTWINDOWSIZE_MSG;
typedef struct _CONSOLE_SCROLLSCREENBUFFER_MSG {
IN SMALL_RECT ScrollRectangle;
IN SMALL_RECT ClipRectangle;
IN BOOLEAN Clip;
IN BOOLEAN Unicode;
IN COORD DestinationOrigin;
IN CHAR_INFO Fill;
} CONSOLE_SCROLLSCREENBUFFER_MSG, *PCONSOLE_SCROLLSCREENBUFFER_MSG;
typedef struct _CONSOLE_SETTEXTATTRIBUTE_MSG {
IN USHORT Attributes;
} CONSOLE_SETTEXTATTRIBUTE_MSG, *PCONSOLE_SETTEXTATTRIBUTE_MSG;
typedef struct _CONSOLE_SETWINDOWINFO_MSG {
IN BOOLEAN Absolute;
IN SMALL_RECT Window;
} CONSOLE_SETWINDOWINFO_MSG, *PCONSOLE_SETWINDOWINFO_MSG;
typedef struct _CONSOLE_READCONSOLEOUTPUTSTRING_MSG {
IN COORD ReadCoord;
IN ULONG StringType;
OUT ULONG NumRecords;
} CONSOLE_READCONSOLEOUTPUTSTRING_MSG, *PCONSOLE_READCONSOLEOUTPUTSTRING_MSG;
typedef struct _CONSOLE_WRITECONSOLEINPUT_MSG {
OUT ULONG NumRecords;
IN BOOLEAN Unicode;
IN BOOLEAN Append;
} CONSOLE_WRITECONSOLEINPUT_MSG, *PCONSOLE_WRITECONSOLEINPUT_MSG;
typedef struct _CONSOLE_WRITECONSOLEOUTPUTSTRING_MSG {
IN COORD WriteCoord;
IN ULONG StringType;
OUT ULONG NumRecords;
} CONSOLE_WRITECONSOLEOUTPUTSTRING_MSG, *PCONSOLE_WRITECONSOLEOUTPUTSTRING_MSG;
typedef struct _CONSOLE_WRITECONSOLEOUTPUT_MSG {
IN OUT SMALL_RECT CharRegion;
IN BOOLEAN Unicode;
} CONSOLE_WRITECONSOLEOUTPUT_MSG, *PCONSOLE_WRITECONSOLEOUTPUT_MSG;
typedef struct _CONSOLE_READCONSOLEOUTPUT_MSG {
IN OUT SMALL_RECT CharRegion;
IN BOOLEAN Unicode;
} CONSOLE_READCONSOLEOUTPUT_MSG, *PCONSOLE_READCONSOLEOUTPUT_MSG;
typedef struct _CONSOLE_GETTITLE_MSG {
OUT ULONG TitleLength;
IN BOOLEAN Unicode;
IN BOOLEAN Original;
} CONSOLE_GETTITLE_MSG, *PCONSOLE_GETTITLE_MSG;
typedef struct _CONSOLE_SETTITLE_MSG {
IN BOOLEAN Unicode;
} CONSOLE_SETTITLE_MSG, *PCONSOLE_SETTITLE_MSG;
typedef enum _CONSOLE_API_NUMBER_L2 {
ConsolepFillConsoleOutput = CONSOLE_FIRST_API_NUMBER(2),
ConsolepGenerateCtrlEvent,
ConsolepSetActiveScreenBuffer,
ConsolepFlushInputBuffer,
ConsolepSetCP,
ConsolepGetCursorInfo,
ConsolepSetCursorInfo,
ConsolepGetScreenBufferInfo,
ConsolepSetScreenBufferInfo,
ConsolepSetScreenBufferSize,
ConsolepSetCursorPosition,
ConsolepGetLargestWindowSize,
ConsolepScrollScreenBuffer,
ConsolepSetTextAttribute,
ConsolepSetWindowInfo,
ConsolepReadConsoleOutputString,
ConsolepWriteConsoleInput,
ConsolepWriteConsoleOutput,
ConsolepWriteConsoleOutputString,
ConsolepReadConsoleOutput,
ConsolepGetTitle,
ConsolepSetTitle,
} CONSOLE_API_NUMBER_L2, *PCONSOLE_API_NUMBER_L2;
typedef union _CONSOLE_MSG_BODY_L2 {
CONSOLE_CTRLEVENT_MSG GenerateConsoleCtrlEvent;
CONSOLE_FILLCONSOLEOUTPUT_MSG FillConsoleOutput;
CONSOLE_SETCP_MSG SetConsoleCP;
CONSOLE_GETCURSORINFO_MSG GetConsoleCursorInfo;
CONSOLE_SETCURSORINFO_MSG SetConsoleCursorInfo;
CONSOLE_SCREENBUFFERINFO_MSG GetConsoleScreenBufferInfo;
CONSOLE_SCREENBUFFERINFO_MSG SetConsoleScreenBufferInfo;
CONSOLE_SETSCREENBUFFERSIZE_MSG SetConsoleScreenBufferSize;
CONSOLE_SETCURSORPOSITION_MSG SetConsoleCursorPosition;
CONSOLE_GETLARGESTWINDOWSIZE_MSG GetLargestConsoleWindowSize;
CONSOLE_SCROLLSCREENBUFFER_MSG ScrollConsoleScreenBuffer;
CONSOLE_SETTEXTATTRIBUTE_MSG SetConsoleTextAttribute;
CONSOLE_SETWINDOWINFO_MSG SetConsoleWindowInfo;
CONSOLE_READCONSOLEOUTPUTSTRING_MSG ReadConsoleOutputString;
CONSOLE_WRITECONSOLEINPUT_MSG WriteConsoleInput;
CONSOLE_WRITECONSOLEOUTPUTSTRING_MSG WriteConsoleOutputString;
CONSOLE_WRITECONSOLEOUTPUT_MSG WriteConsoleOutput;
CONSOLE_READCONSOLEOUTPUT_MSG ReadConsoleOutput;
CONSOLE_SETTITLE_MSG SetConsoleTitle;
CONSOLE_GETTITLE_MSG GetConsoleTitle;
} CONSOLE_MSG_BODY_L2, *PCONSOLE_MSG_BODY_L2;
#ifndef __cplusplus
typedef struct _CONSOLE_MSG_L2 {
CONSOLE_MSG_HEADER Header;
union {
CONSOLE_MSG_BODY_L2;
} u;
} CONSOLE_MSG_L2, *PCONSOLE_MSG_L2;
#else
typedef struct _CONSOLE_MSG_L2 :
public CONSOLE_MSG_HEADER
{
CONSOLE_MSG_BODY_L2 u;
} CONSOLE_MSG_L2, *PCONSOLE_MSG_L2;
#endif // __cplusplus

392
dep/Console/conmsgl3.h Normal file
View File

@ -0,0 +1,392 @@
/*++
Copyright (c) 1985 - 1999, Microsoft Corporation
Module Name:
conmsgl3.h
Abstract:
This include file defines the message formats used to communicate
between the client and server portions of the CONSOLE portion of the
Windows subsystem.
Author:
Therese Stowell (thereses) 10-Nov-1990
Revision History:
Wedson Almeida Filho (wedsonaf) 23-May-2010
Modified the messages for use with the console driver.
--*/
#pragma once
#include <winconp.h> // need FONT_SELECT
typedef struct _CONSOLE_GETNUMBEROFFONTS_MSG {
OUT ULONG NumberOfFonts;
} CONSOLE_GETNUMBEROFFONTS_MSG, *PCONSOLE_GETNUMBEROFFONTS_MSG;
typedef struct _CONSOLE_GETSELECTIONINFO_MSG {
OUT CONSOLE_SELECTION_INFO SelectionInfo;
} CONSOLE_GETSELECTIONINFO_MSG, *PCONSOLE_GETSELECTIONINFO_MSG;
typedef struct _CONSOLE_GETMOUSEINFO_MSG {
OUT ULONG NumButtons;
} CONSOLE_GETMOUSEINFO_MSG, *PCONSOLE_GETMOUSEINFO_MSG;
typedef struct _CONSOLE_GETFONTINFO_MSG {
IN BOOLEAN MaximumWindow;
OUT ULONG NumFonts; // this value is valid even for error cases
} CONSOLE_GETFONTINFO_MSG, *PCONSOLE_GETFONTINFO_MSG;
typedef struct _CONSOLE_GETFONTSIZE_MSG {
IN ULONG FontIndex;
OUT COORD FontSize;
} CONSOLE_GETFONTSIZE_MSG, *PCONSOLE_GETFONTSIZE_MSG;
typedef struct _CONSOLE_CURRENTFONT_MSG {
IN BOOLEAN MaximumWindow;
IN OUT ULONG FontIndex;
IN OUT COORD FontSize;
IN OUT ULONG FontFamily;
IN OUT ULONG FontWeight;
IN OUT WCHAR FaceName[LF_FACESIZE];
} CONSOLE_CURRENTFONT_MSG, *PCONSOLE_CURRENTFONT_MSG;
typedef struct _CONSOLE_SETFONT_MSG {
IN ULONG FontIndex;
} CONSOLE_SETFONT_MSG, *PCONSOLE_SETFONT_MSG;
typedef struct _CONSOLE_SETICON_MSG {
IN HICON hIcon;
} CONSOLE_SETICON_MSG, *PCONSOLE_SETICON_MSG;
typedef struct _CONSOLE_SETICON_MSG64 {
IN PVOID64 hIcon;
} CONSOLE_SETICON_MSG64, *PCONSOLE_SETICON_MSG64;
typedef struct _CONSOLE_ADDALIAS_MSG {
IN USHORT SourceLength;
IN USHORT TargetLength;
IN USHORT ExeLength;
IN BOOLEAN Unicode;
} CONSOLE_ADDALIAS_MSG, *PCONSOLE_ADDALIAS_MSG;
typedef struct _CONSOLE_GETALIAS_MSG {
IN USHORT SourceLength;
OUT USHORT TargetLength;
IN USHORT ExeLength;
IN BOOLEAN Unicode;
} CONSOLE_GETALIAS_MSG, *PCONSOLE_GETALIAS_MSG;
typedef struct _CONSOLE_GETALIASESLENGTH_MSG {
OUT ULONG AliasesLength;
IN BOOLEAN Unicode;
} CONSOLE_GETALIASESLENGTH_MSG, *PCONSOLE_GETALIASESLENGTH_MSG;
typedef struct _CONSOLE_GETALIASEXESLENGTH_MSG {
OUT ULONG AliasExesLength;
IN BOOLEAN Unicode;
} CONSOLE_GETALIASEXESLENGTH_MSG, *PCONSOLE_GETALIASEXESLENGTH_MSG;
typedef struct _CONSOLE_GETALIASES_MSG {
IN BOOLEAN Unicode;
OUT ULONG AliasesBufferLength;
} CONSOLE_GETALIASES_MSG, *PCONSOLE_GETALIASES_MSG;
typedef struct _CONSOLE_GETALIASEXES_MSG {
OUT ULONG AliasExesBufferLength;
IN BOOLEAN Unicode;
} CONSOLE_GETALIASEXES_MSG, *PCONSOLE_GETALIASEXES_MSG;
typedef struct _CONSOLE_EXPUNGECOMMANDHISTORY_MSG {
IN BOOLEAN Unicode;
} CONSOLE_EXPUNGECOMMANDHISTORY_MSG, *PCONSOLE_EXPUNGECOMMANDHISTORY_MSG;
typedef struct _CONSOLE_SETNUMBEROFCOMMANDS_MSG {
IN ULONG NumCommands;
IN BOOLEAN Unicode;
} CONSOLE_SETNUMBEROFCOMMANDS_MSG, *PCONSOLE_SETNUMBEROFCOMMANDS_MSG;
typedef struct _CONSOLE_GETCOMMANDHISTORYLENGTH_MSG {
OUT ULONG CommandHistoryLength;
IN BOOLEAN Unicode;
} CONSOLE_GETCOMMANDHISTORYLENGTH_MSG, *PCONSOLE_GETCOMMANDHISTORYLENGTH_MSG;
typedef struct _CONSOLE_GETCOMMANDHISTORY_MSG {
OUT ULONG CommandBufferLength;
IN BOOLEAN Unicode;
} CONSOLE_GETCOMMANDHISTORY_MSG, *PCONSOLE_GETCOMMANDHISTORY_MSG;
typedef struct _CONSOLE_INVALIDATERECT_MSG {
IN SMALL_RECT Rect;
} CONSOLE_INVALIDATERECT_MSG, *PCONSOLE_INVALIDATERECT_MSG;
typedef struct _CONSOLE_VDM_MSG {
IN ULONG iFunction;
OUT BOOLEAN Bool;
IN OUT POINT Point;
OUT RECT Rect;
} CONSOLE_VDM_MSG, *PCONSOLE_VDM_MSG;
typedef struct _CONSOLE_SETCURSOR_MSG {
IN HCURSOR CursorHandle;
} CONSOLE_SETCURSOR_MSG, *PCONSOLE_SETCURSOR_MSG;
typedef struct _CONSOLE_SETCURSOR_MSG64 {
IN PVOID64 CursorHandle;
} CONSOLE_SETCURSOR_MSG64, *PCONSOLE_SETCURSOR_MSG64;
typedef struct _CONSOLE_SHOWCURSOR_MSG {
IN BOOLEAN bShow;
OUT ULONG DisplayCount;
} CONSOLE_SHOWCURSOR_MSG, *PCONSOLE_SHOWCURSOR_MSG;
typedef struct _CONSOLE_MENUCONTROL_MSG {
IN ULONG CommandIdLow;
IN ULONG CommandIdHigh;
OUT HMENU hMenu;
} CONSOLE_MENUCONTROL_MSG, *PCONSOLE_MENUCONTROL_MSG;
typedef struct _CONSOLE_MENUCONTROL_MSG64 {
IN ULONG CommandIdLow;
IN ULONG CommandIdHigh;
OUT PVOID64 hMenu;
} CONSOLE_MENUCONTROL_MSG64, *PCONSOLE_MENUCONTROL_MSG64;
typedef struct _CONSOLE_SETPALETTE_MSG {
IN HPALETTE hPalette;
IN ULONG dwUsage;
} CONSOLE_SETPALETTE_MSG, *PCONSOLE_SETPALETTE_MSG;
typedef struct _CONSOLE_SETPALETTE_MSG64 {
IN PVOID64 hPalette;
IN ULONG dwUsage;
} CONSOLE_SETPALETTE_MSG64, *PCONSOLE_SETPALETTE_MSG64;
typedef struct _CONSOLE_SETDISPLAYMODE_MSG {
IN ULONG dwFlags;
OUT COORD ScreenBufferDimensions;
} CONSOLE_SETDISPLAYMODE_MSG, *PCONSOLE_SETDISPLAYMODE_MSG;
typedef struct _CONSOLE_REGISTERVDM_MSG {
IN ULONG RegisterFlags;
IN HANDLE StartEvent;
IN HANDLE EndEvent;
IN HANDLE ErrorEvent;
OUT ULONG StateLength;
OUT PVOID StateBuffer;
OUT PVOID VDMBuffer;
} CONSOLE_REGISTERVDM_MSG, *PCONSOLE_REGISTERVDM_MSG;
typedef struct _CONSOLE_REGISTERVDM_MSG64 {
IN ULONG RegisterFlags;
IN PVOID64 StartEvent;
IN PVOID64 EndEvent;
IN PVOID64 ErrorEvent;
OUT ULONG StateLength;
OUT PVOID64 StateBuffer;
OUT PVOID64 VDMBuffer;
} CONSOLE_REGISTERVDM_MSG64, *PCONSOLE_REGISTERVDM_MSG64;
typedef struct _CONSOLE_GETHARDWARESTATE_MSG {
OUT COORD Resolution;
OUT COORD FontSize;
} CONSOLE_GETHARDWARESTATE_MSG, *PCONSOLE_GETHARDWARESTATE_MSG;
typedef struct _CONSOLE_SETHARDWARESTATE_MSG {
IN COORD Resolution;
IN COORD FontSize;
} CONSOLE_SETHARDWARESTATE_MSG, *PCONSOLE_SETHARDWARESTATE_MSG;
typedef struct _CONSOLE_GETDISPLAYMODE_MSG {
OUT ULONG ModeFlags;
} CONSOLE_GETDISPLAYMODE_MSG, *PCONSOLE_GETDISPLAYMODE_MSG;
typedef struct _CONSOLE_GETKEYBOARDLAYOUTNAME_MSG {
union {
WCHAR awchLayout[9];
char achLayout[9];
};
BOOLEAN bAnsi;
} CONSOLE_GETKEYBOARDLAYOUTNAME_MSG, *PCONSOLE_GETKEYBOARDLAYOUTNAME_MSG;
typedef struct _CONSOLE_SETKEYSHORTCUTS_MSG {
IN BOOLEAN Set;
IN BYTE ReserveKeys;
} CONSOLE_SETKEYSHORTCUTS_MSG, *PCONSOLE_SETKEYSHORTCUTS_MSG;
typedef struct _CONSOLE_SETMENUCLOSE_MSG {
IN BOOLEAN Enable;
} CONSOLE_SETMENUCLOSE_MSG, *PCONSOLE_SETMENUCLOSE_MSG;
typedef struct _CONSOLE_CHAR_TYPE_MSG {
IN COORD coordCheck;
OUT ULONG dwType;
} CONSOLE_CHAR_TYPE_MSG, *PCONSOLE_CHAR_TYPE_MSG;
typedef struct _CONSOLE_LOCAL_EUDC_MSG {
IN USHORT CodePoint;
IN COORD FontSize;
} CONSOLE_LOCAL_EUDC_MSG, *PCONSOLE_LOCAL_EUDC_MSG;
typedef struct _CONSOLE_CURSOR_MODE_MSG {
IN OUT BOOLEAN Blink;
IN OUT BOOLEAN DBEnable;
} CONSOLE_CURSOR_MODE_MSG, *PCONSOLE_CURSOR_MODE_MSG;
typedef struct _CONSOLE_REGISTEROS2_MSG {
IN BOOLEAN fOs2Register;
} CONSOLE_REGISTEROS2_MSG, *PCONSOLE_REGISTEROS2_MSG;
typedef struct _CONSOLE_SETOS2OEMFORMAT_MSG {
IN BOOLEAN fOs2OemFormat;
} CONSOLE_SETOS2OEMFORMAT_MSG, *PCONSOLE_SETOS2OEMFORMAT_MSG;
typedef struct _CONSOLE_NLS_MODE_MSG {
IN OUT BOOLEAN Ready;
IN ULONG NlsMode;
} CONSOLE_NLS_MODE_MSG, *PCONSOLE_NLS_MODE_MSG;
typedef struct _CONSOLE_GETCONSOLEWINDOW_MSG {
OUT HWND hwnd;
} CONSOLE_GETCONSOLEWINDOW_MSG, *PCONSOLE_GETCONSOLEWINDOW_MSG;
typedef struct _CONSOLE_GETCONSOLEWINDOW_MSG64 {
OUT PVOID64 hwnd;
} CONSOLE_GETCONSOLEWINDOW_MSG64, *PCONSOLE_GETCONSOLEWINDOW_MSG64;
typedef struct _CONSOLE_GETPROCESSLIST_MSG {
OUT ULONG dwProcessCount;
} CONSOLE_GETCONSOLEPROCESSLIST_MSG, *PCONSOLE_GETCONSOLEPROCESSLIST_MSG;
typedef struct _CONSOLE_GETHISTORY_MSG {
OUT ULONG HistoryBufferSize;
OUT ULONG NumberOfHistoryBuffers;
OUT ULONG dwFlags;
} CONSOLE_HISTORY_MSG, *PCONSOLE_HISTORY_MSG;
typedef enum _CONSOLE_API_NUMBER_L3 {
ConsolepGetNumberOfFonts = CONSOLE_FIRST_API_NUMBER(3),
ConsolepGetMouseInfo,
ConsolepGetFontInfo,
ConsolepGetFontSize,
ConsolepGetCurrentFont,
ConsolepSetFont,
ConsolepSetIcon,
ConsolepInvalidateBitmapRect,
ConsolepVDMOperation,
ConsolepSetCursor,
ConsolepShowCursor,
ConsolepMenuControl,
ConsolepSetPalette,
ConsolepSetDisplayMode,
ConsolepRegisterVDM,
ConsolepGetHardwareState,
ConsolepSetHardwareState,
ConsolepGetDisplayMode,
ConsolepAddAlias,
ConsolepGetAlias,
ConsolepGetAliasesLength,
ConsolepGetAliasExesLength,
ConsolepGetAliases,
ConsolepGetAliasExes,
ConsolepExpungeCommandHistory,
ConsolepSetNumberOfCommands,
ConsolepGetCommandHistoryLength,
ConsolepGetCommandHistory,
ConsolepSetKeyShortcuts,
ConsolepSetMenuClose,
ConsolepGetKeyboardLayoutName,
ConsolepGetConsoleWindow,
ConsolepCharType,
ConsolepSetLocalEUDC,
ConsolepSetCursorMode,
ConsolepGetCursorMode,
ConsolepRegisterOS2,
ConsolepSetOS2OemFormat,
ConsolepGetNlsMode,
ConsolepSetNlsMode,
ConsolepGetSelectionInfo,
ConsolepGetConsoleProcessList,
ConsolepGetHistory,
ConsolepSetHistory,
ConsolepSetCurrentFont,
} CONSOLE_API_NUMBER_L3, *PCONSOLE_API_NUMBER_L3;
typedef union _CONSOLE_MSG_BODY_L3 {
CONSOLE_GETNUMBEROFFONTS_MSG GetNumberOfConsoleFonts;
CONSOLE_GETMOUSEINFO_MSG GetConsoleMouseInfo;
CONSOLE_GETFONTINFO_MSG GetConsoleFontInfo;
CONSOLE_GETFONTSIZE_MSG GetConsoleFontSize;
CONSOLE_CURRENTFONT_MSG GetCurrentConsoleFont;
CONSOLE_SETFONT_MSG SetConsoleFont;
CONSOLE_INVALIDATERECT_MSG InvalidateConsoleBitmapRect;
CONSOLE_VDM_MSG VDMConsoleOperation;
CONSOLE_SHOWCURSOR_MSG ShowConsoleCursor;
CONSOLE_SETDISPLAYMODE_MSG SetConsoleDisplayMode;
#ifdef BUILD_WOW6432
CONSOLE_REGISTERVDM_MSG64 RegisterConsoleVDM;
CONSOLE_SETCURSOR_MSG64 SetConsoleCursor;
CONSOLE_SETICON_MSG64 SetConsoleIcon;
CONSOLE_MENUCONTROL_MSG64 ConsoleMenuControl;
CONSOLE_SETPALETTE_MSG64 SetConsolePalette;
CONSOLE_GETCONSOLEWINDOW_MSG64 GetConsoleWindow;
#else
CONSOLE_REGISTERVDM_MSG RegisterConsoleVDM;
CONSOLE_SETCURSOR_MSG SetConsoleCursor;
CONSOLE_SETICON_MSG SetConsoleIcon;
CONSOLE_MENUCONTROL_MSG ConsoleMenuControl;
CONSOLE_SETPALETTE_MSG SetConsolePalette;
CONSOLE_GETCONSOLEWINDOW_MSG GetConsoleWindow;
#endif
CONSOLE_GETHARDWARESTATE_MSG GetConsoleHardwareState;
CONSOLE_SETHARDWARESTATE_MSG SetConsoleHardwareState;
CONSOLE_GETDISPLAYMODE_MSG GetConsoleDisplayMode;
CONSOLE_ADDALIAS_MSG AddConsoleAliasW;
CONSOLE_GETALIAS_MSG GetConsoleAliasW;
CONSOLE_GETALIASESLENGTH_MSG GetConsoleAliasesLengthW;
CONSOLE_GETALIASEXESLENGTH_MSG GetConsoleAliasExesLengthW;
CONSOLE_GETALIASES_MSG GetConsoleAliasesW;
CONSOLE_GETALIASEXES_MSG GetConsoleAliasExesW;
CONSOLE_EXPUNGECOMMANDHISTORY_MSG ExpungeConsoleCommandHistoryW;
CONSOLE_SETNUMBEROFCOMMANDS_MSG SetConsoleNumberOfCommandsW;
CONSOLE_GETCOMMANDHISTORYLENGTH_MSG GetConsoleCommandHistoryLengthW;
CONSOLE_GETCOMMANDHISTORY_MSG GetConsoleCommandHistoryW;
CONSOLE_SETKEYSHORTCUTS_MSG SetConsoleKeyShortcuts;
CONSOLE_SETMENUCLOSE_MSG SetConsoleMenuClose;
CONSOLE_GETKEYBOARDLAYOUTNAME_MSG GetKeyboardLayoutName;
CONSOLE_CHAR_TYPE_MSG GetConsoleCharType;
CONSOLE_LOCAL_EUDC_MSG SetConsoleLocalEUDC;
CONSOLE_CURSOR_MODE_MSG SetConsoleCursorMode;
CONSOLE_CURSOR_MODE_MSG GetConsoleCursorMode;
CONSOLE_REGISTEROS2_MSG RegisterConsoleOS2;
CONSOLE_SETOS2OEMFORMAT_MSG SetConsoleOS2OemFormat;
CONSOLE_NLS_MODE_MSG GetConsoleNlsMode;
CONSOLE_NLS_MODE_MSG SetConsoleNlsMode;
CONSOLE_GETSELECTIONINFO_MSG GetConsoleSelectionInfo;
CONSOLE_GETCONSOLEPROCESSLIST_MSG GetConsoleProcessList;
CONSOLE_CURRENTFONT_MSG SetCurrentConsoleFont;
CONSOLE_HISTORY_MSG SetConsoleHistory;
CONSOLE_HISTORY_MSG GetConsoleHistory;
} CONSOLE_MSG_BODY_L3, *PCONSOLE_MSG_BODY_L3;
#ifndef __cplusplus
typedef struct _CONSOLE_MSG_L3 {
CONSOLE_MSG_HEADER Header;
union {
CONSOLE_MSG_BODY_L3;
} u;
} CONSOLE_MSG_L3, *PCONSOLE_MSG_L3;
#else
typedef struct _CONSOLE_MSG_L3 :
public CONSOLE_MSG_HEADER
{
CONSOLE_MSG_BODY_L3 u;
} CONSOLE_MSG_L3, *PCONSOLE_MSG_L3;
#endif // __cplusplus

29
dep/Console/ntcon.h Normal file
View File

@ -0,0 +1,29 @@
//
// Copyright (C) Microsoft. All rights reserved.
//
#ifndef _NTCON_
#define _NTCON_
//
// originally in winconp.h
//
#define CONSOLE_DETACHED_PROCESS ((HANDLE)-1)
#define CONSOLE_NEW_CONSOLE ((HANDLE)-2)
#define CONSOLE_CREATE_NO_WINDOW ((HANDLE)-3)
#define SYSTEM_ROOT_CONSOLE_EVENT 3
#define CONSOLE_READ_NOREMOVE 0x0001
#define CONSOLE_READ_NOWAIT 0x0002
#define CONSOLE_READ_VALID (CONSOLE_READ_NOREMOVE | CONSOLE_READ_NOWAIT)
#define CONSOLE_GRAPHICS_BUFFER 2
//
// These are flags stored in PEB::ProcessParameters::ConsoleFlags.
//
#define CONSOLE_IGNORE_CTRL_C 0x1
#endif //_NTCON_

669
dep/Console/winconp.h Normal file
View File

@ -0,0 +1,669 @@
#ifndef _WINCONP_
#define _WINCONP_
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#if _MSC_VER >= 1200
#pragma warning(push)
#pragma warning(disable:4820) // padding added after data member
#endif
#include <wincontypes.h>
//
// History flags (internal)
//
#define CHI_VALID_FLAGS (HISTORY_NO_DUP_FLAG)
//
// Selection flags (internal)
//
#define CONSOLE_SELECTION_INVERTED 0x0010 // selection is inverted (turned off)
#define CONSOLE_SELECTION_VALID (CONSOLE_SELECTION_IN_PROGRESS | \
CONSOLE_SELECTION_NOT_EMPTY | \
CONSOLE_MOUSE_SELECTION | \
CONSOLE_MOUSE_DOWN)
WINBASEAPI
BOOL
WINAPI
GetConsoleKeyboardLayoutNameA(
_Out_writes_(KL_NAMELENGTH) LPSTR pszLayout);
WINBASEAPI
BOOL
WINAPI
GetConsoleKeyboardLayoutNameW(
_Out_writes_(KL_NAMELENGTH) LPWSTR pszLayout);
#ifdef UNICODE
#define GetConsoleKeyboardLayoutName GetConsoleKeyboardLayoutNameW
#else
#define GetConsoleKeyboardLayoutName GetConsoleKeyboardLayoutNameA
#endif // !UNICODE
//
// Registry strings
//
#define CONSOLE_REGISTRY_STRING L"Console"
#define CONSOLE_REGISTRY_FONTSIZE L"FontSize"
#define CONSOLE_REGISTRY_FONTFAMILY L"FontFamily"
#define CONSOLE_REGISTRY_BUFFERSIZE L"ScreenBufferSize"
#define CONSOLE_REGISTRY_CURSORSIZE L"CursorSize"
#define CONSOLE_REGISTRY_WINDOWMAXIMIZED L"WindowMaximized"
#define CONSOLE_REGISTRY_WINDOWSIZE L"WindowSize"
#define CONSOLE_REGISTRY_WINDOWPOS L"WindowPosition"
#define CONSOLE_REGISTRY_WINDOWALPHA L"WindowAlpha"
#define CONSOLE_REGISTRY_FILLATTR L"ScreenColors"
#define CONSOLE_REGISTRY_POPUPATTR L"PopupColors"
#define CONSOLE_REGISTRY_FULLSCR L"FullScreen"
#define CONSOLE_REGISTRY_QUICKEDIT L"QuickEdit"
#define CONSOLE_REGISTRY_FACENAME L"FaceName"
#define CONSOLE_REGISTRY_FONTWEIGHT L"FontWeight"
#define CONSOLE_REGISTRY_INSERTMODE L"InsertMode"
#define CONSOLE_REGISTRY_HISTORYSIZE L"HistoryBufferSize"
#define CONSOLE_REGISTRY_HISTORYBUFS L"NumberOfHistoryBuffers"
#define CONSOLE_REGISTRY_HISTORYNODUP L"HistoryNoDup"
#define CONSOLE_REGISTRY_COLORTABLE L"ColorTable%02u"
#define CONSOLE_REGISTRY_EXTENDEDEDITKEY L"ExtendedEditKey"
#define CONSOLE_REGISTRY_EXTENDEDEDITKEY_CUSTOM L"ExtendedEditkeyCustom"
#define CONSOLE_REGISTRY_WORD_DELIM L"WordDelimiters"
#define CONSOLE_REGISTRY_TRIMZEROHEADINGS L"TrimLeadingZeros"
#define CONSOLE_REGISTRY_LOAD_CONIME L"LoadConIme"
#define CONSOLE_REGISTRY_ENABLE_COLOR_SELECTION L"EnableColorSelection"
#define CONSOLE_REGISTRY_SCROLLSCALE L"ScrollScale"
// V2 console settings
#define CONSOLE_REGISTRY_FORCEV2 L"ForceV2"
#define CONSOLE_REGISTRY_LINESELECTION L"LineSelection"
#define CONSOLE_REGISTRY_FILTERONPASTE L"FilterOnPaste"
#define CONSOLE_REGISTRY_LINEWRAP L"LineWrap"
#define CONSOLE_REGISTRY_CTRLKEYSHORTCUTS_DISABLED L"CtrlKeyShortcutsDisabled"
#define CONSOLE_REGISTRY_ALLOW_ALTF4_CLOSE L"AllowAltF4Close"
#define CONSOLE_REGISTRY_VIRTTERM_LEVEL L"VirtualTerminalLevel"
#define CONSOLE_REGISTRY_CURSORTYPE L"CursorType"
#define CONSOLE_REGISTRY_CURSORCOLOR L"CursorColor"
#define CONSOLE_REGISTRY_INTERCEPTCOPYPASTE L"InterceptCopyPaste"
#define CONSOLE_REGISTRY_COPYCOLOR L"CopyColor"
#define CONSOLE_REGISTRY_USEDX L"UseDx"
#define CONSOLE_REGISTRY_DEFAULTFOREGROUND L"DefaultForeground"
#define CONSOLE_REGISTRY_DEFAULTBACKGROUND L"DefaultBackground"
#define CONSOLE_REGISTRY_TERMINALSCROLLING L"TerminalScrolling"
// end V2 console settings
/*
* Starting code page
*/
#define CONSOLE_REGISTRY_CODEPAGE (L"CodePage")
//
// registry strings on HKEY_LOCAL_MACHINE
//
#define MACHINE_REGISTRY_CONSOLE (L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Console")
#define MACHINE_REGISTRY_CONSOLEIME (L"ConsoleIME")
#define MACHINE_REGISTRY_ENABLE_CONIME_ON_SYSTEM_PROCESS (L"EnableConImeOnSystemProcess")
#define MACHINE_REGISTRY_CONSOLE_TTFONT (L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont")
#define MACHINE_REGISTRY_CONSOLE_TTFONT_WIN32_PATH (L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont")
#define MACHINE_REGISTRY_CONSOLE_NLS (L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\Nls")
#define MACHINE_REGISTRY_CONSOLE_FULLSCREEN (L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\FullScreen")
#define MACHINE_REGISTRY_INITIAL_PALETTE (L"InitialPalette")
#define MACHINE_REGISTRY_COLOR_BUFFER (L"ColorBuffer")
#define MACHINE_REGISTRY_COLOR_BUFFER_NO_TRANSLATE (L"ColorBufferNoTranslate")
#define MACHINE_REGISTRY_MODE_FONT_PAIRS (L"ModeFontPairs")
#define MACHINE_REGISTRY_FS_CODEPAGE (L"CodePage")
#define MACHINE_REGISTRY_EUDC (L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Nls\\CodePage\\EUDCCodeRange")
//
// TrueType font list
//
// doesn't available bold when add BOLD_MARK on first of face name.
#define BOLD_MARK (L'*')
typedef struct _TT_FONT_LIST {
SINGLE_LIST_ENTRY List;
UINT CodePage;
BOOL fDisableBold;
TCHAR FaceName1[LF_FACESIZE];
TCHAR FaceName2[LF_FACESIZE];
} TTFONTLIST, *LPTTFONTLIST;
//
// registry strings on HKEY_CURRENT_USER
//
#define PRELOAD_REGISTRY_STRING (L"Keyboard Layout\\Preload")
//
// Special key for previous word erase
//
#define EXTKEY_ERASE_PREV_WORD (0x7f)
#ifndef NOGDI
typedef struct _CONSOLE_GRAPHICS_BUFFER_INFO {
DWORD dwBitMapInfoLength;
LPBITMAPINFO lpBitMapInfo;
DWORD dwUsage;
HANDLE hMutex;
PVOID lpBitMap;
} CONSOLE_GRAPHICS_BUFFER_INFO, *PCONSOLE_GRAPHICS_BUFFER_INFO;
#endif
BOOL
WINAPI
InvalidateConsoleDIBits(
_In_ HANDLE hConsoleOutput,
_In_ PSMALL_RECT lpRect);
VOID
WINAPI
SetLastConsoleEventActive(
VOID);
#define VDM_HIDE_WINDOW 1
#define VDM_IS_ICONIC 2
#define VDM_CLIENT_RECT 3
#define VDM_CLIENT_TO_SCREEN 4
#define VDM_SCREEN_TO_CLIENT 5
#define VDM_IS_HIDDEN 6
#define VDM_FULLSCREEN_NOPAINT 7
#define VDM_SET_VIDEO_MODE 8
BOOL
WINAPI
VDMConsoleOperation(
_In_ DWORD iFunction,
_Inout_opt_ LPVOID lpData);
BOOL
WINAPI
SetConsoleIcon(
_In_ HICON hIcon);
//
// These console font APIs don't appear to be used anywhere. Maybe they
// should be removed.
//
BOOL
WINAPI
SetConsoleFont(
_In_ HANDLE hConsoleOutput,
_In_ DWORD nFont);
DWORD
WINAPI
GetConsoleFontInfo(
_In_ HANDLE hConsoleOutput,
_In_ BOOL bMaximumWindow,
_In_ DWORD nLength,
_Out_ PCONSOLE_FONT_INFO lpConsoleFontInfo);
DWORD
WINAPI
GetNumberOfConsoleFonts(
VOID);
BOOL
WINAPI
SetConsoleCursor(
_In_ HANDLE hConsoleOutput,
_In_ HCURSOR hCursor);
int
WINAPI
ShowConsoleCursor(
_In_ HANDLE hConsoleOutput,
_In_ BOOL bShow);
HMENU
APIENTRY
ConsoleMenuControl(
_In_ HANDLE hConsoleOutput,
_In_ UINT dwCommandIdLow,
_In_ UINT dwCommandIdHigh);
BOOL
SetConsolePalette(
_In_ HANDLE hConsoleOutput,
_In_ HPALETTE hPalette,
_In_ UINT dwUsage);
#define CONSOLE_UNREGISTER_VDM 0
#define CONSOLE_REGISTER_VDM 1
#define CONSOLE_REGISTER_WOW 2
BOOL
APIENTRY
RegisterConsoleVDM(
_In_ DWORD dwRegisterFlags,
_In_ HANDLE hStartHardwareEvent,
_In_ HANDLE hEndHardwareEvent,
_In_ HANDLE hErrorhardwareEvent,
_Reserved_ DWORD Reserved,
_Out_ LPDWORD lpStateLength,
_Outptr_ PVOID *lpState,
_In_opt_ COORD VDMBufferSize,
_Outptr_ PVOID *lpVDMBuffer);
BOOL
APIENTRY
GetConsoleHardwareState(
_In_ HANDLE hConsoleOutput,
_Out_ PCOORD lpResolution,
_Out_ PCOORD lpFontSize);
BOOL
APIENTRY
SetConsoleHardwareState(
_In_ HANDLE hConsoleOutput,
_In_ COORD dwResolution,
_In_ COORD dwFontSize);
#define CONSOLE_NOSHORTCUTKEY 0x00000000 /* no shortcut key */
#define CONSOLE_ALTTAB 0x00000001 /* Alt + Tab */
#define CONSOLE_ALTESC 0x00000002 /* Alt + Escape */
#define CONSOLE_ALTSPACE 0x00000004 /* Alt + Space */
#define CONSOLE_ALTENTER 0x00000008 /* Alt + Enter */
#define CONSOLE_ALTPRTSC 0x00000010 /* Alt Print screen */
#define CONSOLE_PRTSC 0x00000020 /* Print screen */
#define CONSOLE_CTRLESC 0x00000040 /* Ctrl + Escape */
typedef struct _APPKEY {
WORD Modifier;
WORD ScanCode;
} APPKEY, *LPAPPKEY;
#define CONSOLE_MODIFIER_SHIFT 0x0003 // Left shift key
#define CONSOLE_MODIFIER_CONTROL 0x0004 // Either Control shift key
#define CONSOLE_MODIFIER_ALT 0x0008 // Either Alt shift key
BOOL
APIENTRY
SetConsoleKeyShortcuts(
_In_ BOOL bSet,
_In_ BYTE bReserveKeys,
_In_reads_(dwNumAppKeys) LPAPPKEY lpAppKeys,
_In_ DWORD dwNumAppKeys);
BOOL
APIENTRY
SetConsoleMenuClose(
_In_ BOOL bEnable);
DWORD
GetConsoleInputExeNameA(
_In_ DWORD nBufferLength,
_Out_writes_(nBufferLength) LPSTR lpBuffer);
DWORD
GetConsoleInputExeNameW(
_In_ DWORD nBufferLength,
_Out_writes_(nBufferLength) LPWSTR lpBuffer);
#ifdef UNICODE
#define GetConsoleInputExeName GetConsoleInputExeNameW
#else
#define GetConsoleInputExeName GetConsoleInputExeNameA
#endif // !UNICODE
BOOL
SetConsoleInputExeNameA(
_In_ LPSTR lpExeName);
BOOL
SetConsoleInputExeNameW(
_In_ LPWSTR lpExeName);
#ifdef UNICODE
#define SetConsoleInputExeName SetConsoleInputExeNameW
#else
#define SetConsoleInputExeName SetConsoleInputExeNameA
#endif // !UNICODE
BOOL
WINAPI
ReadConsoleInputExA(
_In_ HANDLE hConsoleInput,
_Out_writes_(nLength) PINPUT_RECORD lpBuffer,
_In_ DWORD nLength,
_Out_ LPDWORD lpNumberOfEventsRead,
_In_ USHORT wFlags);
BOOL
WINAPI
ReadConsoleInputExW(
_In_ HANDLE hConsoleInput,
_Out_writes_(nLength) PINPUT_RECORD lpBuffer,
_In_ DWORD nLength,
_Out_ LPDWORD lpNumberOfEventsRead,
_In_ USHORT wFlags);
#ifdef UNICODE
#define ReadConsoleInputEx ReadConsoleInputExW
#else
#define ReadConsoleInputEx ReadConsoleInputExA
#endif // !UNICODE
BOOL
WINAPI
WriteConsoleInputVDMA(
_In_ HANDLE hConsoleInput,
_In_reads_(nLength) PINPUT_RECORD lpBuffer,
_In_ DWORD nLength,
_Out_ LPDWORD lpNumberOfEventsWritten);
BOOL
WINAPI
WriteConsoleInputVDMW(
_In_ HANDLE hConsoleInput,
_In_reads_(nLength) PINPUT_RECORD lpBuffer,
_In_ DWORD nLength,
_Out_ LPDWORD lpNumberOfEventsWritten);
#ifdef UNICODE
#define WriteConsoleInputVDM WriteConsoleInputVDMW
#else
#define WriteConsoleInputVDM WriteConsoleInputVDMA
#endif // !UNICODE
BOOL
APIENTRY
GetConsoleNlsMode(
_In_ HANDLE hConsole,
_Out_ PDWORD lpdwNlsMode);
BOOL
APIENTRY
SetConsoleNlsMode(
_In_ HANDLE hConsole,
_In_ DWORD fdwNlsMode);
BOOL
APIENTRY
GetConsoleCharType(
_In_ HANDLE hConsole,
_In_ COORD coordCheck,
_Out_ PDWORD pdwType);
#define CHAR_TYPE_SBCS 0 // Displayed SBCS character
#define CHAR_TYPE_LEADING 2 // Displayed leading byte of DBCS
#define CHAR_TYPE_TRAILING 3 // Displayed trailing byte of DBCS
BOOL
APIENTRY
SetConsoleLocalEUDC(
_In_ HANDLE hConsoleHandle,
_In_ WORD wCodePoint,
_In_ COORD cFontSize,
_In_ PCHAR lpSB);
BOOL
APIENTRY
SetConsoleCursorMode(
_In_ HANDLE hConsoleHandle,
_In_ BOOL Blink,
_In_ BOOL DBEnable);
BOOL
APIENTRY
GetConsoleCursorMode(
_In_ HANDLE hConsoleHandle,
_Out_ PBOOL pbBlink,
_Out_ PBOOL pbDBEnable);
BOOL
APIENTRY
RegisterConsoleOS2(
_In_ BOOL fOs2Register);
BOOL
APIENTRY
SetConsoleOS2OemFormat(
_In_ BOOL fOs2OemFormat);
BOOL
IsConsoleFullWidth(
_In_ HDC hDC,
_In_ DWORD CodePage,
_In_ WCHAR wch);
#if defined(FE_IME)
BOOL
APIENTRY
RegisterConsoleIME(
_In_ HWND hWndConsoleIME,
_Out_opt_ DWORD *lpdwConsoleThreadId);
BOOL
APIENTRY
UnregisterConsoleIME(
VOID);
#endif // FE_IME
//
// These bits are always on for console handles and are used for routing
// by windows.
//
#define CONSOLE_HANDLE_SIGNATURE 0x00000003
#define CONSOLE_HANDLE_NEVERSET 0x10000000
#define CONSOLE_HANDLE_MASK (CONSOLE_HANDLE_SIGNATURE | CONSOLE_HANDLE_NEVERSET)
#define CONSOLE_HANDLE(HANDLE) (((ULONG_PTR)(HANDLE) & CONSOLE_HANDLE_MASK) == CONSOLE_HANDLE_SIGNATURE)
//
// These strings are used to open console input or output.
//
#define CONSOLE_INPUT_STRING L"CONIN$"
#define CONSOLE_OUTPUT_STRING L"CONOUT$"
#define CONSOLE_GENERIC L"CON"
//
// this string is used to call RegisterWindowMessage to get
// progman's handle.
//
#define CONSOLE_PROGMAN_HANDLE_MESSAGE "ConsoleProgmanHandle"
//
// stream API definitions. these API are only supposed to be used by
// subsystems (i.e. OpenFile routes to OpenConsoleW).
//
HANDLE
APIENTRY
OpenConsoleW(
_In_ LPWSTR lpConsoleDevice,
_In_ DWORD dwDesiredAccess,
_In_ BOOL bInheritHandle,
_In_ DWORD dwShareMode);
HANDLE
APIENTRY
DuplicateConsoleHandle(
_In_ HANDLE hSourceHandle,
_In_ DWORD dwDesiredAccess,
_In_ BOOL bInheritHandle,
_In_ DWORD dwOptions);
BOOL
APIENTRY
GetConsoleHandleInformation(
_In_ HANDLE hObject,
_Out_ LPDWORD lpdwFlags);
BOOL
APIENTRY
SetConsoleHandleInformation(
_In_ HANDLE hObject,
_In_ DWORD dwMask,
_In_ DWORD dwFlags);
BOOL
APIENTRY
CloseConsoleHandle(
_In_ HANDLE hConsole);
BOOL
APIENTRY
VerifyConsoleIoHandle(
_In_ HANDLE hIoHandle);
HANDLE
APIENTRY
GetConsoleInputWaitHandle(
VOID);
typedef struct _CONSOLE_STATE_INFO {
/* BEGIN V1 CONSOLE_STATE_INFO */
COORD ScreenBufferSize;
COORD WindowSize;
INT WindowPosX;
INT WindowPosY;
COORD FontSize;
UINT FontFamily;
UINT FontWeight;
WCHAR FaceName[LF_FACESIZE];
UINT CursorSize;
UINT FullScreen : 1;
UINT QuickEdit : 1;
UINT AutoPosition : 1;
UINT InsertMode : 1;
UINT HistoryNoDup : 1;
UINT FullScreenSupported : 1;
UINT UpdateValues : 1;
UINT Defaults : 1;
WORD ScreenAttributes;
WORD PopupAttributes;
UINT HistoryBufferSize;
UINT NumberOfHistoryBuffers;
COLORREF ColorTable[16];
HWND hWnd;
HICON hIcon;
LPWSTR OriginalTitle;
LPWSTR LinkTitle;
/*
* Starting code page
*/
UINT CodePage;
/* END V1 CONSOLE_STATE_INFO */
/* BEGIN V2 CONSOLE_STATE_INFO */
BOOL fIsV2Console;
BOOL fWrapText;
BOOL fFilterOnPaste;
BOOL fCtrlKeyShortcutsDisabled;
BOOL fLineSelection;
BYTE bWindowTransparency;
BOOL fWindowMaximized;
unsigned int CursorType;
COLORREF CursorColor;
BOOL InterceptCopyPaste;
COLORREF DefaultForeground;
COLORREF DefaultBackground;
BOOL TerminalScrolling;
/* END V2 CONSOLE_STATE_INFO */
} CONSOLE_STATE_INFO, *PCONSOLE_STATE_INFO;
#ifdef DEFINE_CONSOLEV2_PROPERTIES
#define PID_CONSOLE_FORCEV2 1
#define PID_CONSOLE_WRAPTEXT 2
#define PID_CONSOLE_FILTERONPASTE 3
#define PID_CONSOLE_CTRLKEYSDISABLED 4
#define PID_CONSOLE_LINESELECTION 5
#define PID_CONSOLE_WINDOWTRANSPARENCY 6
#define PID_CONSOLE_WINDOWMAXIMIZED 7
#define PID_CONSOLE_CURSOR_TYPE 8
#define PID_CONSOLE_CURSOR_COLOR 9
#define PID_CONSOLE_INTERCEPT_COPY_PASTE 10
#define PID_CONSOLE_DEFAULTFOREGROUND 11
#define PID_CONSOLE_DEFAULTBACKGROUND 12
#define PID_CONSOLE_TERMINALSCROLLING 13
#define CONSOLE_PROPKEY(name, id) \
DEFINE_PROPERTYKEY(name, 0x0C570607, 0x0396, 0x43DE, 0x9D, 0x61, 0xE3, 0x21, 0xD7, 0xDF, 0x50, 0x26, id);
CONSOLE_PROPKEY(PKEY_Console_ForceV2, PID_CONSOLE_FORCEV2);
CONSOLE_PROPKEY(PKEY_Console_WrapText, PID_CONSOLE_WRAPTEXT);
CONSOLE_PROPKEY(PKEY_Console_FilterOnPaste, PID_CONSOLE_FILTERONPASTE);
CONSOLE_PROPKEY(PKEY_Console_CtrlKeyShortcutsDisabled, PID_CONSOLE_CTRLKEYSDISABLED);
CONSOLE_PROPKEY(PKEY_Console_LineSelection, PID_CONSOLE_LINESELECTION);
CONSOLE_PROPKEY(PKEY_Console_WindowTransparency, PID_CONSOLE_WINDOWTRANSPARENCY);
CONSOLE_PROPKEY(PKEY_Console_WindowMaximized, PID_CONSOLE_WINDOWMAXIMIZED);
CONSOLE_PROPKEY(PKEY_Console_CursorType, PID_CONSOLE_CURSOR_TYPE);
CONSOLE_PROPKEY(PKEY_Console_CursorColor, PID_CONSOLE_CURSOR_COLOR);
CONSOLE_PROPKEY(PKEY_Console_InterceptCopyPaste, PID_CONSOLE_INTERCEPT_COPY_PASTE);
CONSOLE_PROPKEY(PKEY_Console_DefaultForeground, PID_CONSOLE_DEFAULTFOREGROUND);
CONSOLE_PROPKEY(PKEY_Console_DefaultBackground, PID_CONSOLE_DEFAULTBACKGROUND);
CONSOLE_PROPKEY(PKEY_Console_TerminalScrolling, PID_CONSOLE_TERMINALSCROLLING);
#endif
//
// Ensure the alignment is WORD boundary
//
#include <pshpack2.h>
typedef struct {
WORD wMod;
WORD wVirKey;
WCHAR wUnicodeChar;
} ExtKeySubst;
typedef struct {
ExtKeySubst keys[3]; // 0: Ctrl
// 1: Alt
// 2: Ctrl+Alt
} ExtKeyDef;
typedef ExtKeyDef ExtKeyDefTable['Z' - 'A' + 1];
typedef struct {
DWORD dwVersion;
DWORD dwCheckSum;
ExtKeyDefTable table;
} ExtKeyDefBuf;
//
// Restore the previous alignment
//
#include <poppack.h>
#if _MSC_VER >= 1200
#pragma warning(pop)
#endif
#ifdef __cplusplus
}
#endif
#endif // _WINCONP_

3
dep/NT/ntioapi_x.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020

12
dep/Win32K/winuserp.h Normal file
View File

@ -0,0 +1,12 @@
/*
* Reserved console space.
*
* This was moved from the console code so that we can localize it
* in one place. This was necessary for dealing with the background
* color, which we need to have for the hungapp drawing. These are
* stored in the extra-window-bytes of each console.
*/
#define GWL_CONSOLE_WNDALLOC (3 * sizeof(DWORD))
#define GWL_CONSOLE_PID 0
#define GWL_CONSOLE_TID 4
#define GWL_CONSOLE_BKCOLOR 8

96
dep/WinAppDriver/EULA.rtf Normal file
View File

@ -0,0 +1,96 @@
{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Tahoma;}{\f1\fswiss\fprq2\fcharset0 Arial;}{\f2\fnil\fcharset0 Calibri;}}
{\colortbl ;\red0\green0\blue255;}
{\stylesheet{ Normal;}{\s1 heading 1;}{\s2 heading 2;}}
{\*\generator Riched20 10.0.10586}\viewkind4\uc1
\pard\widctlpar\sb120\sa120\b\f0\fs28 MICROSOFT SOFTWARE LICENSE TERMS\par
\pard\brdrb\brdrs\brdrw10\brsp20 \widctlpar\sb120\sa120 Pre-Release and Evaluation EULA \endash Windows Application Driver\par
\pard\widctlpar\sb120\sa120\b0\fs20 IF YOU LIVE IN (OR ARE A BUSINESS WITH YOUR PRINCIPAL PLACE OF BUSINESS IN) THE UNITED STATES, PLEASE READ THE \ldblquote BINDING ARBITRATION AND CLASS ACTION WAIVER\rdblquote SECTION BELOW. IT AFFECTS HOW DISPUTES ARE RESOLVED.\lang9\par
\pard\brdrt\brdrs\brdrw10\brsp20 \widctlpar\sb120\sa120 These license terms are an agreement between you and Microsoft Corporation (or one of its affiliates). They apply to the software named above and any Microsoft services or software updates (except to the extent such services or updates are accompanied by new or \lang1033 additional terms, in which case those different terms apply prospectively and do not alter your or Microsoft\rquote s rights relating to pre-updated software or services\lang9 ). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU HAVE THE RIGHTS BELOW.\par
\pard
{\pntext\f0 1.\tab}{\*\pn\pnlvlbody\pnf0\pnindent360\pnstart1\pndec{\pntxta.}}
\widctlpar\s1\fi-357\li357\sb120\sa120\b\lang1033 INSTALLATION AND USE RIGHTS.\par
\pard
{\pntext\f0 a)\tab}{\*\pn\pnlvlbody\pnf0\pnindent0\pnstart1\pnlcltr{\pntxta)}}
\widctlpar\s2\fi-360\li717\sb120\sa120 General. \b0 You may install and use any number of copies of the software on your devices, solely to i) evaluate for internal business purposes; and ii) design, develop and test your applications. \par
{\pntext\f0 b)\tab}\b Included Microsoft Applications. \b0 The software may include other Microsoft applications. These license terms apply to those included applications, if any, unless other license terms are provided with the other Microsoft applications.\par
{\pntext\f0 c)\tab}\b Third Party Applications. \b0 The software may include third party applications that Microsoft, not the third party, licenses to you under this agreement. Any included notices for third party applications are for your information only and are listed in Exhibit A to these license terms.\par
{\pntext\f0 d)\tab}\b No Distribution Rights. \b0 This agreement does not grant you a license to distribute nor sublicense all or part of the software to any third party.\par
{\pntext\f0 e)\tab}\b\lang9 Package Managers. \b0\lang1033 The software may include package managers, like NuGet, that give you the option to download other Microsoft and third party software packages to use with your application. Those packages are under their own licenses, and not this agreement. Microsoft does not distribute, license or provide any warranties for any of the third party packages\lang9 .\lang1033\par
\pard\widctlpar\s1\fi-357\li357\sb120\sa120\b 2.\tab TIME-SENSITIVE SOFTWARE.\par
\pard
{\pntext\f0 a)\tab}{\*\pn\pnlvlbody\pnf0\pnindent0\pnstart1\pnlcltr{\pntxta)}}
\widctlpar\s2\fi-360\li717\sb120\sa120 Period. \b0 The software is time-sensitive and may stop running on a date that is defined in the software.\par
{\pntext\f0 b)\tab}\b Notice. \b0 You may receive periodic reminder notices of this date through the software.\par
{\pntext\f0 c)\tab}\b Access to data. \b0 You may not be able to access data used in the software when it stops running.\par
\pard\widctlpar\s1\fi-357\li357\sb120\sa120\b 3.\tab PRE-RELEASE SOFTWARE.\b0 The software is a pre-release version. It may not operate correctly. It may be different from the commercially released version.\par
\b 4.\tab FEEDBACK.\b0 If you give feedback about the software to Microsoft, you give to Microsoft, without charge, the right to use, share and commercialize your feedback in any way and for any purpose. You will not give feedback that is subject to a license that requires Microsoft to license its software or documentation to third parties because Microsoft includes your feedback in them. These rights survive this agreement.\par
\b 5.\tab DATA.\b0 The software may collect information about you and your use of the software and send that to Microsoft. Microsoft may use this information to provide services and improve Microsoft\rquote s products and services. Your opt-out rights, if any, are described in\b \b0 the product documentation. Some features in the software may enable collection of data from users of your applications that access or use the software. If you use these features to enable data collection in your applications, you must comply with applicable law, including getting any required user consent, and maintain a prominent privacy policy that accurately informs users about how you use, collect, and share their data. You can learn more about Microsoft\rquote s data collection and use in the product documentation and the Microsoft Privacy Statement at {{\field{\*\fldinst{HYPERLINK http://go.microsoft.com/fwlink/?LinkID=521839 }}{\fldrslt{http://go.microsoft.com/fwlink/?LinkID=521839\ul0\cf0}}}}\f0\fs20 . You agree to comply with all applicable provisions of the Microsoft Privacy Statement.\par
\b 6.\tab SCOPE OF LICENSE.\b0 The software is licensed, not sold. Microsoft reserves all other rights. Unless applicable law gives you more rights despite this limitation, you will not (and have no right to):\par
\pard
{\pntext\f0 a)\tab}{\*\pn\pnlvlbody\pnf0\pnindent0\pnstart1\pnlcltr{\pntxta)}}
\widctlpar\s2\fi-360\li717\sb120\sa120 work around any technical limitations in the software that only allow you to use it in certain ways;\par
{\pntext\f0 b)\tab}reverse engineer, decompile or disassemble the software;\par
{\pntext\f0 c)\tab}remove, minimize, block, or modify any notices of Microsoft or its suppliers in the software;\par
{\pntext\f0 d)\tab}use the software in any way that is against the law or to create or propagate malware; or\par
{\pntext\f0 e)\tab}share, publish, or lend the software (except for any distributable code, and then subject to the applicable terms above), provide the software as a stand-alone hosted solution for others to use, or transfer the software or this agreement to any third party.\par
\pard\widctlpar\s1\fi-357\li357\sb120\sa120\b 7.\tab EXPORT RESTRICTIONS.\b0 You must comply with all domestic and international export laws and regulations that apply to the software, which include restrictions on destinations, end users, and end use. For further information on export restrictions, visit (aka.ms/exporting).\par
\b 8.\tab SUPPORT SERVICES.\b0 Microsoft is not obligated under this agreement to provide any support services for the software. Any support provided is \ldblquote as is\rdblquote , \ldblquote with all faults\rdblquote , and without warranty of any kind.\par
\b 9.\tab UPDATES.\b0 The software may periodically check for updates, and download and install them for you. You may obtain updates only from Microsoft or authorized sources. Microsoft may need to update your system to provide you with updates. You agree to receive these automatic updates without any additional notice. Updates may not include or support all existing software features, services, or peripheral devices.\par
\b 10.\tab BINDING ARBITRATION AND CLASS ACTION WAIVER.\b0 This Section applies if you live in (or, if a business, your principal place of business is in) the United States. If you and Microsoft have a dispute, you and Microsoft agree to try for 60 days to resolve it informally. If you and Microsoft can\rquote t, you and Microsoft agree to binding individual arbitration before the American Arbitration Association under the Federal Arbitration Act (\ldblquote FAA\rdblquote ), and not to sue in court in front of a judge or jury. Instead, a neutral arbitrator will decide. Class action lawsuits, class-wide arbitrations, private attorney-general actions, and any other proceeding where someone acts in a representative capacity are not allowed; nor is combining individual proceedings without the consent of all parties. The complete Arbitration Agreement contains more terms and is at aka.ms/arb-agreement-1. You and Microsoft agree to these terms.\par
\b 11.\tab ENTIRE AGREEMENT.\b0 This agreement, and any other terms Microsoft may provide for supplements, updates, or third-party applications, is the entire agreement for the software.\par
\b 12.\tab APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES.\b0 If you acquired the software in the United States or Canada, the laws of the state or province where you live (or, if a business, where your principal place of business is located) govern the interpretation of this agreement, claims for its breach, and all other claims (including consumer protection, unfair competition, and tort claims), regardless of conflict of laws principles, except that the FAA governs everything related to arbitration. If you acquired the software in any other country, its laws apply, except that the FAA governs everything related to arbitration. If U.S. federal jurisdiction exists, you and Microsoft consent to exclusive jurisdiction and venue in the federal court in King County, Washington for all disputes heard in court (excluding arbitration). If not, you and Microsoft consent to exclusive jurisdiction and venue in the Superior Court of King County, Washington for all disputes heard in court (excluding arbitration).\par
\b 13.\tab CONSUMER RIGHTS; REGIONAL VARIATIONS\b0 . This agreement describes certain legal rights. You may have other rights, including consumer rights, under the laws of your state, province, or country. Separate and apart from your relationship with Microsoft, you may also have rights with respect to the party from which you acquired the software. This agreement does not change those other rights if the laws of your state, province, or country do not permit it to do so. For example, if you acquired the software in one of the below regions, or mandatory country law applies, then the following provisions apply to you:\par
\pard
{\pntext\f0 a)\tab}{\*\pn\pnlvlbody\pnf0\pnindent0\pnstart1\pnlcltr{\pntxta)}}
\widctlpar\s2\fi-360\li717\sb120\sa120\b Australia.\b0 You have statutory guarantees under the Australian Consumer Law and nothing in this agreement is intended to affect those rights.\par
{\pntext\f0 b)\tab}\b Canada.\b0 If you acquired this software in Canada, you may stop receiving updates by turning off the automatic update feature, disconnecting your device from the Internet (if and when you re-connect to the Internet, however, the software will resume checking for and installing updates), or uninstalling the software. The product documentation, if any, may also specify how to turn off updates for your specific device or software.\par
{\pntext\f0 c)\tab}\b Germany and Austria\b0 .\par
\pard\widctlpar\li717\sb120\sa120\b (i)\b0\tab\b Warranty.\b0 The properly licensed software will perform substantially as described in any Microsoft materials that accompany the software. However, Microsoft gives no contractual guarantee in relation to the licensed software.\par
\b (ii)\b0\tab\b Limitation of Liability\b0 . In case of intentional conduct, gross negligence, claims based on the Product Liability Act, as well as, in case of death or personal or physical injury, Microsoft is liable according to the statutory law.\par
\pard\widctlpar\s1\li717\sb120\sa120 Subject to the foregoing clause (ii), Microsoft will only be liable for slight negligence if Microsoft is in breach of such material contractual obligations, the fulfillment of which facilitate the due performance of this agreement, the breach of which would endanger the purpose of this agreement and the compliance with which a party may constantly trust in (so-called "cardinal obligations"). In other cases of slight negligence, Microsoft will not be liable for slight negligence.\par
\pard\widctlpar\s1\fi-357\li357\sb120\sa120\b 14.\tab DISCLAIMER OF WARRANTY.\b0 \b THE SOFTWARE IS LICENSED \ldblquote AS IS.\rdblquote YOU BEAR THE RISK OF USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.\b0\par
\b 15.\tab LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES.\par
\pard\widctlpar\li357\sb120\sa120\b0 This limitation applies to (a) anything related to the software, services, content (including code) on third party Internet sites, or third party applications; and (b) claims for breach of contract, warranty, guarantee, or condition; strict liability, negligence, or other tort; or any other claim; in each case to the extent permitted by applicable law.\par
It also applies even if Microsoft knew or should have known about the possibility of the damages. The above limitation or exclusion may not apply to you because your state, province, or country may not allow the exclusion or limitation of incidental, consequential, or other damages.\par
\pard\widctlpar\sb120\sa120\page\par
\pard\widctlpar\sb120\sa120\qc EXHIBIT A\par
THIRD PARTY NOTICES AND INFORMATION\par
FOR\par
MICROSOFT WINDOWS APPLICATION DRIVER\par
\pard\widctlpar\sb120\sa120\par
THIRD-PARTY SOFTWARE NOTICES AND INFORMATION\line\line Note: While Microsoft is not the author of the files below, Microsoft is offering you a license subject to the terms of the Microsoft Software License Terms for Microsoft Windows Application Driver (the \ldblquote Microsoft Program\rdblquote ). Microsoft reserves all other rights. The notices below are provided for informational purposes only and are not the license terms under which Microsoft distributes these files.\par
The Microsoft Program includes the following third-party software:\par
1.\tab Newtonsoft.json version 7.0. ({\b{\field{\*\fldinst{HYPERLINK http://www.newtonsoft.com/json }}{\fldrslt{http://www.newtonsoft.com/json\ul0\cf0}}}}\f0\fs20 )\par
2.\tab Casablanca ({{\field{\*\fldinst{HYPERLINK http://casablanca.codeplex.com/ }}{\fldrslt{http://casablanca.codeplex.com/\ul0\cf0}}}}\f0\fs20 )\par
As the recipient of the above third-party software, Microsoft sets forth a copy of the notices and other information below.\par
1. Newtonsoft.json version 7.0.1 ({{\field{\*\fldinst{HYPERLINK http://www.newtonsoft.com/json }}{\fldrslt{http://www.newtonsoft.com/json\ul0\cf0}}}}\f0\fs20 )\par
NEWTONSOFT.JSON NOTICES AND INFORMATION BEGIN HERE\line =========================================\par
The MIT License (MIT)\line\line Copyright (c) 2007 James Newton-King\line\line Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\line\line The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\line\line THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\par
NEWTONSOFT.JSON NOTICES AND INFORMATION END HERE\line =========================================\par
2. Casablanca ({{\field{\*\fldinst{HYPERLINK http://casablanca.codeplex.com/ }}{\fldrslt{http://casablanca.codeplex.com/\ul0\cf0}}}}\f0\fs20 )\par
CASABLANCA NOTICES AND INFORMATION BEGIN HERE\line =========================================\par
Copyright (c) Microsoft Corporation. All rights reserved. \line Licensed under the Apache License, Version 2.0 (the "License");\line you may not use this file except in compliance with the License.\line You may obtain a copy of the License at\line {{\field{\*\fldinst{HYPERLINK http://www.apache.org/licenses/LICENSE-2.0 }}{\fldrslt{http://www.apache.org/licenses/LICENSE-2.0\ul0\cf0}}}}\f0\fs20\line\line Unless required by applicable law or agreed to in writing, software\line\f1\fs19 distributed under the License is distributed on an "AS IS" BASIS,\line WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\line See the License for the specific language governing permissions and\line limitations under the License.\fs20\par
\f0 CASABLANCA NOTICES AND INFORMATION END HERE\line =========================================\par
\par
\pard\sa200\sl276\slmult1\f2\fs22\lang9\par
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
Windows Application Driver (Beta)
For documentation, sample code, and logging issues:
https://github.com/Microsoft/WinAppDriver
To request new features and upvote requests filed by others:
https://wpdev.uservoice.com

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

1
dep/gsl Submodule

@ -0,0 +1 @@
Subproject commit b74b286d5e333561b0f1ef1abd18de2606624455

BIN
dep/nuget/nuget.exe Normal file

Binary file not shown.

7
dep/packages/README.md Normal file
View File

@ -0,0 +1,7 @@
These packages are redistributed inside this folder because they are not yet available on a public NuGet feed.
## Microsoft.UI.XAML
This package is a custom development build fork to help us light up tab support. It will eventually go onto the same public feed as the existing `Microsoft.UI.XAML` package that's currently available on NuGet.org
## TAEF.Redist.WLK
This package is vetted for public redistribution and release, but the TAEF team hasn't set up a public feed to consume it yet. If/when they do, we'll move to that.

Binary file not shown.

View File

@ -0,0 +1,17 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- ProjectTelemetry.h
Abstract:
- This module is used for basic definitions for telemetry for the entire project
--*/
#define TraceLoggingOptionMicrosoftTelemetry() TraceLoggingOptionGroup(0x9aa7a361, 0x583f, 0x4c09, 0xb1, 0xf1, 0xce, 0xa1, 0xef, 0x58, 0x63, 0xb0)
#define TelemetryPrivacyDataTag(tag) TraceLoggingUInt64((tag), "PartA_PrivTags")
#define PDT_ProductAndServicePerformance 0x0u
#define PDT_ProductAndServiceUsage 0x0u
#define MICROSOFT_KEYWORD_TELEMETRY 0x0
#define MICROSOFT_KEYWORD_MEASURES 0x0

1
dep/wil Submodule

@ -0,0 +1 @@
Subproject commit fbcd1d2abb558da4564ce343b688f7a658f51318

3
dirs Normal file
View File

@ -0,0 +1,3 @@
DIRS=\
src

40
doc/AddASetting.md Normal file
View File

@ -0,0 +1,40 @@
# Adding a Settings Property
1. Add to wincon.w
* THIS IS NOT IN OPENCONSOLE. Make sure you update
`.../console/published/wincon.w` in the OS repo when you submit the PR.
The branch won't build without it.
* For now, you can update winconp.h with your consumable changes.
* define registry name (ex `CONSOLE_REGISTRY_CURSORCOLOR`)
* add the setting to `CONSOLE_STATE_INFO`
* define the property key ID and the property key itself
- Yes, the large majority of the `DEFINE_PROPERTYKEY` defs are the same, it's only the last byte of the guid that changes
2. Add matching fields to Settings.hpp
- add getters, setters, the whole drill.
3. Add to the propsheet.
- We need to add it to *reading and writing* the registry from the propsheet, and *reading* the link from the propsheet. Yes, that's weird, but the propsheet is smart enough to re-use ShortcutSerialization::s_SetLinkValues, but not smart enough to do the same with RegistrySerialization.
- `src/propsheet/registry.cpp`
- `propsheet/registry.cpp@InitRegistryValues` should initialize the default value for the property.
- `propsheet/registry.cpp@GetRegistryValues` should make sure to read the property from the registry
4. Add the field to the propslib registry map
5. Add the value to `ShortcutSerialization.cpp`
- Read the value in `ShortcutSerialization::s_PopulateV2Properties`
- Write the value in `ShortcutSerialization::s_SetLinkValues`
6. Add the setting to `Menu::s_GetConsoleState`, and `Menu::s_PropertiesUpdate`
Now, your new setting should be stored just like all the other properties.
7. Update the feature test properties to get add the setting as well.
- `ft_uia/Common/NativeMethods.cs@WinConP`:
- `Wtypes.PROPERTYKEY PKEY_Console_`
- `NT_CONSOLE_PROPS`
8. Add the default value for the setting to `win32k-settings.man`
- If the setting shouldn't default to 0 or `nullptr`, then you'll need to set the default value of the setting in `win32k-settings.man`.
9. Update `Settings::InitFromStateInfo` and `Settings::CreateConsoleStateInfo` to get/set the value in a CONSOLE_STATE_INFO appropriately.

22
doc/ConsoleCtrlEvent.md Normal file
View File

@ -0,0 +1,22 @@
# Console Control Events
## Generation
conhost requests that user32 inject a thread into the attached console application.
See ntuser's exitwin.c for `CreateCtrlThread`.
## Timeouts
_Sourced from ntuser's **exitwin.c**, **user.h**_
| Event | Circumstances | Timeout |
|------------------------|---------------------------------|-------------------------------------------------------------|
| `CTRL_CLOSE_EVENT` | _any_ | system parameter `SPI_GETHUNGAPPTIMEOUT`, 5000ms |
| `CTRL_LOGOFF_EVENT` | `CONSOLE_QUICK_RESOLVE_FLAG`[1] | registry key `CriticalAppShutdownTimeout` or 500ms |
| `CTRL_LOGOFF_EVENT` | _none of the above_ | system parameter `SPI_GETWAITTOKILLTIMEOUT`, 5000ms |
| `CTRL_SHUTDOWN_EVENT` | **service process** | system parameter `SPI_GETWAITTOKILLSERVICETIMEOUT`, 20000ms |
| `CTRL_SHUTDOWN_EVENT` | `CONSOLE_QUICK_RESOLVE_FLAG`[1] | registry key `CriticalAppShutdownTimeout` or 500ms |
| `CTRL_SHUTDOWN_EVENT` | _none of the above_ | system parameter `SPI_GETWAITTOKILLTIMEOUT`, 5000ms |
| `CTRL_C`, `CTRL_BREAK` | _any_ | **no timeout** |
_[1]: nobody sets `CONSOLE_QUICK_RESOLVE_FLAG`._

View File

@ -0,0 +1,70 @@
# Understanding Console Host Settings
Settings in the Windows Console Host can be a bit tricky to understand. This is mostly because the settings system evolved over the course of decades. Before we dig into the details of how settings are persisted, it's probably worth a quick look at what these settings are.
## Settings Description
|Name |Type |Description |
|---------------------------|-----------------------|--------------------------------------|
|`FontSize` |Coordinate (REG_DWORD) |Size of font in pixels |
|`FontFamily` |REG_DWORD |GDI Font family |
|`ScreenBufferSize` |Coordinate (REG_DWORD) |Size of the screen buffer in WxH characters |
|`CursorSize` |REG_DWORD |Cursor height as percentage of a single character |
|`WindowSize` |Coordinate (REG_DWORD) |Initial size of the window in WxH characters |
|`WindowPosition` |Coordinate (REG_DWORD) |Initial position of the window in WxH pixels (if not set, use auto-positioning) |
|`WindowAlpha` |REG_DWORD |Opacity of the window (valid range: 0x4D-0xFF) |
|`ScreenColors` |REG_DWORD |Default foreground and background colors |
|`PopupColors` |REG_DWORD |FG and BG colors used when displaying a popup window (e.g. when F2 is pressed in CMD.exe) |
|`QuickEdit` |REG_DWORD |Whether QuickEdit is on by default or not |
|`FaceName` |REG_SZ |Name of font to use (or "__DefaultTTFont__", which defaults to whichever font is deemed most appropriate for your codepage) |
|`FontWeight` |REG_DWORD |GDI font weight |
|`InsertMode` |REG_DWORD |Whether Insert mode is on by default or not |
|`HistoryBufferSize` |REG_DWORD |Number of history entries to retain |
|`NumberOfHistoryBuffers` |REG_DWORD |Number of history buffers to retain |
|`HistoryNoDup` |REG_DWORD |Whether to retain duplicate history entries or not |
|`ColorTable%%` |REG_DWORD |For each of the 16 colors in the palette, the RGB value of the color to use |
|`ExtendedEditKey` |REG_DWORD |Whether to allow the use of extended edit keys or not |
|`WordDelimiters` |REG_SZ |A list of characters that are considered as delimiting words (e.g. `' .-/\=|,()[]{}'`) |
|`TrimLeadingZeros` |REG_DWORD |Whether to remove zeroes from the beginning of a selected string on copy (e.g. `00000001` becomes `1`) |
|`EnableColorSelection` |REG_DWORD |Whether to allow selection colorization or not |
|`ScrollScale` |REG_DWORD |How many lines to scroll when using `SHIFT|Scroll Wheel` |
|`CodePage` |REG_DWORD |The default codepage to use |
|`ForceV2` |REG_DWORD |Whether to use the improved version of the Windows Console Host |
|`LineSelection`* |REG_DWORD |Whether to use wrapped text selection |
|`FilterOnPaste`* |REG_DWORD |Whether to replace characters on paste (e.g. Word "smart quotes" are replaced with regular quotes) |
|`LineWrap`* |REG_DWORD |Whether to have the Windows Console Host break long lines into multiple rows |
|`CtrlKeyShortcutsDisabled`*|REG_DWORD |Disables new control key shortcuts |
|`AllowAltF4Close`* |REG_DWORD |Allows the user to disable the Alt-F4 hotkey |
|`VirtualTerminalLevel`* |REG_DWORD |The level of VT support provided by the Windows Console Host |
*: Only applies to the improved version of the Windows Console Host
## The Settings Hierarchy
Settings are persisted to a variety of locations depending on how they are modified and how the Windows Console Host was invoked:
* Hardcoded settings in conhostv2.dll
* User's configured defaults (stored as values in `HKCU\Console`)
* Per-console-application storage (stored as subkeys of `HKCU\Console`). Subkey names:
* Console application path (with `\` replaced with `_`)
* Console title
* Windows shortcut (.lnk) files
To modify the defaults, invoke the `Defaults` titlebar menu option on a Windows Console Host window. Any changes made in the resulting dialog will be persisted to the registry location mentioned above.
To modify settings specific to the current application, invoke the `Properties` titlebar menu option on a Windows Console Host window. If the application was launched directly (e.g. via the Windows run dialog), changes made in the dialog will be persisted in the per-application storage location mentioned above. If the application was launched via a Windows shortcut file, changes made in the settings dialog will be persisted directly into the .lnk file. For console applications with a shortcut, you can also right-click on the shortcut file and choose `Properties` to access the settings dialog.
When console applications are launched, the Windows Console Host determines which settings to use by overlaying settings from the above locations.
1. Initialize settings based on hardcoded defaults
2. Overlay settings specified by the user's configured defaults
3. Overlay application-specific settings from either the registry or the shortcut file, depending on how the application was launched
Note that the registry settings are "sparse" settings repositories, meaning that if a setting isn't present, then whatever value that is already in use remains unchanged. This allows users to have some settings shared amongst all console applications and other settings be specific. Shortcut files, however, store each setting regardless of whether it was a default setting or not.
## Known Issues
* Modifications to system-created Start Menu and Win-X menu console applications are not kept during upgrade.
## Adding settings
Adding a setting involves a bunch of steps - see [AddASetting.md](AddASetting.md).

10
doc/Debugging.md Normal file
View File

@ -0,0 +1,10 @@
# Debugging Miscellanea
This file contains notes about debugging various items in the repository.
## Setting breakpoints in Visual Studio for Cascadia (packaged) application
If you want to debug code in the Cascadia package via Visual Studio, your breakpoints will not be hit by default. A tweak is required to the *CascadiaPackage* project in order to enable this.
1. Right-click on *CascadiaPackage* in Solution Explorer and select Properties
2. Change the *Application process* type from *Mixed (Managed and Native)* to *Native Only*.

36
doc/EXCEPTIONS.md Normal file
View File

@ -0,0 +1,36 @@
# Using Exceptions
## Philosophy
Introducing exceptions to an existing non-exception-based codebase can be perilous. The console was originally written
in C at a time when C++ was relatively unused in the Windows operating system. As part of our project to modernize the
Windows console, we converted to use C++, but still had an aversion to using exception-based error handling in
our code for fear that it introduce unexpected failures. However, the STL and other libraries like it are so useful that
sometimes it's significantly simpler to use them. Given that, we have a set of rules that we follow when considering
exception use.
## Rules
1. **DO NOT** allow exceptions to leak out of new code into new code
1. **DO** use NTSTATUS or HRESULT as return values as appropriate
1. **DO** Encapsulate all exception behaviors within implementing classes
1. **DO NOT** introduce modern exception throwing code into old code. Instead, refactor as needed to allow encapsulation or
use non-exception based code
1. **DO** use WIL as an alternative for non-throwing modern facilities (e.g. wil::unique_ptr<>)
## Examples
### Encapsulating exception behaviors in a class
class ExceptionsDoNotLeak
{
public:
HRESULT SomePublicFunction();
int iPublic;
private:
void _SomePrivateFunction();
int _iPrivate;
};
### Using WIL for non-throwing modern facilities
###

123
doc/ORGANIZATION.md Normal file
View File

@ -0,0 +1,123 @@
# Code Organization
## Rules
- **Follow the pattern of what you already see in the code**
- Try to package new ideas/components into libraries that have nicely defined interfaces
- Package new ideas into classes or refactor existing ideas into a class as you extend.
- Each project should have a Unit test in a ut_ folder in its subdirectory (like `ut_host`)
- Functional tests should be in ft_ subdirectories (like `ft_api`)
- Build scripts are generally in subdirectories with their type of output (like `/dll` or `/exe`)
- Try to place interfaces in an `inc` folder in an appropriate location
- Structure related libraries together (`/terminal/parser` and `/terminal/adapter`)
## Code Overview
* `/` - root is where solution files, root MD documentation, SD replication artifacts go.
* `/bin` not checked in is where binaries will be generated by the MSBuild system
* `/dep` dependencies that arent a part of the SDK
* `/dep/console` files that are currently in the internal-only private SDK for the console but were working on opening
* `/dep/DDK` files lifted wholesale from the public Microsoft DDK so you dont have to install that. Were reducing dependencies on these but we still use TAEF (included in here) as our test runner engine
* `/dep/NT` some more structures from the DDK, sometimes internal-only/non-public were trying to remove.
* `/dep/telemetry` Private Microsoft telemetry headers
* `/dep/wil` Windows Internal Library extremely useful for interfacing with Win32/NT/COM APIs. Contains tons of “unique pointer” like syntax for various Win32 APIs and a handful of useful macros to enable cleaner code writing (RETURN_HR_IF, LOG_IF_WIN32_ERROR, etc.)
* `/dep/win32k` private headers from the Windows windowing system that were trying to migrate off of
* `/ipch` not checked in is where intellisense data will be generated if you use Visual Studio 2015
* `/obj` not checked in is where objects will be generated by the MSBuild system
* `/src` This is the fun one. In the root is common build system data.
* `/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 arent stated anywhere else. Were trying to pull things out that are reusable into other libraries, but its a work in progress
* `/src/host/lib` Builds the reusable LIB copy of the host
* `/src/host/dll` Packages LIB into conhostv2.dll to be put into the OS C:\windows\system32\
* `/src/host/exe` Packages LIB into OpenConsole.exe currently used for testing without replacing your system32 copy
* `/src/host/tools` Random odds and ends that make testing/debugging/development a bit easier
* ...to be docd, each of what these are
* `/src/host/ut_host` Contains complete unit test library for everything weve managed to get unit tests on. Wed like all new code to contribute appropriate unit tests in here
* `/src/host/ft_api` Feature level tests for anything that changes the way we interact with the outside world via the API. Building these up as we work as well
* `/src/host/ft_cjk` Double-wide/double-byte specific Chinese/Japanese/Korean language tests that previously had to be run in a different environment. To be merged into ft_api one day
* `/src/host/ft_resize` Special test for resizing/reflowing the buffer window
* `/src/host/ft_uia` Currently disabled (for not being very reliable) UI Automation tests that we are looking to re-enable and expand to do UI Automation coverage of various human interactions
* `/src/host/...` - The files Ill list out below
* `/src/inc` Include files that are shared between the host and some of the other libraries. This is only some of them. The include story is kind of a mess right now, but wed like to clean it up at some point
* `/src/propslib` Library shared between console host and the OS shell “right click a shortcut file and modify console properties” page to read/write user settings to and from the registry and embedded within shortcut LNK data
* `/src/renderer` Refactored extraction of all activities related to rendering the text in the buffers onto the screen
* `/src/renderer/base` Base interface layer providing non-engine-specific rendering things like choosing the data from the console buffer, deciding how to lay out or transform that data, then dispatching commands to a specific final display engine
* `/src/renderer/gdi` The GDI implementation of rendering to the screen. Takes commands to “draw a line” or “fill the background” or “select a region” from the base and turns them into GDI calls to the screen. Extracted from original console host code.
* `/src/renderer/inc Interface definitions for all renderer communication
* `/src/terminal` Virtual terminal support for the console. This is the sequences that are found in-band with other text on STDIN/STDOUT that command the display to do things. This is the *nix way of controlling a console.
* `/src/terminal/parser` This contains a state machine and sorting engine for feeding in individual characters from STDOUT or STDIN and decoding them into the appropriate verbs that should be performed
* `/src/terminal/adapter` This converts the verbs from the interface into calls on the console API. It doesnt actually call through the API (for performance reasons since it lives inside the same binary), but it tries to remain as close to an API call as possible. There are some private extensions to the API for behaviors that didnt exist before this was written that weve not made public. We dont know if we will yet or force people to use VT to get at them.
* `/src/tsf` Text Services Foundation. This provides IME input services to the console. This was historically used for only Chinese, Japanese, and Korean IMEs specifically on OS installations with those as the primary language. It was in the summer of 2016 unrestricted to be able to be used on any OS installation with any IME (whether or not it will display correctly is a different story). It also was unrestricted to allow things like Pen and Touch input (which are routed via IME messages) to display properly inside the console from the TabTip window (the little popup that helps you insert pen/touch writing/keyboard candidates into an application)
## Host File Overview
* Generally related to handling input/output data and sometimes intertwined with the actual service calls
* `_output.cpp`
* `_stream.cpp`
* Handles copy/paste/etc.
* `clipboard.cpp`
* Handles the command prompt line as you see in CMD.exe (known as the processed input line… most other shells handle this themselves with raw input and dont use ours. This is a legacy of bad architectural design, putting stuff in conhost not in CMD)
* `cmdline.cpp`
* Handles shunting IME data back and forth to the TSF library and to and from the various buffers
* `Conimeinfo.cpp`
* `Convarea.cpp`
* Contains the global state for the entire console application
* `consoleInformation.cpp`
* Stuff related to the low-level server communication over our protocol with the driver
* `Csrutil.cpp`
* `Srvinit.cpp`
* `Handle.cpp`
* Routines related to startup of the application
* `Srvinit.cpp`
* Routines related to the API calls (and the servicing thereof, muxes a bit with the server protocol)
* `Directio.cpp`
* `Getset.cpp`
* `Srvinit.cpp`
* Extra stuff strapped onto the buffer to enable CJK languages
* `Dbcs.cpp`
* Attempted class-ification of existing Cursor structures to take them out of Screen Info/Text Info
* `Cursor.cpp`
* Related to searching through the back buffer of the console (the output scroll buffer as defined in screeninfo/textinfo)
* `Find.cpp`
* Contains global state data
* `Globals.cpp`
* Attempted class-ification of existing Icon manipulation to take them out of ConsoleInformation/Settings
* `Icon.cpp`
* Contains all keyboard/mouse input handling, capture of keys, conversion of keys, and some manipulation of the input buffer
* `Input.cpp`
* `Inputkeyinfo.cpp`
* `Inputreadhandledata.cpp`
* Main entry point used ONLY by the OS to send a pre-configured driver handle to conhostv2.dll
* `Main.cpp`
* Assorted utilities and stuff
* `Misc.cpp` (left for us by previous eras of random console devs)
* `Util.cpp` (created in our era)
* Custom zeroing and non-throwing allocator
* `Newdelete.cpp`
* Related to inserting text into the TextInfo buffer
* `Output.cpp`
* `Stream.cpp`
* Connects to interfaces in the PropsLib to manipulate persistent settings state
* `Registry.cpp`
* Connects to our relatively recently extracted renderer LIB to give it data about console state and user prefs
* `renderData.cpp`
* `renderFontDefaults.cpp`
* Maintains most of the information about what we should present inside the window on the screen (sizes, dimensions, also holds a text buffer instance and a cursor instance and a selection instance)
* `screenInfo.cpp`
* Handles some aspects of scrolling with the mouse and keyboard
* `Scrolling.cpp`
* Handles the click-and-drag highlighting of text on the screen to select (or the keyboard-based Mark mode selection where you can enter the mode and select around). Often calls clipboard when done
* `Selection.cpp`
* `selectionInput.cpp`
* `selectionState.cpp`
* Handles all user preferences and state. Was extracted from consoleInformation and CI subclasses it still (because it was hard to break the association out)
* `Settings.cpp`
* Good ol Windows 10 telemetry pipeline & ETW events as debugging aids (they use the same channel with a different flag)
* `Telemetry.cpp`
* `Tracing.cpp`
* Private calls into the Windows Window Manager to perform privileged actions related to the console process (working to eliminate) or for High DPI stuff (also working to eliminate)
* `Userprivapi.cpp`
* `Windowdpiapi.cpp`
* New UTF8 state machine in progress to improve Bash (and other apps) support for UTF-8 in console
* `Utf8ToWideCharParser.cpp`
* Window resizing/layout/management/window messaging loops and all that other stuff that has us interact with Windows to create a visual display surface and control the user interaction entry point
* `Window.cpp`
* `Windowproc.cpp`

7
doc/STYLE.md Normal file
View File

@ -0,0 +1,7 @@
# Coding Style
## Philosophy
1. If it's inserting something into the existing classes/functions, try to follow the existing style as closely as possible.
1. If it's brand new code or refactoring a complete class or area of the code, please follow as Modern C++ of a style as you can and reference the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines) as much as you possibly can.
1. When working with any Win32 or NT API, please try to use the [Windows Internal Library](./WIL.md) smart pointers and result handlers.
1. The use of NTSTATUS as a result code is discouraged, HRESULT or exceptions are preferred. Functions should not return a status code if they would always return a successful status code. Any function that returns a status code should be marked `noexcept` and have the `nodiscard` attribute.

20
doc/TAEF.md Normal file
View File

@ -0,0 +1,20 @@
### TAEF ###
TAEF, the Test Authoring and Execution Framework, is used extensively within the Windows organization to test the operating system code in a unified manner for system, driver, and application code. As the console is a Windows OS Component, we strive to continue using the same system such that tests can be ran in a unified manner both externally to Microsoft as well as inside the official OS Build/Test system.
The [official documentation](https://msdn.microsoft.com/en-us/library/windows/hardware/hh439725\(v=vs.85\).aspx) for TAEF describes the basic architecture, usage, and functionality of the test system. It is similar to Visual Studio test, but a bit more comprehensive and flexible.
For the purposes of the console project, you can run the tests using the *TE.exe* that matches the architecture for which the test was build (x86/x64) in the pattern
te.exe Console.Unit.Tests.dll
Replacing the binary name with any other test binary name that might need running. Wildcard patterns or multiple binaries can be specified and all found tests will be executed.
Limiting the tests to be run is also useful with:
te.exe Console.Unit.Tests.dll /name:*BufferTests*
Any pattern of class/method names can be specified after the */name:* flag with wildcard patterns.
For any further details on the functionality of the TAEF test runner, *TE.exe*, please see the documentation above or run the embedded help with
te.exe /!

117
doc/UniversalTest.md Normal file
View File

@ -0,0 +1,117 @@
# Universal Testing for Console
## Overview
Universal Testing is the Microsoft framework for creating and deploying test packages onto just about any device through just about any process. We use it for packaging up all sorts of test resources and sending it into our automated test labs no matter what the source of the content or the engineering system involved.
It involves several parts:
- TESTMD
- These define a package unit for deployment to the test device. This usually includes the test binaries and any dependent data that it will need to execute.
- There can also be a hierarchy where one package can depend on another such that packages can be re-used
- TESTLIST
- This defines a batch of TESTMD packages that should be executed together.
- TESTPASSES
- This defines a list of tests via a TESTLIST and a lab environment configuration on which the tests should be run
These files can either include their child element as they're supposed to (TESTMDs included in TESTLISTs) or they can often include themselves to provide chain structuring (one TESTLIST can reference another TESTLIST).
- TREX
- This is the legacy configuration system that performed the same job as TESTPASSES, but not in source files.
## Configuration
This is a record of the current setup (as of Mar-1-2019) of the console's universal tests. This series of steps was created in conjunction with converting the console's testing from the legacy TREX dispatching mode to the new TESTPASSES dispatching mode for the Source Is Truth initiative (define all testing metadata in source next to the code being tested, instead of in a separate database somewhere else).
1. Have some TestMDs.
- \onecore\windows\core\console\open\src\host\ut_host\testmd.definition + SOURCES file
- Generates “Microsoft-Console-Host-UnitTests” TESTMD and package
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
1. Microsoft.Console.Host.UnitTests.testmd
1. Microsoft-Console-Host-UnitTests.cab
1. Microsoft-Console-Host-UnitTests.man.dsm.xml
- \onecore\windows\core\console\open\src\host\ft_host\testmd.definition + SOURCES file
- Generates “Microsoft-Console-Host-FeatureTests” TESTMD and package
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
1. Microsoft.Console.Host.FeatureTests.testmd
1. Microsoft-Console-Host-FeatureTests.cab
1. Microsoft-Console-Host-FeatureTests.man.dsm.xml
- \onecore\windows\core\console\open\src\buffer\out\ut_textbuffer\testmd.definition + SOURCES file
- Generates “Microsoft-Console-TextBuffer-UnitTests” TESTMD and package
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
1. Microsoft.Console.TextBuffer.UnitTests.testmd
1. Microsoft-Console-TextBuffer-UnitTests.cab
1. Microsoft-Console-TextBuffer-UnitTests.man.dsm.xml
- \minkernel\console\client\ut_conpty\testmd.definition + SOURCES file
- Generates “Microsoft-Console-ConPty-UnitTests” TESTMD and package
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
1. Microsoft.Console.ConPty.UnitTests.testmd
1. Microsoft-Console-ConPty-UnitTests.cab
1. Microsoft-Console-ConPty-UnitTests.man.dsm.xml
- \onecore\windows\core\console\open\src\terminal\parser\ut_parser\testmd.definition + SOURCES file
- Generates “Microsoft-Console-VirtualTerminal-Parser-UnitTests” TESTMD and package
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
1. Microsoft.Console.VirtualTerminal.Parser.UnitTests.testmd
1. Microsoft-Console-VirtualTerminal-Parser-UnitTests.cab
1. Microsoft-Console-VirtualTerminal-Parser-UnitTests.man.dsm.xml
- \onecore\windows\core\console\open\src\terminal\adapter\ut_adapter\testmd.definition + SOURCES file
- Generates “Microsoft-Console-VirtualTerminal-Adapter-UnitTests” TESTMD and package
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
1. Microsoft.Console.VirtualTerminal.Adapter.UnitTests.testmd
1. Microsoft-Console-VirtualTerminal-Adapter-UnitTests.cab
1. Microsoft-Console-VirtualTerminal-Adapter-UnitTests.man.dsm.xml
1. Have some TESTLISTs that refer to the TESTMDs
- \onecore\windows\core\console\open\src\testlist\Microsoft.Console.Tests.testlist + SOURCES file
- Includes
1. Microsoft.Console.Host.UnitTests.testmd
1. Microsoft.Console.Host.FeatureTests.testmd
1. Microsoft.Console.TextBuffer.UnitTests.testmd
1. Microsoft.Console.Conpty.UnitTests.testmd
1. Microsoft.Console.VirtualTerminal.Parser.UnitTests.testmd
1. Microsoft.Console.VirtualTerminal.Adapter.UnitTests.testmd
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
- Microsoft.Console.Tests.testlist
- \onecore\windows\core\console\open\src\testlist\Microsoft.Console.TestLab.Desktop.testlist + SOURCES file
- Includes
1. Microsoft.Console.Tests.testlist
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
- Microsoft.Console.TestLab.Desktop.testlist
- Is currently the subject of TREX IDs
1. 153251 TESTLIST based AMD64 Desktop VM testpass (to be offboarded when done)
1. 153252 TESTLIST based X86 Desktop VM testpass (to be offboarded when done)
- \onecore\windows\core\console\open\src\testlist\Microsoft.Console.TestLab.OneCoreUap.testlist + SOURCES file
- Includes
1. Microsoft.Console.Tests.testlist
- Binplaces to prebuilt\test\<arch>\<fre/chk>\
- Microsoft.Console.TestLab.OneCoreUAP.testlist
- Is currently the subject of TREX IDs
1. 153253 TESTLIST based AMD64 OneCoreUAP VM testpass (to be offboarded when done)
1. 153254 TESTLIST based X86 OneCoreUAP VM testpass (to be offboarded when done)
1. Create some TESTPASSES
- For the existing OneCoreUAP ones…
- Create directory \onecoreuap\testpasses\local\console\
- Create file console_onecoreuap.testpasses
1. Create AMD64 pass
- Name it similarly to the existing name
- Use the environment $(TESTPASSES_ONECOREUAP)/standard_testenvs/OneCoreUAP-amd64-VM.testenv
- Connect to the testlist $(TESTLIST_SEARCH_PATHS)/Microsoft.Console.TestLab.OneCoreUAP.testlist
1. Create X86 pass
- Name it similarly to the existing name
- Use the environment $(TESTPASSES_ONECOREUAP)/standard_testenvs/OneCoreUAP-x86-VM.testenv
- Connect to the testlist $(TESTLIST_SEARCH_PATHS)/Microsoft.Console.TestLab.OneCoreUAP.testlist
- For the Desktop ones…
- Create directory \pcshell\testpasses\local\console\
- Create file console_desktop.testpasses
1. Create AMD64 pass
- Name it similarly to the existing name
- Use the environment $(TESTPASSES_PCSHELL)/standard_testenvs/Enterprise-amd64-VM.testenv
- Connect to the testlist $(TESTLIST_SEARCH_PATHS)/Microsoft.Console.TestLab.Desktop.testlist
1. Create X86 pass
- Name it similarly to the existing name
- Use the environment $(TESTPASSES_PCSHELL)/standard_testenvs/Enterprise-x86-VM.testenv
- Connect to the testlist $(TESTLIST_SEARCH_PATHS)/Microsoft.Console.TestLab.Desktop.testlist
1. Hook up the TESTPASSES into the official branch TESTPASSES file
- Open up \.branchconfig\official\rs_onecore_dep_acidev\official_build.testpasses
1. Add TestpassReferences item targeting $(TESTPASSES_ONECOREUAP)/local/console/console_onecoreuap.testpasses
1. Add TestpassReferences item targeting $(TESTPASSES_PCSHELL)/local/console/console_desktop.testpasses

27
doc/WIL.md Normal file
View File

@ -0,0 +1,27 @@
# Windows Internal Library
## Overview
Windows Internal Library, or WIL, is a header-only library created to help make working with the Windows API more predictable and (hopefully) bug free.
A majority of functions are in either the `wil::` or `wistd::` namespace. `wistd::` is used for things that have an equivalent in STL's `std::` namespace but have some special functionality like being exception-free. Everything else is in `wil::` namespace.
The primary usages of WIL in our code so far are...
### Smart Pointers ###
Inside [wil\resource.h](..\dep\wil\resource.h) are smart pointer like classes for many Windows OS resources like file handles, socket handles, process handles, and so on. They're of the form `wil::unique_handle` and call the appropriate/matching OS function (like `CloseHandle()` in this case) when they go out of scope.
Another useful item is `wil::make_unique_nothrow()` which is analogous to `std::make_unique` (except without the exception which might help you integrate with existing exception-free code in the console.) This will return a `wistd::unique_ptr` (vs. a `std::unique_ptr`) which can be used in a similar manner.
### Result Handling ###
To manage the various types of result codes that come back from Windows APIs, the file [wil\result.h](..\dep\wil\result.h) provides a wealth of macros that can help.
As an example, the method `DuplicateHandle()` returns a `BOOL` value that is `FALSE` under failure and would like you to `GetLastError()` from the operating system to find out what the actual result code is. In this circumstance, you could use the macro `RETURN_IF_WIN32_BOOL_FALSE` to wrap the call to `DuplicateHandle()` which would automatically handle this pattern for you and return the `HRESULT` equivalent on failure.
This leads to nice patterns where you can set up all resources in a function as protected by `std::unique_ptr` or the various `wil::` smart pointers and smart handles then `RETURN_IF_*` on every call to a Windows API and be guaranteed that your resources will be cleaned up appropriately under any failure case. Do note that this generally requires you to return an `HRESULT` as your return code and use out pointer parameters for return data. There are exceptions to this... read the header for more details.
The additional advantage to using this pattern is that failures at any point are logged to our global tracing/debugging channels to be viewed under the debugger output with the exact line number and function details for the error.
Additionally, if you just want to make sure that a failure case is logged for debugging purposes, all of these macros have a `LOG_IF_*` equivalent that will simply log a failure and keep rolling.

42
doc/WindowsTestPasses.md Normal file
View File

@ -0,0 +1,42 @@
# Windows Test Passes for Console
## Overview
Every night, we run a set of automated test passes in the Windows engineering system for the console host code. This process is orchestrated on our working branch, which at the time of this writing is `RS_ONECORE_DEP_ACIDEV` (and will soon switch back to `RS_ONECORE_DEP_ACIOSS` or something of that ilk).
You can find the information about our nightly build, including these test passes, at the website [https://es.microsoft.com], choosing our branch, and then navigating to the `Execution Status` page.
At the bottom of the page will be the test pass runs for our tests that night. You can find out more about how these are set up in the [UniversalTest.md] file.
When a failure occurs in one of these passes, a bug will automatically be generated in the Azure DevOps project for the OS and assigned to our path.
The next step would be investigating one of these failures...
## Investigation
A quick overview of investigation... normally you can just attempt to build and reproduce the failure locally with the `OpenConsole` project and it will happen the same way as it did on the nightly build in the lab. However, sometimes the failure will be exclusive to the lab or won't happen in the same way as it does on your local dev machine. At that point, you need to move into setting up the environment as it was during the testpass and figuring out what went wrong.
You can try to do this all manually by pulling down a VM image from the release share for the nightly build, making a VM, deploying the test binaries and TAEF test runnner executables to the machine, installing the VS Remote Debugging or WinDBG tools on the VM, and then running the test and figuring out what's going wrong with the debuggers.
Or you can use some of the Engineering Systems tools to make this easier. I'll detail how to do that below.
Prerequisites:
- Visual Studio 2017
- Install the TDP (Test Development Platform) plug-in (see: [https://osgwiki.com/wiki/Test_Development_Platform_(TDP)]).
1. Open Visual Studio 2017 and use the TDP drop-down menu to open the `Device Manager`
1. In the pane that opens to the left, choose `Add` and then `Nebula VM Device`. Nebula is a cloud provider for VMs (like Azure but a more private instance for corporate work usage).
1. Name the machine and choose the build/branch/flavor/SKU from the drop downs at the bottom. It will find the VHD for you from the build shares. Hit `Add Device` to deploy to Nebula
1. Wait a few minutes. It took 5-10 for it to be deployed.
1. Right click the machine name in the `Device Manager` list and choose `Launch T-Shell`. You can also use `Connect via Console` to get a "remote desktop"-like session to the KVM port on the VM.
1. In T-shell, use `testd Microsoft.Console.TestLab.Desktop.testlist` or a command of that format with a different TESTLIST or TESTMD name from our project (see the [UniversalTest.md] documentation). The `testd` utility will automatically resolve the build/branch/flavor information, dig through the build shares for the matching TESTLIST/TESTMD metadata, and attempt to deploy all relevent packages and dependencies on the device. When it's successful, it will move onto running all the tests and giving you the results. On conclusion, the test results should pop up in the web browser or the `Hubble - Log Viewer` tool provided by the Engineering Systems team.
If some of the above things do not work, go to [https://osgwiki.com] and type them into the Search bar. For instance, if T-Shell isn't found or working, you can find out where to get it or download it on `OSGWiki`. The same goes for the other commands besides `testd` to use in T-shell and more information on what `Hubble` or `Nebula` are.
Presumably now you have a failure. Or a success. You can attempt to spelunk the logs in `Hubble` and you might come to a conclusion. Or you can move onto debugging directly.
Now that you've relied on `testd` to get everything deployed and orchestrated and run once on the device, you can use `execd` to run things again or to run a smaller subset of things on the remote device through `T-Shell`.
By default, in the `Universal Test` world, everything will be deployed onto the remote machine at `C:\data\test\bin`. In T-Shell, use `cdd C:\data\test\bin` to change to that directory and then `execd te.exe Microsoft.Console.Host.FeatureTests.dll /name:*TestReadFileEcho*` to run just one specific test. Of course you should substitute the file name and test name parameters as makes sense. And of course you can find out more about `cdd` and `execd` on the `T-shell` page of `OSGWiki`.
Fortunately, running things through `T-shell` in this fashion is exactly the same way that the testlab orchestrates the tests. If you still don't get good data this way, you can use the `Connect via Console` mechanism way above to try to run things under `WinDBG` or the `Visual Studio Remote Debugger` manually on the machine to get them to repro or under the debugger more completely.

32
doc/building.md Normal file
View File

@ -0,0 +1,32 @@
# How to build Openconsole
Openconsole can be built with Visual Studio or from the command line. There are build scripts for both cmd and powershell in /tools.
## Building with cmd
The cmd scripts are set up to emulate a portion of the OS razzle build environment. razzle.cmd is the first script that should be run. bcz.cmd will build clean and bz.cmd should build incrementally.
There are also scripts for running the tests:
- runut.cmd - run the unit tests
- runft.cmd - run the feature tests
- runuia.cmd - run the UIA tests
## Build with Powershell
Openconsole.psm1 should be loaded with `Import-Module`. From there `Set-MsbuildDevEnvironment` will set up environment variables required to build. There are a few exported functions (look at their documentation for further details):
- Invoke-OpenConsolebuild - builds the solution. Can be passed msbuild arguments.
- Invoke-OpenConsoleTests - runs the various tests. Will run the unit tests by default.
- Start-OpenConsole - starts Openconsole.exe from the output directory. x64 is run by default.
- Debug-OpenConsole - starts Openconsole.exe and attaches it to the default debugger. x64 is run by default.
## Configuration Types
Openconsole has three configuration types:
- Debug
- Release
- AuditMode
AuditMode is an experimental mode that enables some additional static analyis from CppCoreCheck.

View File

@ -0,0 +1,108 @@
# Keymapping spec
* author: Mike Griese __migrie__
* created on: 2018-Oct-23
## Abstract
It should be possible to configure the terminal so that it doesn't send certain keystrokes as input to the terminal, and instead triggers certain actions. Examples of these actions could be copy/pasting text, opening a new tab, or changing the font size.
This spec describes a mechanism by which we could provide a common implementation of handling keyboard shortcuts like these. This common implementation could then be leveraged and extended by the UX implementation as to handle certain callbacks in the UX layer. For example, The TerminalCore doesn't have a concept of what a tab is, but the keymap abstraction could raise an event such that a WPF app could implement creating a new tab in it's idomatic way, and UWP could implement them in their own way.
## Terminology
* **Key Chord**: This is any possible keystroke that a user can input
simultaneously, as a combination of a single character and any set of
(<kbd>Ctrl</kbd>, <kbd>Alt</kbd> and <kbd>Shift</kbd>).
For example, pressing <kbd>Ctrl</kbd> and <kbd>C</kbd> at the same time is the
key chord Ctrl+C. Pressing <kbd>Ctrl+B</kbd>, <kbd>C</kbd> are two separate
key chords. Trying to press them simultaneously (<kbd>Ctrl+B+C</kbd>) should
generate two separate key chords, with the order determined by the OS.
## User Stories
1. The User should be able to press certain key-chords to trigger certain
actions in the frontend of the application, such as copying text, pasting,
opening new tabs, or switching focus between panes.
2. The user should be able to configure which key chords are bound to which actions.
3. If a key chord is not mapped to an action, it should be sent to the Terminal just as any other keypress.
## Details
When the UX frontend is created, it should instantiate a `IKeyBindings` object with the keybindings mapped as it would like.
When it's creating it's platform-dependent terminal component, it can pass the `IKeyBindings` object to that component. The component will then be able to pass that object to the terminal instance.
When the terminal component calls `ITerminalInput.SendKeyEvent(uint vkey, KeyModifiers modifiers)`, the terminal will use `IKeyBindings.TryKeyChord` to see if there are any bound actions to that input. If there are, the `IKeyBindings` implementation will either handle the event by interacting with the `ITerminalInput`, or it'll invoke an event that's been registered by the frontend
```csharp
struct KeyChord
{
KeyModifiers modifiers;
int vkey;
}
interface IKeyBindings {
bool TryKeyChord(KeyChord kc);
}
```
Each frontend can implement the `IKeyBindings` interface however it so chooses.
The `ITerminalInput` interface will be extended with the following method:
```csharp
public interface ITerminalInput
{
...
void SetKeyBindings(IKeyBindings bindings);
...
}
```
This will set the `IKeyBindings` object that the `ITerminalInput` implementation will use to filter key events.
This method will be implemented by the `Terminal` object:
```csharp
partial class Terminal
{
public void ITerminalInput.SetKeyBindings(IKeyBindings bindings);
}
```
### Project Cascadia Sample
Below is an example of how the Project Cascadia application might implement it's
keybindings.
```csharp
enum ShortcutAction
{
CopyText,
PasteText,
NewTab,
NewWindow,
CloseWindow,
CloseTab,
SwitchToTab,
NextTab,
PrevTab,
IncreaseFontSize,
DecreaseFontSize,
...
}
public delegate bool NewTabEvent(object sender);
public delegate bool CloseTabEvent(object sender);
public delegate bool NewWindowEvent(object sender);
public delegate bool CloseWindowEvent(object sender);
public delegate bool CopyEvent(object sender);
public delegate bool PasteEvent(object sender);
class KeyBindings : IKeyBindings
{
private Dictionary<ShortcutAction, KeyChord?> keyShortcuts;
public void SetKeyBinding(ShortcutAction action, KeyChord? chord);
public bool TryKeyChord(KeyChord chord);
}
```
### Copy/Paste
How does Copy/paste play into this?
When Input is written to the terminal, and it tries the copy keybinding, what happens?
The Keybindings are global to the frontend, not local to the terminal. Copy/Paste events should also be delegates that get raised, and the frontend can then determine what to do with them. It'll probably query it's active/focused Terminal Component, then Get the `ITerminalInput` from that component, and use that to CopyText / PasteText from the Terminal as needed.

View File

@ -0,0 +1,233 @@
# Terminal Settings
* author: Mike Griese __migrie__
* created on: 2018-Oct-23
## Abstract
This spec will outline how various terminal frontends will be able to interact with the settings for the terminal.
## Terminology
* **Frontend** or **Application Layer**: This is the end-user experience. This
could be a Terminal Application (ex. Project Cascadia) or something that's
embedding a terminal window inside of it (ex. Visual Studio). These frontends
consume the terminal component as an atomic unit.
* **Component Layer**: This is the UI framework-dependent implementation of the
Terminal component. As planned currently, this is either the UWP or WPF
Terminal component.
* **Terminal Layer**: This is the shared core implementation of the terminal.
This is the Terminal Connection, Parser/Adapter, Buffer, and Renderer (but not
the UX-dependant RenderEngine).
## User Stories
1. "Project Cascadia" should be able to have both global settings (such as
scrollbar styling) and settings that are stored per-profile (such as
commandline, color scheme, etc.)
2. "Project Cascadia" should be able to load these settings at boot, use them to
create terminal instances, be able to edit them, and be able to save them
back.
3. "Project Cascadia" should be able to have terminal instances reflect the
changes to the settings when the settings are changed.
4. "Project Cascadia" should be able to host panes/tabs with different profiles
set at the same time.
5. Visual Studio should be able to persist and edit settings globally, without
the need for a globals/profiles structure.
6. The Terminal should be able to read information from a settings structure
that's independant of how it's persisted / implemented by the Application
7. The Component should be able to have it's own settings independent of the
application that's embedding it, such as font size and face, scrollbar
visibility, etc. These should be settings that are specific to the component,
and the Terminal should logically be unaffected by these settings.
## Details
Some settings will need to be Application-specific, some will need to be component-specific, and some are terminal-specific. For example:
Terminal | Component | Frontend
--------------------|-----------------------|------------------
Color Table | Font Face, size | Status Line Visibility, contents
Cursor Color | Scrollbar Visibility | ~~Window Size~~[1]
History Size | |
Buffer Size [1] | |
* [1] I believe only the "Default" or "Initial" buffer size should be the one we truly store in the settings. When the app first boots up, it can use that value to with the font size to figure out how big its window should be. When additional tabs/panes are created, they should inherit the size of the existing window. Similarly, VS could first calculate how much space it has available, then override that value when creating the terminal.
Project Cascadia needs to be able to persist settings as a bipartite globals-profiles structure.
VS needs to be able to persist settings just as a simple set of global settings.
When the application needs to retrieve these settings, they need to use them as a tripartite structure: frontend-component-terminal settings.
Each frontend will have it's own set of settings.
Each component implementation will also ned to have some settings that control it.
The terminal also will have some settings specific to the terminal.
### Globals and Profiles
With \*nix-like terminals, settings are typically structured as two parts:
Globals and Profiles.
Globals are settings that affect the entirety of the terminal application. They wouldn't be different from one pane to the next. An example is the Terminal KeyBindings - these should be the same for all tabs/panes that are running as a part of the terminal application.
Profiles are what you might consider per-application settings. These are settings that can be different from one terminal instance to the next. One of the primary differentiators between profiles is the commandline used to start the terminal instance - this enables the user to have both a `cmd` profile and a `powershell` profile, for example. Things like the color table/scheme, font size, history length, these all change per-profile.
Per-Profile | Globals
------------------------|------------------------
Color Table | Keybindings
Cursor Color | Scrollbar Visibility
History Size | Status Line Visibility, contents
Font Face, size | Window Size
Shell Commandline |
### Simple Settings
An application like VS might not even care about settings profiles. They should be able to persist the settings as just a singular entity, and change those as needed, without the additional overhead. Profiles will be something that's more specifc to Project Cascadia.
### Interface Descriptions
```csharp
public class TerminalSettings
{
Color DefaultForeground;
Color DefaultBackground;
Color[] ColorTable;
Coord? Dimensions;
int HistorySize;
Color CursorColor;
CursorShape CursorShape;
}
public interface IComponentSettings
{
TerminalSettings TerminalSettings { get; }
}
public interface IApplicationSettings
{
IComponentSettings ComponentSettings { get; }
}
```
The Application can store whatever settings it wants in it's implementation of `IApplicationSettings`. When it instantiates a Terminal Component, it will pass it's `IComponentSettings` to it.
The component will retrieve whatever settings it wants from that object, and then pass the `TerminalSettings` to the Terminal it creates.
The frontend will be able to get/set it's settings from the `IApplicationSettings` implementation.
The frontend will be able to create components using the `IComponentSettings` in it's `IApplicationSettings`.
The Component will then create the Terminal using the `TerminalSettings`.
#### Project Cascadia Settings Details
The `CascadiaSettings` will store the settings as two parts:
* A set of global data & settings
* A list of Profiles, that each have more data
When Cascadia starts up, it'll load all the settings, including the Globals and profiles. The Globals will also tell us which profile is the "Default" profile we should use to instantiate the terminal.
Using the globals and the Profile, it'll convert those to a `ApplicationSettings : IApplicationSettings`.
It'll read data from that `ApplicationSettings` to initialize things it needs to know.
* It'll determine whether or not to display the status line
* It'll query the Component settings for the default size of the component, so it knows how big of a space it needs to reserve for it
It'll then instantiate a `UWPTerminalComponent` and pass it the `UWPComponentSettings`.
This is a rough draft of what these members might all be like.
```csharp
class CascadiaSettings
{
void LoadAll();
void SaveAll();
GlobalAppSettings Globals;
List<Profile> Profiles;
ApplicationSettings ToSettings(GlobalAppSettings globals, Profile profile);
void Update(ApplicationSettings appSettings, GUID profileID);
}
class Profile
{
GUID ProfileGuid;
string Name;
string Commandline;
TerminalSettings TerminalSettings;
string FontFace;
int FontSize;
float acrylicTransparency;
bool useAcrylic;
}
class GlobalAppSettings
{
GUID defaultProfile;
Keybindings keybindings;
bool showScrollbars;
bool showStatusline;
}
class ApplicationSettings : IApplicationSettings
{
UWPComponentSettings ComponentSettings;
Keybindings keybindings;
bool showStatusline;
}
class UWPComponentSettings : IComponentSettings
{
Point GetDefaultComponentSize();
TerminalSettings TerminalSettings;
string FontFace;
int FontSize;
bool showScrollbars;
float acrylicTransparency;
bool useAcrylic;
}
```
### Updating Settings
What happens when the user changes the application's settings? The App,
Component, and Terminal might all need to update their settings.
The component will expose a `UpdateSettings()` method that will cause the
Component and Terminal to reload the settings from their settings objects.
```csharp
interface ITerminalComponent
{
void UpdateSettings(IComponentSettings componentSettings);
}
partial class UWPTerminalComponent : ITerminalComponent
{
void UpdateSettings(IComponentSettings componentSettings)
{
// Recalculate GlyphTypeFace
// Recalculate rows/cols using current geometry and typeface
// Update our terminal instance:
terminal.UpdateSettings(componentSettings.TerminalSettings);
}
}
```
#### Updating settings in Project Cascadia
However, when Cascadia's settings change, we're going to possibly change some global settings and possibly some profile settings. The profile's that are changed may or may not be currently active.
> Say we have two different panes open with different profiles (A and B).
> What happens if we change the settings for one profile's font and not the other's?
> ~~We resize the height of the terminal to account for the change in height of the win~~
>
> We should never change the window size in response to a settings change if there is more than one tab/pane open.
> > never?
Cascadia would have to maintain a mapping of which components have which profiles:
```csharp
class CascadiaTerminalInstance
{
GUID ProfileGuid;
UWPTerminalComponent component;
}
```
Then, when the settings are closed, it'll enumerate all of the components it has loaded, and apply the updated settings to them. It'll do this by looking up the profile GUID of the component, then getting the `ApplicationSettings` for the profile, then calling `UpdateSettings` on the component.
~~We need to have a way so that only the currently foreground component can change the window size.~~
I don't like that - if we change the font size, we should just recalculate how many characters can fit in the current window size.
## Questions / TODO
* How does this interplay with setting properties of the terminal component in XAML?
* I would think that the component would load the XAML properties first, and if the controlling application calls `UpdateSettings` on the component, then those in-XAML properties would likely get overwritten.
* It's not necessary to create the component with a `IComponentSettings`, nor is it necessary to call `UpdateSettings`. If you wanted to create a trivial settings-less terminal component entriely in XAML, go right ahead.
* Any settings that *are* exposed through XAML properties *should* also be exposed in the component's settings implementation as well.
* Can that be enforced any way? I doubt it.

26
doc/submitting_code.md Normal file
View File

@ -0,0 +1,26 @@
# Branches in Openconsole
In Openconsole, `dev/main` is the master branch for the repo.
Any branch that begins with `dev/` is recognized by our CI system and will automatically run x86 and amd64 builds and run our unit and feature tests. For feature branchs the pattern we use is `dev/<alias>/<whatever you want here>`. ex. `dev/austdi/SomeCoolUnicodeFeature`. The important parts are the dev prefix and your alias.
`inbox` is a special branch that coordinates Openconsole code to the main OS repo.
The code will be checked into the OS repo at `/onecore/windows/core/console/open`. It would be prudent to make sure that directory builds in razzle with your submitted changes.
# Code Submission Process
Because we build outside of the OS repo, we need a way to get code back into it once it's been merged into `dev/main`. This is done by cherry-picking the PR to the `inbox` branch once it has been merged (and preferably squashed) into `dev/main`. We have a tool called Git2Git that listens for new merges into `inbox` and replicates the commits over to the OS repo. Feel free to approve and complete the `inbox` PR yourself. About a minute after the `inbox` PR is submitted, Git2Git will create a PR in the OS repo under the alias `miniksa`. It will automatically target the OS branch we're using at the time, it just needs you to go approve and complete it. Once that merge is completed it is a good idea to build the OS branch with the new code in it to make sure that the PR won't be the cause of a build break that evening.
## What to do when cherry-picking to inbox fails
Sometimes VSTS doesn't want to allow a cherry pick to the inbox branch. It might have a valid reason or it might just be finicky. You'll need to complete the merge manually on a local machine. The steps are:
1. make sure you have pulled the latest commits for the `dev/main` and `inbox` branches
2. make a new branch from inbox
3. cherry-pick the commits from the PR to the newly created branch (this is easier if you squashed your commits when you merged into `dev/main`
4. fix any merge conficts and commit
5. push the new branch to the remote
6. create a new PR of that branch in `inbox`
7. complete PR and continue on to completing the auto-created PR in the OS repo

35
doc/virtual-dtors.md Normal file
View File

@ -0,0 +1,35 @@
# Virtual Destructors for Interfaces
* author: Mike Griese __migrie__
* created on: 2019-Feb-20
As you look through the code, you may come across patterns that look like the following:
``` c++
class IRenderData
{
public:
virtual ~IRenderData() = 0;
// methods
};
inline IRenderData::~IRenderData() {}
```
You may ask yourself, why is the destructor deleted, then later defined to the
default destructor? This is a good question, because it seems both unintuitive
and unnecessary. However, if you don't define your interfaces exactly like
this, then sometimes on object destruction, the interface's dtor will be
called instead of the destructor for the base class. There is other
strangeness that can occur as well, the details of which escape my memory from
when @austdi and I first investigaved this early 2018.
The end result of not defining your interfaces exacly like this will be that
occasionally, when destructing objects, you'll get a segfault.
To check that this behavior works, I direct your attention to the VtIoTests.
There are a bunch of tests in that module that create objects, then delete
them, to make sure that they won't ever crash.

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\common.openconsole.props" Condition="'$(OpenConsoleDir)'==''" />
<Import Project="$(OpenConsoleDir)src\wap-common.build.pre.props" />
<PropertyGroup Label="Configuration">
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17134.0</TargetPlatformMinVersion>
<!--
These two properties are very important!
Without them, msbuild will stomp MinVersion and MaxVersionTested in the
Package.appxmanifest and replace them with whatever our values for
TargetPlatformMinVersion and TargetPlatformVersion are.
-->
<AppxOSMinVersionReplaceManifestVersion>false</AppxOSMinVersionReplaceManifestVersion>
<AppxOSMaxVersionTestedReplaceManifestVersion>false</AppxOSMaxVersionTestedReplaceManifestVersion>
<!-- In a WAP project, this suppresses a spurious dependency on the non-Desktop VCLibs. -->
<IncludeGetResolvedSDKReferences>false</IncludeGetResolvedSDKReferences>
<!-- Suppress the inclusion of Windows.winmd in the appx. -->
<SkipUnionWinmd>true</SkipUnionWinmd>
</PropertyGroup>
<PropertyGroup>
<ProjectGuid>2D310963-F3E0-4EE5-8AC6-FBC94DCC3310</ProjectGuid>
<EntryPointExe>OpenConsole.exe</EntryPointExe>
<EntryPointProjectUniqueName>..\..\src\host\exe\Host.EXE.vcxproj</EntryPointProjectUniqueName>
</PropertyGroup>
<PropertyGroup>
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
</PropertyGroup>
<PropertyGroup Condition="!Exists('OpenConsolePackage_TemporaryKey.pfx')">
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
<AppxBundle>Never</AppxBundle>
</PropertyGroup>
<PropertyGroup Condition="Exists('OpenConsolePackage_TemporaryKey.pfx')">
<AppxPackageSigningEnabled>true</AppxPackageSigningEnabled>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<PackageCertificateKeyFile>OpenConsolePackage_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup>
<ItemGroup Condition="Exists('OpenConsolePackage_TemporaryKey.pfx')">
<None Include="OpenConsolePackage_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="images\LockScreenLogo.scale-200.png" />
<Content Include="images\Square150x150Logo.scale-200.png" />
<Content Include="images\Square44x44Logo.scale-200.png" />
<Content Include="images\Square44x44Logo.targetsize-16_altform-unplated.png" />
<Content Include="images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="images\Square44x44Logo.targetsize-32_altform-unplated.png" />
<Content Include="images\Square44x44Logo.targetsize-48_altform-unplated.png" />
<Content Include="images\Square44x44Logo.targetsize-256_altform-unplated.png" />
<Content Include="images\StoreLogo.png" />
<Content Include="images\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<Import Project="$(OpenConsoleDir)src\wap-common.build.post.props" />
<ItemGroup>
<ProjectReference Include="..\..\src\host\exe\Host.EXE.vcxproj" />
<ProjectReference Include="..\..\src\propsheet\propsheet.vcxproj" />
</ItemGroup>
<Target Name="OpenConsoleStompSourceProjectForWapProject" BeforeTargets="_ConvertItems">
<ItemGroup>
<_TemporaryFilteredWapProjOutput Include="@(_FilteredNonWapProjProjectOutput)" />
<_FilteredNonWapProjProjectOutput Remove="@(_FilteredNonWapProjProjectOutput)" />
<_FilteredNonWapProjProjectOutput Include="@(_TemporaryFilteredWapProjOutput)">
<SourceProject></SourceProject> <!-- Blank SourceProject, which WapProj uses to name subdirectories. -->
</_FilteredNonWapProjProjectOutput>
</ItemGroup>
</Target>
</Project>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4" IgnorableNamespaces="uap mp rescap">
<Identity Name="Microsoft.WindowsConsoleHost" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" Version="0.9.0.0" />
<Properties>
<DisplayName>Windows Console (Preview)</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Logo>images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="OpenConsole.exe" EntryPoint="$targetentrypoint$">
<Extensions>
<uap3:Extension Category="windows.appExecutionAlias" EntryPoint="Windows.FullTrustApplication" Executable="OpenConsole.exe">
<uap3:AppExecutionAlias>
<desktop:ExecutionAlias Alias="OpenConsole.exe" />
<desktop:ExecutionAlias Alias="confans.exe" />
</uap3:AppExecutionAlias>
</uap3:Extension>
</Extensions>
<uap:VisualElements DisplayName="Windows Console (Preview)" Description="The Windows Console, but actually fun!" BackgroundColor="transparent" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png">
</uap:DefaultTile>
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 697 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

BIN
res/console.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
res/truetype.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<InstrumentationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Instrumentation>
<Regions>
<!-- The RegionRoot and Region GUID are made up. Make some up. -->
<RegionRoot Guid="{ff1020e3-3f3a-3656-44a0-096b0b9b575a}" Name="TAEF">
<Region Guid="{e1f18b03-d49c-6f10-3753-2dc36fa663f1}" Name="TestRun">
<Start>
<!-- This GUID corresponds to one of the TAEF providers that will send this start/stop event pair. -->
<Event Provider="{70d27130-f2f3-4365-b790-d31223254ef4}" Name="RunTest_TestRunScope" Opcode="1"/>
</Start>
<Stop>
<Event Provider="{70d27130-f2f3-4365-b790-d31223254ef4}" Name="RunTest_TestRunScope" Opcode="2"/>
</Stop>
<Match>
<Event>
<Payload FieldName="ScopeName"/>
</Event>
</Match>
<Naming>
<PayloadBased NameField="ScopeName"/>
</Naming>
<Metadata>
<!-- At a bare minimum, you must collect something to get the wall time measurement. -->
<!-- The WinPerf team recommended collecting CPU if you don't care about anything else. -->
<WinperfWPAPreset.1>CPU</WinperfWPAPreset.1>
<WinperfWPAPreset.1.ProcessName>te.processhost.exe</WinperfWPAPreset.1.ProcessName>
</Metadata>
</Region>
<!-- Again, this GUID is just straight up made up. -->
<!-- Also, just keep making regions. There's also a provision to stack a region inside a region. -->
<!-- Go look up "Region of Interest" files in respect to WPA to learn more. -->
<Region Guid="{A7E0E48F-F95D-49A9-83F5-560E8A0279FB}" Name="ApiCall">
<Start>
<!-- This GUID corresponds to Console Host provider which will send the start/stop pair. -->
<Event Provider="{fe1ff234-1f09-50a8-d38d-c44fab43e818}" Name="ApiCall" Opcode="1"/>
</Start>
<Stop>
<Event Provider="{fe1ff234-1f09-50a8-d38d-c44fab43e818}" Name="ApiCall" Opcode="2"/>
</Stop>
<Match>
<Event>
<Payload FieldName="ApiName"/>
</Event>
</Match>
<Naming>
<PayloadBased NameField="ApiName"/>
</Naming>
<Metadata>
<WinperfWPAPreset.1>CPU</WinperfWPAPreset.1>
<!-- Semicolon delimiting the process names (or any other field) is OK here. -->
<WinperfWPAPreset.1.ProcessName>conhost.exe;openconsole.exe</WinperfWPAPreset.1.ProcessName>
<!-- Just keep incrementing the numbers. See the OSGWiki on WinPerf for the valid preset names. -->
<!-- https://osgwiki.com/wiki/Winperf#Leveraging_Built-In_Resource_Utilization_Metrics -->
<!-- DO NOTE: Using a preset here isn't the end of it. This is just specifying that we're interested in it. -->
<!-- You must also go change the .wprp to COLLECT the relevant data in the first place. -->
<WinperfWPAPreset.2>Commit</WinperfWPAPreset.2>
<WinperfWPAPreset.2.ProcessName>conhost.exe;openconsole.exe</WinperfWPAPreset.2.ProcessName>
</Metadata>
</Region>
</RegionRoot>
</Regions>
</Instrumentation>
</InstrumentationManifest>

105
src/ConsolePerf.wprp Normal file
View File

@ -0,0 +1,105 @@
<WindowsPerformanceRecorder Version="1.0" Comments="Test" Company="Microsoft Corporation" Copyright="Microsoft Corporation">
<Profiles>
<SystemCollector Id="SystemCollector_ConsolePerfSystemCollectorInFileLarge">
<BufferSize Value="1024"/>
<Buffers Value="100"/>
</SystemCollector>
<!-- Leave this system provider alone. It's for environmental statistics by the plugin only -->
<SystemProvider Id="SystemProvider_Winperf_Environment_Light">
<Keywords Operation="Add">
<Keyword Value="CpuConfig"/>
</Keywords>
</SystemProvider>
<!-- This one is our system provider to customize as we see fit. -->
<SystemProvider Id="SystemProvider_ConsolePerf_Verbose" Base="SystemProvider_Base">
<Keywords Operation="Add">
<!-- Add additional kernel system collection here if we decide we need it for the regions of interest file -->
<Keyword Value="CSwitch"/>
<Keyword Value="MemoryInfo"/>
<Keyword Value="MemoryInfoWS"/>
<Keyword Value="VirtualAllocation"/>
</Keywords>
</SystemProvider>
<!-- Then add all the event providers we might possibly need. The first batch up here is boilerplate ones -->
<EventProvider Id="EventProvider-Microsoft.OSGENG.Testing.TaefEngine" Name="70d27130-f2f3-4365-b790-d31223254ef4"/>
<EventProvider Id="EventProvider-Microsoft-Windows-TestExecution" Name="Microsoft-Windows-TestExecution"/>
<EventProvider Id="EventProvider-Microsoft.Windows.TestExecution.WexLogger" Name="40c4df8b-00a9-5159-62bc-9bbc5ee78a29"/>
<EventProvider Id="EventProvider-Microsoft-Windows-WinPerf" Name="7dba59f2-a1ff-40f0-b9f1-34b7531e9580"/>
<EventProvider Id="EventProvider-Microsoft.Windows.WinPerf" Name="BE6F04EA-3488-4543-8082-24843EAEC303"/>
<EventProvider Id="EventProvider-Census" Name="262CDE7A-5C84-46CF-9420-94963791EF69"/>
<!-- These providers are relevant to specific Regions of Interest -->
<EventProvider Id="EventProvider-Microsoft-Windows-Kernel-Memory" Name="Microsoft-Windows-Kernel-Memory"/>
<EventProvider Id="EventProvider_Microsoft-Windows-Kernel-Power" Name="331c3b3a-2005-44c2-ac5e-77220c37d6b4" NonPagedMemory="true">
<Keywords>
<Keyword Value="0x8000000000000000" />
</Keywords>
<CaptureStateOnSave>
<Keyword Value="0x80"/>
</CaptureStateOnSave>
</EventProvider>
<!-- Add console providers here -->
<EventProvider Id="EventProvider-Microsoft.Windows.Console.Launcher" Name="770aa552-671a-5e97-579b-151709ec0dbd"/>
<EventProvider Id="EventProvider-Microsoft.Windows.Console.Host" Name="fe1ff234-1f09-50a8-d38d-c44fab43e818"/>
<EventProvider Id="EventProvider-Microsoft.Windows.Console.Server" Name="1A541C01-589A-496E-85A7-A9E02170166D"/>
<EventProvider Id="EventProvider-Microsoft.Windows.Console.VirtualTerminal.Parser" Name="c9ba2a84-d3ca-5e19-2bd6-776a0910cb9d"/>
<EventProvider Id="EventProvider-Microsoft.Windows.Console.Render.VtEngine" Name="c9ba2a95-d3ca-5e19-2bd6-776a0910cb9d"/>
<!-- Now define some profiles. We'll call them by ID when collecting. Also, the Base is where it is inheriting from and is a .wprpi file built... -->
<!-- ... into WPR automatically. Go look in the WPR install directory or in the documentation to find it. -->
<Profile Id="ConsolePerf.Verbose.File" Base="GeneralProfile.Light.File" LoggingMode="File" Name="ConsolePerfProfile" DetailLevel="Verbose" Description="Console Performance default profile">
<Collectors Operation="Add">
<SystemCollectorId Value="SystemCollector_ConsolePerfSystemCollectorInFileLarge">
<!-- You don't have to change anything here when system keywords are added above. -->
<!-- Kernel collection is a bit more unified than user collection of events. -->
<SystemProviderId Value="SystemProvider_ConsolePerf_Verbose"/>
</SystemCollectorId>
<EventCollectorId Value="EventCollector_WPREventCollectorInFile">
<EventProviders Operation="Add">
<!-- Anything we need to collect for our perf test has to be referenced again here. -->
<EventProviderId Value="EventProvider-Microsoft.OSGENG.Testing.TaefEngine"/>
<EventProviderId Value="EventProvider-Microsoft-Windows-TestExecution"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.TestExecution.WexLogger"/>
<EventProviderId Value="EventProvider-Microsoft-Windows-WinPerf"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.WinPerf"/>
<EventProviderId Value="EventProvider-Microsoft-Windows-Kernel-Memory"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.Console.Launcher"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.Console.Host"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.Console.Server"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.Console.VirtualTerminal.Parser"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.Console.Render.VtEngine"/>
</EventProviders>
</EventCollectorId>
</Collectors>
</Profile>
<!-- Leave everything below here alone. They're needed for WinPerf to collect environmental census information -->
<Profile Id="WinPerfEnvironment.Light.File" Base="" LoggingMode="File" Name="WinPerfEnvironment" DetailLevel="Light" Description="WinPerf environment profile">
<Collectors Operation="Add">
<SystemCollectorId Value="SystemCollector_WPRSystemCollectorInFile">
<SystemProviderId Value="SystemProvider_Winperf_Environment_Light" />
</SystemCollectorId>
<EventCollectorId Value="EventCollector_WPREventCollectorInFile">
<EventProviders Operation="Add">
<EventProviderId Value="EventProvider-Census"/>
<EventProviderId Value="EventProvider_Microsoft-Windows-Kernel-Power"/>
<EventProviderId Value="EventProvider-Microsoft.OSGENG.Testing.TaefEngine"/>
<EventProviderId Value="EventProvider-Microsoft-Windows-TestExecution"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.TestExecution.WexLogger"/>
<EventProviderId Value="EventProvider-Microsoft-Windows-WinPerf"/>
<EventProviderId Value="EventProvider-Microsoft.Windows.WinPerf"/>
</EventProviders>
</EventCollectorId>
</Collectors>
</Profile>
<Profile Id="WinPerfEnvironment.Light.Memory" Base="WinPerfEnvironment.Light.File" LoggingMode="Memory" Name="WinPerfEnvironment" DetailLevel="Light" Description="WinPerf environment profile">
<Collectors Operation="Add">
<SystemCollectorId Value="SystemCollector_WPRSystemCollectorInFile">
<BufferSize Value="1024"/>
<Buffers Value="5" PercentageOfTotalMemory="true"/>
</SystemCollectorId>
<EventCollectorId Value="EventCollector_WPREventCollectorInFile">
<BufferSize Value="1024"/>
<Buffers Value="3" PercentageOfTotalMemory="true"/>
</EventCollectorId>
</Collectors>
</Profile>
</Profiles>
</WindowsPerformanceRecorder>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Console Rules" Description="These rules enforce static analysis on console code." ToolsVersion="15.0">
<Include Path="cppcorecheckrules.ruleset" Action="Default" />
</RuleSet>

3
src/buffer/dirs Normal file
View File

@ -0,0 +1,3 @@
DIRS=out \

583
src/buffer/out/AttrRow.cpp Normal file
View File

@ -0,0 +1,583 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "AttrRow.hpp"
// Routine Description:
// - constructor
// Arguments:
// - cchRowWidth - the length of the default text attribute
// - attr - the default text attribute
// Return Value:
// - constructed object
// Note: will throw exception if unable to allocate memory for text attribute storage
ATTR_ROW::ATTR_ROW(const UINT cchRowWidth, const TextAttribute attr)
{
_list.push_back(TextAttributeRun(cchRowWidth, attr));
_cchRowWidth = cchRowWidth;
}
// Routine Description:
// - Sets all properties of the ATTR_ROW to default values
// Arguments:
// - attr - The default text attributes to use on text in this row.
void ATTR_ROW::Reset(const TextAttribute attr)
{
_list.clear();
_list.push_back(TextAttributeRun(_cchRowWidth, attr));
}
// Routine Description:
// - Takes an existing row of attributes, and changes the length so that it fills the NewWidth.
// If the new size is bigger, then the last attr is extended to fill the NewWidth.
// If the new size is smaller, the runs are cut off to fit.
// Arguments:
// - oldWidth - The original width of the row.
// - newWidth - The new width of the row.
// Return Value:
// - <none>, throws exceptions on failures.
void ATTR_ROW::Resize(const size_t newWidth)
{
THROW_HR_IF(E_INVALIDARG, 0 == newWidth);
// Easy case. If the new row is longer, increase the length of the last run by how much new space there is.
if (newWidth > _cchRowWidth)
{
// Get the attribute that covers the final column of old width.
const auto runPos = FindAttrIndex(_cchRowWidth - 1, nullptr);
auto& run = _list[runPos];
// Extend its length by the additional columns we're adding.
run.SetLength(run.GetLength() + newWidth - _cchRowWidth);
// Store that the new total width we represent is the new width.
_cchRowWidth = newWidth;
}
// harder case: new row is shorter.
else
{
// Get the attribute that covers the final column of the new width
size_t CountOfAttr = 0;
const auto runPos = FindAttrIndex(newWidth - 1, &CountOfAttr);
auto& run = _list[runPos];
// CountOfAttr was given to us as "how many columns left from this point forward are covered by the returned run"
// So if the original run was B5 covering a 5 size OldWidth and we have a NewWidth of 3
// then when we called FindAttrIndex, it returned the B5 as the pIndexedRun and a 2 for how many more segments it covers
// after and including the 3rd column.
// B5-2 = B3, which is what we desire to cover the new 3 size buffer.
run.SetLength(run.GetLength() - CountOfAttr + 1);
// Store that the new total width we represent is the new width.
_cchRowWidth = newWidth;
// Erase segments after the one we just updated.
_list.erase(_list.cbegin() + runPos + 1, _list.cend());
// NOTE: Under some circumstances here, we have leftover run segments in memory or blank run segments
// in memory. We're not going to waste time redimensioning the array in the heap. We're just noting that the useful
// portions of it have changed.
}
}
// Routine Description:
// - returns a copy of the TextAttribute at the specified column
// Arguments:
// - column - the column to get the attribute for
// Return Value:
// - the text attribute at column
// Note:
// - will throw on error
TextAttribute ATTR_ROW::GetAttrByColumn(const size_t column) const
{
return GetAttrByColumn(column, nullptr);
}
// Routine Description:
// - returns a copy of the TextAttribute at the specified column
// Arguments:
// - column - the column to get the attribute for
// - pApplies - if given, fills how long this attribute will apply for
// Return Value:
// - the text attribute at column
// Note:
// - will throw on error
TextAttribute ATTR_ROW::GetAttrByColumn(const size_t column,
size_t* const pApplies) const
{
THROW_HR_IF(E_INVALIDARG, column >= _cchRowWidth);
const auto runPos = FindAttrIndex(column, pApplies);
return _list[runPos].GetAttributes();
}
// Routine Description:
// - reports how many runs we have stored (to be used for some optimizations
// Return Value:
// - Count of runs. 1 means we have 1 color to represent the entire row.
size_t ATTR_ROW::GetNumberOfRuns() const noexcept
{
return _list.size();
}
// Routine Description:
// - This routine finds the nth attribute in this ATTR_ROW.
// Arguments:
// - index - which attribute to find
// - applies - on output, contains corrected length of indexed attr.
// for example, if the attribute string was { 5, BLUE } and the requested
// index was 3, CountOfAttr would be 2.
// Return Value:
// - const reference to attribute run object
size_t ATTR_ROW::FindAttrIndex(const size_t index, size_t* const pApplies) const
{
FAIL_FAST_IF(!(index < _cchRowWidth)); // The requested index cannot be longer than the total length described by this set of Attrs.
size_t cTotalLength = 0;
FAIL_FAST_IF(!(_list.size() > 0)); // There should be a non-zero and positive number of items in the array.
// Scan through the internal array from position 0 adding up the lengths that each attribute applies to
auto runPos = _list.cbegin();
do
{
cTotalLength += runPos->GetLength();
if (cTotalLength > index)
{
// If we've just passed up the requested index with the length we added, break early
break;
}
runPos++;
} while (runPos < _list.cend());
// we should have broken before falling out the while case.
// if we didn't break, then this ATTR_ROW wasn't filled with enough attributes for the entire row of characters
FAIL_FAST_IF(runPos >= _list.cend());
// The remaining iterator position is the position of the attribute that is applicable at the position requested (index)
// Calculate its remaining applicability if requested
// The length on which the found attribute applies is the total length seen so far minus the index we were searching for.
FAIL_FAST_IF(!(cTotalLength > index)); // The length of all attributes we counted up so far should be longer than the index requested or we'll underflow.
if (nullptr != pApplies)
{
const auto attrApplies = cTotalLength - index;
FAIL_FAST_IF(!(attrApplies > 0)); // An attribute applies for >0 characters
// MSFT: 17130145 - will restore this and add a better assert to catch the real issue.
//FAIL_FAST_IF(!(attrApplies <= _cchRowWidth)); // An attribute applies for a maximum of the total length available to us
*pApplies = attrApplies;
}
return runPos - _list.cbegin();
}
// Routine Description:
// - Sets the attributes (colors) of all character positions from the given position through the end of the row.
// Arguments:
// - iStart - Starting index position within the row
// - attr - Attribute (color) to fill remaining characters with
// Return Value:
// - <none>
bool ATTR_ROW::SetAttrToEnd(const UINT iStart, const TextAttribute attr)
{
size_t const length = _cchRowWidth - iStart;
const TextAttributeRun run(length, attr);
return SUCCEEDED(InsertAttrRuns({ &run, 1 }, iStart, _cchRowWidth - 1, _cchRowWidth));
}
// Routine Description:
// - Replaces all runs in the row with the given wToBeReplacedAttr with the new
// attribute wReplaceWith. This method is used for replacing specifically
// legacy attributes.
// Arguments:
// - wToBeReplacedAttr - the legacy attribute to replace in this row.
// - wReplaceWith - the new value for the matching runs' attributes.
// Return Value:
// <none>
void ATTR_ROW::ReplaceLegacyAttrs(_In_ WORD wToBeReplacedAttr, _In_ WORD wReplaceWith) noexcept
{
TextAttribute ToBeReplaced;
ToBeReplaced.SetFromLegacy(wToBeReplacedAttr);
TextAttribute ReplaceWith;
ReplaceWith.SetFromLegacy(wReplaceWith);
ReplaceAttrs(ToBeReplaced, ReplaceWith);
}
// Method Description:
// - Replaces all runs in the row with the given toBeReplacedAttr with the new
// attribute replaceWith.
// Arguments:
// - toBeReplacedAttr - the attribute to replace in this row.
// - replaceWith - the new value for the matching runs' attributes.
// Return Value:
// - <none>
void ATTR_ROW::ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAttribute& replaceWith) noexcept
{
for (auto& run : _list)
{
if (run.GetAttributes() == toBeReplacedAttr)
{
run.SetAttributes(replaceWith);
}
}
}
// Routine Description:
// - Takes a array of attribute runs, and inserts them into this row from startIndex to endIndex.
// - For example, if the current row was was [{4, BLUE}], the merge string
// was [{ 2, RED }], with (StartIndex, EndIndex) = (1, 2),
// then the row would modified to be = [{ 1, BLUE}, {2, RED}, {1, BLUE}].
// Arguments:
// - rgInsertAttrs - The array of attrRuns to merge into this row.
// - cInsertAttrs - The number of elements in rgInsertAttrs
// - iStart - The index in the row to place the array of runs.
// - iEnd - the final index of the merge runs
// - BufferWidth - the width of the row.
// Return Value:
// - STATUS_NO_MEMORY if there wasn't enough memory to insert the runs
// otherwise STATUS_SUCCESS if we were successful.
[[nodiscard]]
HRESULT ATTR_ROW::InsertAttrRuns(const std::basic_string_view<TextAttributeRun> newAttrs,
const size_t iStart,
const size_t iEnd,
const size_t cBufferWidth)
{
// Definitions:
// Existing Run = The run length encoded color array we're already storing in memory before this was called.
// Insert Run = The run length encoded color array that someone is asking us to inject into our stored memory run.
// New Run = The run length encoded color array that we have to allocate and rebuild to store internally
// which will replace Existing Run at the end of this function.
// Example:
// cBufferWidth = 10.
// Existing Run: R3 -> G5 -> B2
// Insert Run: Y1 -> N1 at iStart = 5 and iEnd = 6
// (rgInsertAttrs is a 2 length array with Y1->N1 in it and cInsertAttrs = 2)
// Final Run: R3 -> G2 -> Y1 -> N1 -> G1 -> B2
// We'll need to know what the last valid column is for some calculations versus iEnd
// because iEnd is specified to us as an inclusive index value.
// Do the -1 math here now so we don't have to have -1s scattered all over this function.
const size_t iLastBufferCol = cBufferWidth - 1;
// If the insertion size is 1, do some pre-processing to
// see if we can get this done quickly.
if (newAttrs.size() == 1)
{
// Get the new color attribute we're trying to apply
const TextAttribute NewAttr = newAttrs.at(0).GetAttributes();
// If the existing run was only 1 element...
// ...and the new color is the same as the old, we don't have to do anything and can exit quick.
if (_list.size() == 1 && _list.at(0).GetAttributes() == NewAttr)
{
return S_OK;
}
// .. otherwise if we internally have a list of 2 and we're about to insert a single color
// it's probable that we're just walking left-to-right through the row and changing each
// cell one at a time.
// e.g.
// AAAAABBBBBBB
// AAAAAABBBBBB
// AAAAAAABBBBB
// Check for that circumstance by seeing if we're inserting a single run of the
// left side color right at the boundary and just adjust the counts in the existing
// two elements in our internal list.
else if (_list.size() == 2 && newAttrs.at(0).GetLength() == 1)
{
auto left = _list.begin();
if (iStart == left->GetLength() && NewAttr == left->GetAttributes())
{
auto right = left + 1;
left->IncrementLength();
right->DecrementLength();
// If we just reduced the right half to zero, just erase it out of the list.
if (right->GetLength() == 0)
{
_list.erase(right);
}
return S_OK;
}
}
}
// If we're about to cover the entire existing run with a new one, we can also make an optimization.
if (iStart == 0 && iEnd == iLastBufferCol)
{
// Just dump what we're given over what we have and call it a day.
_list.assign(newAttrs.cbegin(), newAttrs.cend());
return S_OK;
}
// In the worst case scenario, we will need a new run that is the length of
// The existing run in memory + The new run in memory + 1.
// This worst case occurs when we inject a new item in the middle of an existing run like so
// Existing R3->B5->G2, Insertion Y2 starting at 5 (in the middle of the B5)
// becomes R3->B2->Y2->B1->G2.
// The original run was 3 long. The insertion run was 1 long. We need 1 more for the
// fact that an existing piece of the run was split in half (to hold the latter half).
const size_t cNewRun = _list.size() + newAttrs.size() + 1;
std::vector<TextAttributeRun> newRun;
newRun.resize(cNewRun);
// We will start analyzing from the beginning of our existing run.
// Use some pointers to keep track of where we are in walking through our runs.
// Get the existing run that we'll be updating/manipulating.
const auto existingRun = _list.begin();
auto pExistingRunPos = existingRun;
const auto pExistingRunEnd = existingRun + _list.size();
auto pInsertRunPos = newAttrs.begin();
size_t cInsertRunRemaining = newAttrs.size();
auto pNewRunPos = newRun.begin();
size_t iExistingRunCoverage = 0;
// Copy the existing run into the new buffer up to the "start index" where the new run will be injected.
// If the new run starts at 0, we have nothing to copy from the beginning.
if (iStart != 0)
{
// While we're less than the desired insertion position...
while (iExistingRunCoverage < iStart)
{
// Add up how much length we can cover by copying an item from the existing run.
iExistingRunCoverage += pExistingRunPos->GetLength();
// Copy it to the new run buffer and advance both pointers.
*pNewRunPos++ = *pExistingRunPos++;
}
// When we get to this point, we've copied full segments from the original existing run
// into our new run buffer. We will have 1 or more full segments of color attributes and
// we MIGHT have to cut the last copied segment's length back depending on where the inserted
// attributes will fall in the final/new run.
// Some examples:
// - Starting with the original string R3 -> G5 -> B2
// - 1. If the insertion is Y5 at start index 3
// We are trying to get a result/final/new run of R3 -> Y5 -> B2.
// We just copied R3 to the new destination buffer and we cang skip down and start inserting the new attrs.
// - 2. If the insertion is Y3 at start index 5
// We are trying to get a result/final/new run of R3 -> G2 -> Y3 -> B2.
// We just copied R3 -> G5 to the new destination buffer with the code above.
// But the insertion is going to cut out some of the length of the G5.
// We need to fix this up below so it says G2 instead to leave room for the Y3 to fit in
// the new/final run.
// Copying above advanced the pointer to an empty cell beyond what we copied.
// Back up one cell so we can manipulate the final item we copied from the existing run to the new run.
pNewRunPos--;
// Fetch out the length so we can fix it up based on the below conditions.
size_t length = pNewRunPos->GetLength();
// If we've covered more cells already than the start of the attributes to be inserted...
if (iExistingRunCoverage > iStart)
{
// ..then subtract some of the length of the final cell we copied.
// We want to take remove the difference in distance between the cells we've covered in the new
// run and the insertion point.
// (This turns G5 into G2 from Example 2 just above)
length -= (iExistingRunCoverage - iStart);
}
// Now we're still on that "last cell copied" into the new run.
// If the color of that existing copied cell matches the color of the first segment
// of the run we're about to insert, we can just increment the length to extend the coverage.
if (pNewRunPos->GetAttributes() == pInsertRunPos->GetAttributes())
{
length += pInsertRunPos->GetLength();
// Since the color matched, we have already "used up" part of the insert run
// and can skip it in our big "memcopy" step below that will copy the bulk of the insert run.
cInsertRunRemaining--;
pInsertRunPos++;
}
// We're done manipulating the length. Store it back.
pNewRunPos->SetLength(length);
// Now that we're done adjusting the last copied item, advance the pointer into a fresh/blank
// part of the new run array.
pNewRunPos++;
}
// Bulk copy the majority (or all, depending on circumstance) of the insert run into the final run buffer.
std::copy_n(pInsertRunPos, cInsertRunRemaining, pNewRunPos);
// Advance the new run pointer into the position just after everything we copied.
pNewRunPos += cInsertRunRemaining;
// We're technically done with the insert run now and have 0 remaining, but won't bother updating its pointers
// and counts any further because we won't use them.
// Now we need to move our pointer for the original existing run forward and update our counts
// on how many cells we could have copied from the source before finishing off the new run.
while (iExistingRunCoverage <= iEnd)
{
FAIL_FAST_IF(!(pExistingRunPos != pExistingRunEnd));
iExistingRunCoverage += pExistingRunPos->GetLength();
pExistingRunPos++;
}
// If we still have original existing run cells remaining, copy them into the final new run.
if (pExistingRunPos != pExistingRunEnd || iExistingRunCoverage != (iEnd + 1))
{
// Back up one cell so we can inspect the most recent item copied into the new run for optimizations.
pNewRunPos--;
// We advanced the existing run pointer and its count to on or past the end of what the insertion run filled in.
// If this ended up being past the end of what the insertion run covers, we have to account for the cells after
// the insertion run but before the next piece of the original existing run.
// The example in this case is if we had...
// Existing Run = R3 -> G5 -> B2 -> X5
// Insert Run = Y2 @ iStart = 7 and iEnd = 8
// ... then at this point in time, our states would look like...
// New Run so far = R3 -> G4 -> Y2
// Existing Run Pointer is at X5
// Existing run coverage count at 3 + 5 + 2 = 10.
// However, in order to get the final desired New Run
// (which is R3 -> G4 -> Y2 -> B1 -> X5)
// we would need to grab a piece of that B2 we already skipped past.
// iExistingRunCoverage = 10. iEnd = 8. iEnd+1 = 9. 10 > 9. So we skipped something.
if (iExistingRunCoverage > (iEnd + 1))
{
// Back up the existing run pointer so we can grab the piece we skipped.
pExistingRunPos--;
// If the color matches what's already in our run, just increment the count value.
// This case is slightly off from the example above. This case is for if the B2 above was actually Y2.
// That Y2 from the existing run is the same color as the Y2 we just filled a few columns left in the final run
// so we can just adjust the final run's column count instead of adding another segment here.
if (pNewRunPos->GetAttributes() == pExistingRunPos->GetAttributes())
{
size_t length = pNewRunPos->GetLength();
length += (iExistingRunCoverage - (iEnd + 1));
pNewRunPos->SetLength(length);
}
else
{
// If the color didn't match, then we just need to copy the piece we skipped and adjust
// its length for the discrepency in columns not yet covered by the final/new run.
// Move forward to a blank spot in the new run
pNewRunPos++;
// Copy the existing run's color information to the new run
pNewRunPos->SetAttributes(pExistingRunPos->GetAttributes());
// Adjust the length of that copied color to cover only the reduced number of columns needed
// now that some have been replaced by the insert run.
pNewRunPos->SetLength(iExistingRunCoverage - (iEnd + 1));
}
// Now that we're done recovering a piece of the existing run we skipped, move the pointer forward again.
pExistingRunPos++;
}
// OK. In this case, we didn't skip anything. The end of the insert run fell right at a boundary
// in columns that was in the original existing run.
// However, the next piece of the original existing run might happen to have the same color attribute
// as the final piece of what we just copied.
// As an example...
// Existing Run = R3 -> G5 -> B2.
// Insert Run = B5 @ iStart = 3 and iEnd = 7
// New Run so far = R3 -> B5
// New Run desired when done = R3 -> B7
// Existing run pointer is on B2.
// We want to merge the 2 from the B2 into the B5 so we get B7.
else if (pNewRunPos->GetAttributes() == pExistingRunPos->GetAttributes())
{
// Add the value from the existing run into the current new run position.
size_t length = pNewRunPos->GetLength();
length += pExistingRunPos->GetLength();
pNewRunPos->SetLength(length);
// Advance the existing run position since we consumed its value and merged it in.
pExistingRunPos++;
}
// OK. We're done inspecting the most recently copied cell for optimizations.
pNewRunPos++;
// Now bulk copy any segments left in the original existing run
if (pExistingRunPos < pExistingRunEnd)
{
std::copy_n(pExistingRunPos, (pExistingRunEnd - pExistingRunPos), pNewRunPos);
// Fix up the end pointer so we know where we are for counting how much of the new run's memory space we used.
pNewRunPos += (pExistingRunEnd - pExistingRunPos);
}
}
// OK, phew. We're done. Now we just need to free the existing run, store the new run in its place,
// and update the count for the correct length of the new run now that we've filled it up.
newRun.erase(pNewRunPos, newRun.end());
_list.swap(newRun);
return S_OK;
}
// Routine Description:
// - packs a vector of TextAttribute into a vector of TextAttrbuteRun
// Arguments:
// - attrs - text attributes to pack
// Return Value:
// - packed text attribute run
std::vector<TextAttributeRun> ATTR_ROW::PackAttrs(const std::vector<TextAttribute>& attrs)
{
std::vector<TextAttributeRun> runs;
if (attrs.empty())
{
return runs;
}
for (auto attr : attrs)
{
if (runs.empty() || runs.back().GetAttributes() != attr)
{
const TextAttributeRun run(1, attr);
runs.push_back(run);
}
else
{
runs.back().SetLength(runs.back().GetLength() + 1);
}
}
return runs;
}
ATTR_ROW::const_iterator ATTR_ROW::begin() const noexcept
{
return AttrRowIterator(this);
}
ATTR_ROW::const_iterator ATTR_ROW::end() const noexcept
{
return AttrRowIterator::CreateEndIterator(this);
}
ATTR_ROW::const_iterator ATTR_ROW::cbegin() const noexcept
{
return AttrRowIterator(this);
}
ATTR_ROW::const_iterator ATTR_ROW::cend() const noexcept
{
return AttrRowIterator::CreateEndIterator(this);
}
bool operator==(const ATTR_ROW& a, const ATTR_ROW& b) noexcept
{
return (a._list.size() == b._list.size() &&
a._list.data() == b._list.data() &&
a._cchRowWidth == b._cchRowWidth);
}

View File

@ -0,0 +1,76 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- AttrRow.hpp
Abstract:
- contains data structure for the attributes of one row of screen buffer
Author(s):
- Michael Niksa (miniksa) 10-Apr-2014
- Paul Campbell (paulcam) 10-Apr-2014
Revision History:
- From components of output.h/.c
by Therese Stowell (ThereseS) 1990-1991
- Pulled into its own file from textBuffer.hpp/cpp (AustDi, 2017)
--*/
#pragma once
#include "TextAttributeRun.hpp"
#include "AttrRowIterator.hpp"
class ATTR_ROW final
{
public:
using const_iterator = typename AttrRowIterator;
ATTR_ROW(const UINT cchRowWidth, const TextAttribute attr);
void Reset(const TextAttribute attr);
TextAttribute GetAttrByColumn(const size_t column) const;
TextAttribute GetAttrByColumn(const size_t column,
size_t* const pApplies) const;
size_t GetNumberOfRuns() const noexcept;
size_t FindAttrIndex(const size_t index,
size_t* const pApplies) const;
bool SetAttrToEnd(const UINT iStart, const TextAttribute attr);
void ReplaceLegacyAttrs(const WORD wToBeReplacedAttr, const WORD wReplaceWith) noexcept;
void ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAttribute& replaceWith) noexcept;
void Resize(const size_t newWidth);
[[nodiscard]]
HRESULT InsertAttrRuns(const std::basic_string_view<TextAttributeRun> newAttrs,
const size_t iStart,
const size_t iEnd,
const size_t cBufferWidth);
static std::vector<TextAttributeRun> PackAttrs(const std::vector<TextAttribute>& attrs);
const_iterator begin() const noexcept;
const_iterator end() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
friend bool operator==(const ATTR_ROW& a, const ATTR_ROW& b) noexcept;
friend class AttrRowIterator;
private:
std::vector<TextAttributeRun> _list;
size_t _cchRowWidth;
#ifdef UNIT_TESTING
friend class AttrRowTests;
#endif
};

View File

@ -0,0 +1,146 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "AttrRowIterator.hpp"
#include "AttrRow.hpp"
AttrRowIterator AttrRowIterator::CreateEndIterator(const ATTR_ROW* const attrRow)
{
AttrRowIterator it{ attrRow };
it._setToEnd();
return it;
}
AttrRowIterator::AttrRowIterator(const ATTR_ROW* const attrRow) :
_pAttrRow{ attrRow },
_run{ attrRow->_list.cbegin() },
_currentAttributeIndex{ 0 }
{
}
AttrRowIterator::operator bool() const noexcept
{
return _run < _pAttrRow->_list.cend();
}
bool AttrRowIterator::operator==(const AttrRowIterator& it) const
{
return (_pAttrRow == it._pAttrRow &&
_run == it._run &&
_currentAttributeIndex == it._currentAttributeIndex);
}
bool AttrRowIterator::operator!=(const AttrRowIterator& it) const
{
return !(*this == it);
}
AttrRowIterator& AttrRowIterator::operator++()
{
_increment(1);
return *this;
}
AttrRowIterator AttrRowIterator::operator++(int)
{
auto copy = *this;
_increment(1);
return copy;
}
AttrRowIterator& AttrRowIterator::operator+=(const ptrdiff_t& movement)
{
if (movement >= 0)
{
_increment(gsl::narrow<size_t>(movement));
}
else
{
_decrement(gsl::narrow<size_t>(-movement));
}
return *this;
}
AttrRowIterator& AttrRowIterator::operator-=(const ptrdiff_t& movement)
{
return this->operator+=(-movement);
}
AttrRowIterator& AttrRowIterator::operator--()
{
_decrement(1);
return *this;
}
AttrRowIterator AttrRowIterator::operator--(int)
{
auto copy = *this;
_decrement(1);
return copy;
}
const TextAttribute* AttrRowIterator::operator->() const
{
return &_run->GetAttributes();
}
const TextAttribute& AttrRowIterator::operator*() const
{
return _run->GetAttributes();
}
// Routine Description:
// - increments the index the iterator points to
// Arguments:
// - count - the amount to increment by
void AttrRowIterator::_increment(size_t count)
{
while (count > 0)
{
const size_t runLength = _run->GetLength();
if (count + _currentAttributeIndex < runLength)
{
_currentAttributeIndex += count;
return;
}
else
{
count -= runLength - _currentAttributeIndex;
++_run;
_currentAttributeIndex = 0;
}
}
}
// Routine Description:
// - decrements the index the iterator points to
// Arguments:
// - count - the amount to decrement by
void AttrRowIterator::_decrement(size_t count)
{
while (count > 0)
{
if (count <= _currentAttributeIndex)
{
_currentAttributeIndex -= count;
return;
}
else
{
count -= _currentAttributeIndex;
--_run;
_currentAttributeIndex = _run->GetLength() - 1;
}
}
}
// Routine Description:
// - sets fields on the iterator to describe the end() state of the ATTR_ROW
void AttrRowIterator::_setToEnd()
{
_run = _pAttrRow->_list.cend();
_currentAttributeIndex = 0;
}

View File

@ -0,0 +1,62 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- AttrRowIterator.hpp
Abstract:
- iterator for ATTR_ROW to walk the TextAttributes of the run
- read only iterator
Author(s):
- Austin Diviness (AustDi) 04-Jun-2018
--*/
#pragma once
#include "TextAttribute.hpp"
#include "TextAttributeRun.hpp"
class ATTR_ROW;
class AttrRowIterator final
{
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = TextAttribute;
using difference_type = std::ptrdiff_t;
using pointer = TextAttribute*;
using reference = TextAttribute&;
static AttrRowIterator CreateEndIterator(const ATTR_ROW* const attrRow);
AttrRowIterator(const ATTR_ROW* const attrRow);
operator bool() const noexcept;
bool operator==(const AttrRowIterator& it) const;
bool operator!=(const AttrRowIterator& it) const;
AttrRowIterator& operator++();
AttrRowIterator operator++(int);
AttrRowIterator& operator+=(const ptrdiff_t& movement);
AttrRowIterator& operator-=(const ptrdiff_t& movement);
AttrRowIterator& operator--();
AttrRowIterator operator--(int);
const TextAttribute* operator->() const;
const TextAttribute& operator*() const;
private:
std::vector<TextAttributeRun>::const_iterator _run;
const ATTR_ROW* _pAttrRow;
size_t _currentAttributeIndex; // index of TextAttribute within the current TextAttributeRun
void _increment(size_t count);
void _decrement(size_t count);
void _setToEnd();
};

324
src/buffer/out/CharRow.cpp Normal file
View File

@ -0,0 +1,324 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "CharRow.hpp"
#include "unicode.hpp"
#include "Row.hpp"
// Routine Description:
// - constructor
// Arguments:
// - rowWidth - the size (in wchar_t) of the char and attribute rows
// - pParent - the parent ROW
// Return Value:
// - instantiated object
// Note: will through if unable to allocate char/attribute buffers
CharRow::CharRow(size_t rowWidth, ROW* const pParent) :
_wrapForced{ false },
_doubleBytePadded{ false },
_data(rowWidth, value_type()),
_pParent{ FAIL_FAST_IF_NULL(pParent) }
{
}
// Routine Description:
// - Sets the wrap status for the current row
// Arguments:
// - wrapForced - True if the row ran out of space and we forced to wrap to the next row. False otherwise.
// Return Value:
// - <none>
void CharRow::SetWrapForced(const bool wrapForced) noexcept
{
_wrapForced = wrapForced;
}
// Routine Description:
// - Gets the wrap status for the current row
// Arguments:
// - <none>
// Return Value:
// - True if the row ran out of space and we were forced to wrap to the next row. False otherwise.
bool CharRow::WasWrapForced() const noexcept
{
return _wrapForced;
}
// Routine Description:
// - Sets the double byte padding for the current row
// Arguments:
// - fWrapWasForced - True if the row ran out of space for a double byte character and we padded out the row. False otherwise.
// Return Value:
// - <none>
void CharRow::SetDoubleBytePadded(const bool doubleBytePadded) noexcept
{
_doubleBytePadded = doubleBytePadded;
}
// Routine Description:
// - Gets the double byte padding status for the current row.
// Arguments:
// - <none>
// Return Value:
// - True if the row didn't have space for a double byte character and we were padded out the row. False otherwise.
bool CharRow::WasDoubleBytePadded() const noexcept
{
return _doubleBytePadded;
}
// Routine Description:
// - gets the size of the row, in glyph cells
// Arguments:
// - <none>
// Return Value:
// - the size of the row
size_t CharRow::size() const noexcept
{
return _data.size();
}
// Routine Description:
// - Sets all properties of the CharRowBase to default values
// Arguments:
// - sRowWidth - The width of the row.
// Return Value:
// - <none>
void CharRow::Reset()
{
for (auto& cell : _data)
{
cell.Reset();
}
_wrapForced = false;
_doubleBytePadded = false;
}
// Routine Description:
// - resizes the width of the CharRowBase
// Arguments:
// - newSize - the new width of the character and attributes rows
// Return Value:
// - S_OK on success, otherwise relevant error code
[[nodiscard]]
HRESULT CharRow::Resize(const size_t newSize) noexcept
{
try
{
const value_type insertVals;
_data.resize(newSize, insertVals);
}
CATCH_RETURN();
return S_OK;
}
typename CharRow::iterator CharRow::begin() noexcept
{
return _data.begin();
}
typename CharRow::const_iterator CharRow::cbegin() const noexcept
{
return _data.cbegin();
}
typename CharRow::iterator CharRow::end() noexcept
{
return _data.end();
}
typename CharRow::const_iterator CharRow::cend() const noexcept
{
return _data.cend();
}
// Routine Description:
// - Inspects the current internal string to find the left edge of it
// Arguments:
// - <none>
// Return Value:
// - The calculated left boundary of the internal string.
size_t CharRow::MeasureLeft() const
{
std::vector<value_type>::const_iterator it = _data.cbegin();
while (it != _data.cend() && it->IsSpace())
{
++it;
}
return it - _data.cbegin();
}
// Routine Description:
// - Inspects the current internal string to find the right edge of it
// Arguments:
// - <none>
// Return Value:
// - The calculated right boundary of the internal string.
size_t CharRow::MeasureRight() const noexcept
{
std::vector<value_type>::const_reverse_iterator it = _data.crbegin();
while (it != _data.crend() && it->IsSpace())
{
++it;
}
return _data.crend() - it;
}
void CharRow::ClearCell(const size_t column)
{
_data.at(column).Reset();
}
// Routine Description:
// - Tells you whether or not this row contains any valid text.
// Arguments:
// - <none>
// Return Value:
// - True if there is valid text in this row. False otherwise.
bool CharRow::ContainsText() const noexcept
{
for (const value_type& cell : _data)
{
if (!cell.IsSpace())
{
return true;
}
}
return false;
}
// Routine Description:
// - gets the attribute at the specified column
// Arguments:
// - column - the column to get the attribute for
// Return Value:
// - the attribute
// Note: will throw exception if column is out of bounds
const DbcsAttribute& CharRow::DbcsAttrAt(const size_t column) const
{
return _data.at(column).DbcsAttr();
}
// Routine Description:
// - gets the attribute at the specified column
// Arguments:
// - column - the column to get the attribute for
// Return Value:
// - the attribute
// Note: will throw exception if column is out of bounds
DbcsAttribute& CharRow::DbcsAttrAt(const size_t column)
{
return const_cast<DbcsAttribute&>(static_cast<const CharRow* const>(this)->DbcsAttrAt(column));
}
// Routine Description:
// - resets text data at column
// Arguments:
// - column - column index to clear text data from
// Return Value:
// - <none>
// Note: will throw exception if column is out of bounds
void CharRow::ClearGlyph(const size_t column)
{
_data.at(column).EraseChars();
}
// Routine Description:
// - returns text data at column as a const reference.
// Arguments:
// - column - column to get text data for
// Return Value:
// - text data at column
// - Note: will throw exception if column is out of bounds
const CharRow::reference CharRow::GlyphAt(const size_t column) const
{
THROW_HR_IF(E_INVALIDARG, column >= _data.size());
return { const_cast<CharRow&>(*this), column };
}
// Routine Description:
// - returns text data at column as a reference.
// Arguments:
// - column - column to get text data for
// Return Value:
// - text data at column
// - Note: will throw exception if column is out of bounds
CharRow::reference CharRow::GlyphAt(const size_t column)
{
THROW_HR_IF(E_INVALIDARG, column >= _data.size());
return { *this, column };
}
// Routine Description:
// - returns string containing text data exactly how it's stored internally, including doubling of
// leading/trailing cells.
// Arguments:
// - none
// Return Value:
// - text stored in char row
// - Note: will throw exception if out of memory
std::wstring CharRow::GetTextRaw() const
{
std::wstring wstr;
wstr.reserve(_data.size());
for (size_t i = 0; i < _data.size(); ++i)
{
auto glyph = GlyphAt(i);
for (auto it = glyph.begin(); it != glyph.end(); ++it)
{
wstr.push_back(*it);
}
}
return wstr;
}
std::wstring CharRow::GetText() const
{
std::wstring wstr;
wstr.reserve(_data.size());
for (size_t i = 0; i < _data.size(); ++i)
{
auto glyph = GlyphAt(i);
if (!DbcsAttrAt(i).IsTrailing())
{
for (auto it = glyph.begin(); it != glyph.end(); ++it)
{
wstr.push_back(*it);
}
}
}
return wstr;
}
UnicodeStorage& CharRow::GetUnicodeStorage()
{
return _pParent->GetUnicodeStorage();
}
const UnicodeStorage& CharRow::GetUnicodeStorage() const
{
return _pParent->GetUnicodeStorage();
}
// Routine Description:
// - calculates the key used by the given column of the char row to store glyph data in UnicodeStorage
// Arguments:
// - column - the column to generate the key for
// Return Value:
// - the COORD key for data access from UnicodeStorage for the column
COORD CharRow::GetStorageKey(const size_t column) const
{
return { gsl::narrow<SHORT>(column), _pParent->GetId() };
}
// Routine Description:
// - Updates the pointer to the parent row (which might change if we shuffle the rows around)
// Arguments:
// - pParent - Pointer to the parent row
void CharRow::UpdateParent(ROW* const pParent) noexcept
{
_pParent = FAIL_FAST_IF_NULL(pParent);
}

123
src/buffer/out/CharRow.hpp Normal file
View File

@ -0,0 +1,123 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- CharRow.hpp
Abstract:
- contains data structure for UCS2 encoded character data of a row
Author(s):
- Michael Niksa (miniksa) 10-Apr-2014
- Paul Campbell (paulcam) 10-Apr-2014
Revision History:
- From components of output.h/.c
by Therese Stowell (ThereseS) 1990-1991
- Pulled into its own file from textBuffer.hpp/cpp (AustDi, 2017)
--*/
#pragma once
#include "DbcsAttribute.hpp"
#include "CharRowCellReference.hpp"
#include "CharRowCell.hpp"
#include "UnicodeStorage.hpp"
class ROW;
// the characters of one row of screen buffer
// we keep the following values so that we don't write
// more pixels to the screen than we have to:
// left is initialized to screenbuffer width. right is
// initialized to zero.
//
// [ foo.bar 12-12-61 ]
// ^ ^ ^ ^
// | | | |
// Chars Left Right end of Chars buffer
class CharRow final
{
public:
using glyph_type = typename wchar_t;
using value_type = typename CharRowCell;
using iterator = typename std::vector<value_type>::iterator;
using const_iterator = typename std::vector<value_type>::const_iterator;
using reference = typename CharRowCellReference;
CharRow(size_t rowWidth, ROW* const pParent);
void SetWrapForced(const bool wrap) noexcept;
bool WasWrapForced() const noexcept;
void SetDoubleBytePadded(const bool doubleBytePadded) noexcept;
bool WasDoubleBytePadded() const noexcept;
size_t size() const noexcept;
void Reset();
[[nodiscard]]
HRESULT Resize(const size_t newSize) noexcept;
size_t MeasureLeft() const;
size_t MeasureRight() const noexcept;
void ClearCell(const size_t column);
bool ContainsText() const noexcept;
const DbcsAttribute& DbcsAttrAt(const size_t column) const;
DbcsAttribute& DbcsAttrAt(const size_t column);
void ClearGlyph(const size_t column);
std::wstring GetText() const;
// other functions implemented at the template class level
std::wstring GetTextRaw() const;
// working with glyphs
const reference GlyphAt(const size_t column) const;
reference GlyphAt(const size_t column);
// iterators
iterator begin() noexcept;
const_iterator cbegin() const noexcept;
iterator end() noexcept;
const_iterator cend() const noexcept;
UnicodeStorage& GetUnicodeStorage();
const UnicodeStorage& GetUnicodeStorage() const;
COORD GetStorageKey(const size_t column) const;
void UpdateParent(ROW* const pParent) noexcept;
friend CharRowCellReference;
friend constexpr bool operator==(const CharRow& a, const CharRow& b) noexcept;
protected:
// Occurs when the user runs out of text in a given row and we're forced to wrap the cursor to the next line
bool _wrapForced;
// Occurs when the user runs out of text to support a double byte character and we're forced to the next line
bool _doubleBytePadded;
// storage for glyph data and dbcs attributes
std::vector<value_type> _data;
// ROW that this CharRow belongs to
ROW* _pParent;
};
constexpr bool operator==(const CharRow& a, const CharRow& b) noexcept
{
return (a._wrapForced == b._wrapForced &&
a._doubleBytePadded == b._doubleBytePadded &&
a._data == b._data);
}
template<typename InputIt1, typename InputIt2>
void OverwriteColumns(InputIt1 startChars, InputIt1 endChars, InputIt2 startAttrs, CharRow::iterator outIt)
{
std::transform(startChars,
endChars,
startAttrs,
outIt,
[](const wchar_t wch, const DbcsAttribute attr)
{
return CharRow::value_type{ wch, attr };
});
}

View File

@ -0,0 +1,86 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "CharRowCell.hpp"
#include "unicode.hpp"
// default glyph value, used for reseting the character data portion of a cell
static constexpr wchar_t DefaultValue = UNICODE_SPACE;
CharRowCell::CharRowCell() :
_wch{ DefaultValue },
_attr{}
{
}
CharRowCell::CharRowCell(const wchar_t wch, const DbcsAttribute attr) :
_wch{ wch },
_attr{ attr }
{
}
// Routine Description:
// - "erases" the glyph. really sets it back to the default "empty" value
void CharRowCell::EraseChars()
{
if (_attr.IsGlyphStored())
{
_attr.SetGlyphStored(false);
}
_wch = DefaultValue;
}
// Routine Description:
// - resets this object back to the defaults it would have from the default constructor
void CharRowCell::Reset() noexcept
{
_attr.Reset();
_wch = DefaultValue;
}
// Routine Description:
// - checks if cell contains a space glyph
// Return Value:
// - true if cell contains a space glyph, false otherwise
bool CharRowCell::IsSpace() const noexcept
{
return !_attr.IsGlyphStored() && _wch == UNICODE_SPACE;
}
// Routine Description:
// - Access the DbcsAttribute for the cell
// Return Value:
// - ref to the cells' DbcsAttribute
DbcsAttribute& CharRowCell::DbcsAttr() noexcept
{
return _attr;
}
// Routine Description:
// - Access the DbcsAttribute for the cell
// Return Value:
// - ref to the cells' DbcsAttribute
const DbcsAttribute& CharRowCell::DbcsAttr() const noexcept
{
return _attr;
}
// Routine Description:
// - Access the cell's wchar field. this does not access any char data through UnicodeStorage.
// Return Value:
// - the cell's wchar field
wchar_t& CharRowCell::Char() noexcept
{
return _wch;
}
// Routine Description:
// - Access the cell's wchar field. this does not access any char data through UnicodeStorage.
// Return Value:
// - the cell's wchar field
const wchar_t& CharRowCell::Char() const noexcept
{
return _wch;
}

View File

@ -0,0 +1,60 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- CharRowCell.hpp
Abstract:
- data structure for one cell of a char row. contains the char data for one
coordinate position in the output buffer (leading/trailing information and
the char itself.
Author(s):
- Austin Diviness (AustDi) 02-May-2018
--*/
#pragma once
#include "DbcsAttribute.hpp"
#if (defined(_M_IX86) || defined(_M_AMD64))
// currently CharRowCell's fields use 3 bytes of memory, leaving the 4th byte in unused. this leads
// to a rather large amount of useless memory allocated. so instead, pack CharRowCell by bytes instead of words.
#pragma pack(push, 1)
#endif
class CharRowCell final
{
public:
CharRowCell();
CharRowCell(const wchar_t wch, const DbcsAttribute attr);
void EraseChars();
void Reset() noexcept;
bool IsSpace() const noexcept;
DbcsAttribute& DbcsAttr() noexcept;
const DbcsAttribute& DbcsAttr() const noexcept;
wchar_t& Char() noexcept;
const wchar_t& Char() const noexcept;
friend constexpr bool operator==(const CharRowCell& a, const CharRowCell& b) noexcept;
private:
wchar_t _wch;
DbcsAttribute _attr;
};
#if (defined(_M_IX86) || defined(_M_AMD64))
#pragma pack(pop)
#endif
constexpr bool operator==(const CharRowCell& a, const CharRowCell& b) noexcept
{
return (a._wch == b._wch &&
a._attr == b._attr);
}

View File

@ -0,0 +1,134 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "UnicodeStorage.hpp"
#include "CharRow.hpp"
// Routine Description:
// - assignment operator. will store extended glyph data in a separate storage location
// Arguments:
// - chars - the glyph data to store
void CharRowCellReference::operator=(const std::wstring_view chars)
{
THROW_HR_IF(E_INVALIDARG, chars.empty());
if (chars.size() == 1)
{
_cellData().Char() = chars.front();
_cellData().DbcsAttr().SetGlyphStored(false);
}
else
{
auto& storage = _parent.GetUnicodeStorage();
const auto key = _parent.GetStorageKey(_index);
storage.StoreGlyph(key, { chars.cbegin(), chars.cend() });
_cellData().DbcsAttr().SetGlyphStored(true);
}
}
// Routine Description:
// - implicit conversion to vector<wchar_t> operator.
// Return Value:
// - std::vector<wchar_t> of the glyph data in the referenced cell
CharRowCellReference::operator std::wstring_view() const
{
return _glyphData();
}
// Routine Description:
// - The CharRowCell this object "references"
// Return Value:
// - ref to the CharRowCell
CharRowCell& CharRowCellReference::_cellData()
{
return _parent._data.at(_index);
}
// Routine Description:
// - The CharRowCell this object "references"
// Return Value:
// - ref to the CharRowCell
const CharRowCell& CharRowCellReference::_cellData() const
{
return _parent._data.at(_index);
}
// Routine Description:
// - the glyph data of the referenced cell
// Return Value:
// - the glyph data
std::wstring_view CharRowCellReference::_glyphData() const
{
if (_cellData().DbcsAttr().IsGlyphStored())
{
const auto& text = _parent.GetUnicodeStorage().GetText(_parent.GetStorageKey(_index));
return { text.data(), text.size() };
}
else
{
return { &_cellData().Char(), 1 };
}
}
// Routine Description:
// - gets read-only iterator to the beginning of the glyph data
// Return Value:
// - iterator of the glyph data
CharRowCellReference::const_iterator CharRowCellReference::begin() const
{
if (_cellData().DbcsAttr().IsGlyphStored())
{
return _parent.GetUnicodeStorage().GetText(_parent.GetStorageKey(_index)).data();
}
else
{
return &_cellData().Char();
}
}
// Routine Description:
// - get read-only iterator to the end of the glyph data
// Return Value:
// - end iterator of the glyph data
CharRowCellReference::const_iterator CharRowCellReference::end() const
{
if (_cellData().DbcsAttr().IsGlyphStored())
{
const auto& chars = _parent.GetUnicodeStorage().GetText(_parent.GetStorageKey(_index));
return chars.data() + chars.size();
}
else
{
return &_cellData().Char() + 1;
}
}
bool operator==(const CharRowCellReference& ref, const std::vector<wchar_t>& glyph)
{
const DbcsAttribute& dbcsAttr = ref._cellData().DbcsAttr();
if (glyph.size() == 1 && dbcsAttr.IsGlyphStored())
{
return false;
}
else if (glyph.size() > 1 && !dbcsAttr.IsGlyphStored())
{
return false;
}
else if (glyph.size() == 1 && !dbcsAttr.IsGlyphStored())
{
return ref._cellData().Char() == glyph.front();
}
else
{
const auto& chars = ref._parent.GetUnicodeStorage().GetText(ref._parent.GetStorageKey(ref._index));
return chars == glyph;
}
}
bool operator==(const std::vector<wchar_t>& glyph, const CharRowCellReference& ref)
{
return ref == glyph;
}

View File

@ -0,0 +1,65 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- CharRowCellReference.hpp
Abstract:
- reference class for the glyph data of a char row cell
Author(s):
- Austin Diviness (AustDi) 02-May-2018
--*/
#pragma once
#include "DbcsAttribute.hpp"
#include "CharRowCell.hpp"
#include <utility>
class CharRow;
class CharRowCellReference final
{
public:
using const_iterator = const wchar_t*;
CharRowCellReference(CharRow& parent, const size_t index) :
_parent{ parent },
_index{ index }
{
}
~CharRowCellReference() = default;
CharRowCellReference(const CharRowCellReference&) = default;
CharRowCellReference(CharRowCellReference&&) = default;
void operator=(const CharRowCellReference&) = delete;
void operator=(CharRowCellReference&&) = delete;
void operator=(const std::wstring_view chars);
operator std::wstring_view() const;
const_iterator begin() const;
const_iterator end() const;
friend bool operator==(const CharRowCellReference& ref, const std::vector<wchar_t>& glyph);
friend bool operator==(const std::vector<wchar_t>& glyph, const CharRowCellReference& ref);
private:
// what char row the object belongs to
CharRow& _parent;
// the index of the cell in the parent char row
const size_t _index;
CharRowCell& _cellData();
const CharRowCell& _cellData() const;
std::wstring_view _glyphData() const;
};
bool operator==(const CharRowCellReference& ref, const std::vector<wchar_t>& glyph);
bool operator==(const std::vector<wchar_t>& glyph, const CharRowCellReference& ref);

View File

@ -0,0 +1,143 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- DbcsAttribute.hpp
Abstract:
- helper class for storing double byte character set information about a cell in the output buffer.
Author(s):
- Austin Diviness (AustDi) 26-Jan-2018
Revision History:
--*/
#pragma once
class DbcsAttribute final
{
public:
enum class Attribute : BYTE
{
Single = 0x00,
Leading = 0x01,
Trailing = 0x02
};
DbcsAttribute() noexcept :
_attribute{ Attribute::Single },
_glyphStored{ false }
{
}
DbcsAttribute(const Attribute attribute) noexcept :
_attribute{ attribute },
_glyphStored{ false }
{
}
constexpr bool IsSingle() const noexcept
{
return _attribute == Attribute::Single;
}
constexpr bool IsLeading() const noexcept
{
return _attribute == Attribute::Leading;
}
constexpr bool IsTrailing() const noexcept
{
return _attribute == Attribute::Trailing;
}
constexpr bool IsDbcs() const noexcept
{
return IsLeading() || IsTrailing();
}
constexpr bool IsGlyphStored() const noexcept
{
return _glyphStored;
}
void SetGlyphStored(const bool stored)
{
_glyphStored = stored;
}
void SetSingle() noexcept
{
_attribute = Attribute::Single;
}
void SetLeading() noexcept
{
_attribute = Attribute::Leading;
}
void SetTrailing() noexcept
{
_attribute = Attribute::Trailing;
}
void Reset() noexcept
{
SetSingle();
SetGlyphStored(false);
}
WORD GeneratePublicApiAttributeFormat() const noexcept
{
WORD publicAttribute = 0;
if (IsLeading())
{
WI_SetFlag(publicAttribute, COMMON_LVB_LEADING_BYTE);
}
if (IsTrailing())
{
WI_SetFlag(publicAttribute, COMMON_LVB_TRAILING_BYTE);
}
return publicAttribute;
}
static DbcsAttribute FromPublicApiAttributeFormat(WORD publicAttribute)
{
// it's not valid to be both a leading and trailing byte
if (WI_AreAllFlagsSet(publicAttribute, COMMON_LVB_LEADING_BYTE | COMMON_LVB_TRAILING_BYTE))
{
THROW_HR(E_INVALIDARG);
}
DbcsAttribute attr;
if (WI_IsFlagSet(publicAttribute, COMMON_LVB_LEADING_BYTE))
{
attr.SetLeading();
}
else if (WI_IsFlagSet(publicAttribute, COMMON_LVB_TRAILING_BYTE))
{
attr.SetTrailing();
}
return attr;
}
friend constexpr bool operator==(const DbcsAttribute& a, const DbcsAttribute& b) noexcept;
private:
Attribute _attribute : 2;
bool _glyphStored : 1;
#ifdef UNIT_TESTING
friend class TextBufferTests;
#endif
};
constexpr bool operator==(const DbcsAttribute& a, const DbcsAttribute& b) noexcept
{
return a._attribute == b._attribute;
}
static_assert(sizeof(DbcsAttribute) == sizeof(BYTE), "DbcsAttribute should be one byte big. if this changes then it needs"
" either an implicit conversion to a BYTE or an update to all places that assume it's a byte big");

View File

@ -0,0 +1,118 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "OutputCell.hpp"
#include "../../types/inc/GlyphWidth.hpp"
#include "../../types/inc/convert.hpp"
#include "../../inc/conattrs.hpp"
static constexpr TextAttribute InvalidTextAttribute{ INVALID_COLOR, INVALID_COLOR };
OutputCell::OutputCell() :
_text{},
_dbcsAttribute{},
_textAttribute{ InvalidTextAttribute },
_behavior{ TextAttributeBehavior::Stored }
{
}
OutputCell::OutputCell(const std::wstring_view charData,
const DbcsAttribute dbcsAttribute,
const TextAttributeBehavior behavior) :
_text{ UNICODE_INVALID },
_dbcsAttribute{ dbcsAttribute },
_textAttribute{ InvalidTextAttribute },
_behavior{ behavior }
{
THROW_HR_IF(E_INVALIDARG, charData.empty());
_setFromStringView(charData);
_setFromBehavior(behavior);
}
OutputCell::OutputCell(const std::wstring_view charData,
const DbcsAttribute dbcsAttribute,
const TextAttribute textAttribute) :
_text{ UNICODE_INVALID },
_dbcsAttribute{ dbcsAttribute },
_textAttribute{ textAttribute },
_behavior{ TextAttributeBehavior::Stored }
{
THROW_HR_IF(E_INVALIDARG, charData.empty());
_setFromStringView(charData);
}
OutputCell::OutputCell(const CHAR_INFO& charInfo) :
_text{ UNICODE_INVALID },
_dbcsAttribute{},
_textAttribute{ InvalidTextAttribute },
_behavior{ TextAttributeBehavior::Stored }
{
_setFromCharInfo(charInfo);
}
OutputCell::OutputCell(const OutputCellView& cell)
{
_setFromOutputCellView(cell);
}
const std::wstring_view OutputCell::Chars() const noexcept
{
return _text;
}
void OutputCell::SetChars(const std::wstring_view chars)
{
_setFromStringView(chars);
}
DbcsAttribute& OutputCell::DbcsAttr() noexcept
{
return _dbcsAttribute;
}
TextAttribute& OutputCell::TextAttr()
{
THROW_HR_IF(E_INVALIDARG, _behavior == TextAttributeBehavior::Current);
return _textAttribute;
}
void OutputCell::_setFromBehavior(const TextAttributeBehavior behavior)
{
THROW_HR_IF(E_INVALIDARG, behavior == TextAttributeBehavior::Stored);
}
void OutputCell::_setFromCharInfo(const CHAR_INFO& charInfo)
{
_text = charInfo.Char.UnicodeChar;
if (WI_IsFlagSet(charInfo.Attributes, COMMON_LVB_LEADING_BYTE))
{
_dbcsAttribute.SetLeading();
}
else if (WI_IsFlagSet(charInfo.Attributes, COMMON_LVB_TRAILING_BYTE))
{
_dbcsAttribute.SetTrailing();
}
_textAttribute.SetFromLegacy(charInfo.Attributes);
_behavior = TextAttributeBehavior::Stored;
}
void OutputCell::_setFromStringView(const std::wstring_view view)
{
_text = view;
}
void OutputCell::_setFromOutputCellView(const OutputCellView& cell)
{
_dbcsAttribute = cell.DbcsAttr();
_textAttribute = cell.TextAttr();
_behavior = cell.TextAttrBehavior();
const auto& view = cell.Chars();
_text = view;
}

View File

@ -0,0 +1,92 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- OutputCell.hpp
Abstract:
- Representation of all data stored in a cell of the output buffer.
- RGB color supported.
Author:
- Austin Diviness (AustDi) 20-Mar-2018
--*/
#pragma once
#include "DbcsAttribute.hpp"
#include "TextAttribute.hpp"
#include "OutputCellView.hpp"
#include <exception>
#include <variant>
class InvalidCharInfoConversionException : public std::exception
{
const char* what() noexcept
{
return "Cannot convert to CHAR_INFO without explicit TextAttribute";
}
};
class OutputCell final
{
public:
OutputCell();
OutputCell(const std::wstring_view charData,
const DbcsAttribute dbcsAttribute,
const TextAttributeBehavior behavior);
OutputCell(const std::wstring_view charData,
const DbcsAttribute dbcsAttribute,
const TextAttribute textAttribute);
OutputCell(const CHAR_INFO& charInfo);
OutputCell(const OutputCellView& view);
OutputCell(const OutputCell&) = default;
OutputCell(OutputCell&&) = default;
OutputCell& operator=(const OutputCell&) = default;
OutputCell& operator=(OutputCell&&) = default;
~OutputCell() = default;
const std::wstring_view Chars() const noexcept;
void SetChars(const std::wstring_view chars);
DbcsAttribute& DbcsAttr() noexcept;
TextAttribute& TextAttr();
constexpr const DbcsAttribute& DbcsAttr() const
{
return _dbcsAttribute;
}
const TextAttribute& TextAttr() const
{
THROW_HR_IF(E_INVALIDARG, _behavior == TextAttributeBehavior::Current);
return _textAttribute;
}
constexpr TextAttributeBehavior TextAttrBehavior() const
{
return _behavior;
}
private:
// basic_string contains a small storage internally so we don't need
// to worry about heap allocation for short strings.
std::wstring _text;
DbcsAttribute _dbcsAttribute;
TextAttribute _textAttribute;
TextAttributeBehavior _behavior;
void _setFromBehavior(const TextAttributeBehavior behavior);
void _setFromCharInfo(const CHAR_INFO& charInfo);
void _setFromStringView(const std::wstring_view view);
void _setFromOutputCellView(const OutputCellView& cell);
};

View File

@ -0,0 +1,560 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "OutputCellIterator.hpp"
#include "../../types/inc/convert.hpp"
#include "../../types/inc/Utf16Parser.hpp"
#include "../../types/inc/GlyphWidth.hpp"
#include "../../inc/conattrs.hpp"
static constexpr TextAttribute InvalidTextAttribute{ INVALID_COLOR, INVALID_COLOR };
// Routine Description:
// - This is a fill-mode iterator for one particular wchar. It will repeat forever if fillLimit is 0.
// Arguments:
// - wch - The character to use for filling
// - fillLimit - How many times to allow this value to be viewed/filled. Infinite if 0.
OutputCellIterator::OutputCellIterator(const wchar_t& wch, const size_t fillLimit) :
_mode(Mode::Fill),
_currentView(s_GenerateView(wch)),
_run(),
_attr(InvalidTextAttribute),
_pos(0),
_distance(0),
_fillLimit(fillLimit)
{
}
// Routine Description:
// - This is a fill-mode iterator for one particular color. It will repeat forever if fillLimit is 0.
// Arguments:
// - attr - The color attribute to use for filling
// - fillLimit - How many times to allow this value to be viewed/filled. Infinite if 0.
OutputCellIterator::OutputCellIterator(const TextAttribute& attr, const size_t fillLimit) :
_mode(Mode::Fill),
_currentView(s_GenerateView(attr)),
_run(),
_attr(InvalidTextAttribute),
_pos(0),
_distance(0),
_fillLimit(fillLimit)
{
}
// Routine Description:
// - This is a fill-mode iterator for one particular character and color. It will repeat forever if fillLimit is 0.
// Arguments:
// - wch - The character to use for filling
// - attr - The color attribute to use for filling
// - fillLimit - How many times to allow this value to be viewed/filled. Infinite if 0.
OutputCellIterator::OutputCellIterator(const wchar_t& wch, const TextAttribute& attr, const size_t fillLimit) :
_mode(Mode::Fill),
_currentView(s_GenerateView(wch, attr)),
_run(),
_attr(InvalidTextAttribute),
_pos(0),
_distance(0),
_fillLimit(fillLimit)
{
}
// Routine Description:
// - This is a fill-mode iterator for one particular CHAR_INFO. It will repeat forever if fillLimit is 0.
// Arguments:
// - charInfo - The legacy character and color data to use for fililng (uses Unicode portion of text data)
// - fillLimit - How many times to allow this value to be viewed/filled. Infinite if 0.
OutputCellIterator::OutputCellIterator(const CHAR_INFO& charInfo, const size_t fillLimit) :
_mode(Mode::Fill),
_currentView(s_GenerateView(charInfo)),
_run(),
_attr(InvalidTextAttribute),
_pos(0),
_distance(0),
_fillLimit(fillLimit)
{
}
// Routine Description:
// - This is an iterator over a range of text only. No color data will be modified as the text is inserted.
// Arguments:
// - utf16Text - UTF-16 text range
OutputCellIterator::OutputCellIterator(const std::wstring_view utf16Text) :
_mode(Mode::LooseTextOnly),
_currentView(s_GenerateView(utf16Text)),
_run(utf16Text),
_attr(InvalidTextAttribute),
_pos(0),
_distance(0),
_fillLimit(0)
{
}
// Routine Description:
// - This is an iterator over a range text that will apply the same color to every position.
// Arguments:
// - utf16Text - UTF-16 text range
// - attribute - Color to apply over the entire range
OutputCellIterator::OutputCellIterator(const std::wstring_view utf16Text, const TextAttribute attribute) :
_mode(Mode::Loose),
_currentView(s_GenerateView(utf16Text, attribute)),
_run(utf16Text),
_attr(attribute),
_distance(0),
_pos(0),
_fillLimit(0)
{
}
// Routine Description:
// - This is an iterator over legacy colors only. The text is not modified.
// Arguments:
// - legacyAttrs - One legacy color item per cell
// - unused - useless bool to change function signature for legacyAttrs constructor because the C++ compiler in
// razzle cannot distinguish between a std::wstring_view and a std::basic_string_view<WORD>
// NOTE: This one internally casts to wchar_t because Razzle sees WORD and wchar_t as the same type
// despite that Visual Studio build can tell the difference.
OutputCellIterator::OutputCellIterator(const std::basic_string_view<WORD> legacyAttrs, const bool /*unused*/) :
_mode(Mode::LegacyAttr),
_currentView(s_GenerateViewLegacyAttr(legacyAttrs.at(0))),
_run(std::wstring_view(reinterpret_cast<const wchar_t*>(legacyAttrs.data()), legacyAttrs.size())),
_attr(InvalidTextAttribute),
_distance(0),
_pos(0),
_fillLimit(0)
{
}
// Routine Description:
// - This is an iterator over legacy cell data. We will use the unicode text and the legacy color attribute.
// Arguments:
// - charInfos - Multiple cell with unicode text and legacy color data.
OutputCellIterator::OutputCellIterator(const std::basic_string_view<CHAR_INFO> charInfos) :
_mode(Mode::CharInfo),
_currentView(s_GenerateView(charInfos.at(0))),
_run(charInfos),
_attr(InvalidTextAttribute),
_distance(0),
_pos(0),
_fillLimit(0)
{
}
// Routine Description:
// - This is an iterator over existing OutputCells with full text and color data.
// Arguments:
// - cells - Multiple cells in a run
OutputCellIterator::OutputCellIterator(const std::basic_string_view<OutputCell> cells) :
_mode(Mode::Cell),
_currentView(s_GenerateView(cells.at(0))),
_run(cells),
_attr(InvalidTextAttribute),
_distance(0),
_pos(0),
_fillLimit(0)
{
}
// Routine Description:
// - Specifies whether this iterator is valid for dereferencing (still valid underlying data)
// Return Value:
// - True if the views on dereference are valid. False if it shouldn't be dereferenced.
OutputCellIterator::operator bool() const noexcept
{
try
{
switch (_mode)
{
case Mode::Loose:
case Mode::LooseTextOnly:
{
// In lieu of using start and end, this custom iterator type simply becomes bool false
// when we run out of items to iterate over.
return _pos < std::get<std::wstring_view>(_run).length();
}
case Mode::Fill:
{
if (_fillLimit > 0)
{
return _pos < _fillLimit;
}
return true;
}
case Mode::Cell:
{
return _pos < std::get<std::basic_string_view<OutputCell>>(_run).length();
}
case Mode::CharInfo:
{
return _pos < std::get<std::basic_string_view<CHAR_INFO>>(_run).length();
}
case Mode::LegacyAttr:
{
return _pos < std::get<std::wstring_view>(_run).length();
}
default:
FAIL_FAST_HR(E_NOTIMPL);
}
}
CATCH_FAIL_FAST();
}
// Routine Description:
// - Advances the iterator one position over the underlying data source.
// Return Value:
// - Reference to self after advancement.
OutputCellIterator& OutputCellIterator::operator++()
{
// Keep track of total distance moved (cells filled)
_distance++;
switch (_mode)
{
case Mode::Loose:
{
if (!_TryMoveTrailing())
{
// When walking through a text sequence, we need to move forward by the number of wchar_ts consumed in the previous view
// in case we had a surrogate pair (or wider complex sequence) in the previous view.
_pos += _currentView.Chars().size();
if (operator bool())
{
_currentView = s_GenerateView(std::get<std::wstring_view>(_run).substr(_pos), _attr);
}
}
break;
}
case Mode::LooseTextOnly:
{
if (!_TryMoveTrailing())
{
// When walking through a text sequence, we need to move forward by the number of wchar_ts consumed in the previous view
// in case we had a surrogate pair (or wider complex sequence) in the previous view.
_pos += _currentView.Chars().size();
if (operator bool())
{
_currentView = s_GenerateView(std::get<std::wstring_view>(_run).substr(_pos));
}
}
break;
}
case Mode::Fill:
{
if (!_TryMoveTrailing())
{
if (_currentView.DbcsAttr().IsTrailing())
{
auto dbcsAttr = _currentView.DbcsAttr();
dbcsAttr.SetLeading();
_currentView = OutputCellView(_currentView.Chars(),
dbcsAttr,
_currentView.TextAttr(),
_currentView.TextAttrBehavior());
}
if (_fillLimit > 0)
{
// We walk forward by one because we fill with the same cell over and over no matter what
_pos++;
}
}
break;
}
case Mode::Cell:
{
// Walk forward by one because cells are assumed to be in the form they needed to be
_pos++;
if (operator bool())
{
_currentView = s_GenerateView(std::get<std::basic_string_view<OutputCell>>(_run).at(_pos));
}
break;
}
case Mode::CharInfo:
{
// Walk forward by one because charinfos are just the legacy version of cells and prealigned to columns
_pos++;
if (operator bool())
{
_currentView = s_GenerateView(std::get<std::basic_string_view<CHAR_INFO>>(_run).at(_pos));
}
break;
}
case Mode::LegacyAttr:
{
// Walk forward by one because color attributes apply cell by cell (no complex text information)
_pos++;
if (operator bool())
{
_currentView = s_GenerateViewLegacyAttr(std::get<std::wstring_view>(_run).at(_pos));
}
break;
}
default:
FAIL_FAST_HR(E_NOTIMPL);
}
return (*this);
}
// Routine Description:
// - Advances the iterator one position over the underlying data source.
// Return Value:
// - Reference to self after advancement.
OutputCellIterator OutputCellIterator::operator++(int)
{
auto temp(*this);
operator++();
return temp;
}
// Routine Description:
// - Reference the view to fully-formed output cell data representing the underlying data source.
// Return Value:
// - Reference to the view
const OutputCellView& OutputCellIterator::operator*() const
{
return _currentView;
}
// Routine Description:
// - Get pointer to the view to fully-formed output cell data representing the underlying data source.
// Return Value:
// - Pointer to the view
const OutputCellView* OutputCellIterator::operator->() const
{
return &_currentView;
}
// Routine Description:
// - Checks the current view. If it is a leading half, it updates the current
// view to the trailing half of the same glyph.
// - This helps us to draw glyphs that are two columns wide by "doubling"
// the view that is returned so it will consume two cells.
// Return Value:
// - True if we just turned a lead half into a trailing half (and caller doesn't
// need to further update the view).
// - False if this wasn't applicable and the caller should update the view.
bool OutputCellIterator::_TryMoveTrailing()
{
if (_currentView.DbcsAttr().IsLeading())
{
auto dbcsAttr = _currentView.DbcsAttr();
dbcsAttr.SetTrailing();
_currentView = OutputCellView(_currentView.Chars(),
dbcsAttr,
_currentView.TextAttr(),
_currentView.TextAttrBehavior());
return true;
}
else
{
return false;
}
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and specify that the attributes shouldn't be changed.
// Arguments:
// - view - View representing characters corresponding to a single glyph
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateView(const std::wstring_view view)
{
return s_GenerateView(view, InvalidTextAttribute, TextAttributeBehavior::Current);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and apply the appropriate attributes to the view.
// Arguments:
// - view - View representing characters corresponding to a single glyph
// - attr - Color attributes to apply to the text
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateView(const std::wstring_view view,
const TextAttribute attr)
{
return s_GenerateView(view, attr, TextAttributeBehavior::Stored);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and apply the appropriate attributes to the view.
// Arguments:
// - view - View representing characters corresponding to a single glyph
// - attr - Color attributes to apply to the text
// - behavior - Behavior of the given text attribute (used when writing)
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateView(const std::wstring_view view,
const TextAttribute attr,
const TextAttributeBehavior behavior)
{
const auto glyph = Utf16Parser::ParseNext(view);
DbcsAttribute dbcsAttr;
if (!glyph.empty() && IsGlyphFullWidth(glyph))
{
dbcsAttr.SetLeading();
}
return OutputCellView(glyph, dbcsAttr, attr, behavior);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and apply the appropriate attributes to the view.
// Arguments:
// - wch - View representing a single UTF-16 character (that can be represented without surrogates)
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateView(const wchar_t& wch)
{
const auto glyph = std::wstring_view(&wch, 1);
DbcsAttribute dbcsAttr;
if (IsGlyphFullWidth(wch))
{
dbcsAttr.SetLeading();
}
return OutputCellView(glyph, dbcsAttr, InvalidTextAttribute, TextAttributeBehavior::Current);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and apply the appropriate attributes to the view.
// Arguments:
// - attr - View representing a single color
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateView(const TextAttribute& attr)
{
return OutputCellView({}, {}, attr, TextAttributeBehavior::StoredOnly);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and apply the appropriate attributes to the view.
// Arguments:
// - wch - View representing a single UTF-16 character (that can be represented without surrogates)
// - attr - View representing a single color
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateView(const wchar_t& wch, const TextAttribute& attr)
{
const auto glyph = std::wstring_view(&wch, 1);
DbcsAttribute dbcsAttr;
if (IsGlyphFullWidth(wch))
{
dbcsAttr.SetLeading();
}
return OutputCellView(glyph, dbcsAttr, attr, TextAttributeBehavior::Stored);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and apply the appropriate attributes to the view.
// Arguments:
// - legacyAttr - View representing a single legacy color
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateViewLegacyAttr(const WORD& legacyAttr)
{
WORD cleanAttr = legacyAttr;
WI_ClearAllFlags(cleanAttr, COMMON_LVB_SBCSDBCS); // don't use legacy lead/trailing byte flags for colors
TextAttribute attr(cleanAttr);
return s_GenerateView(attr);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and apply the appropriate attributes to the view.
// Arguments:
// - charInfo - character and attribute pair representing a single cell
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateView(const CHAR_INFO& charInfo)
{
const auto glyph = std::wstring_view(&charInfo.Char.UnicodeChar, 1);
DbcsAttribute dbcsAttr;
if (WI_IsFlagSet(charInfo.Attributes, COMMON_LVB_LEADING_BYTE))
{
dbcsAttr.SetLeading();
}
else if (WI_IsFlagSet(charInfo.Attributes, COMMON_LVB_TRAILING_BYTE))
{
dbcsAttr.SetTrailing();
}
TextAttribute textAttr;
textAttr.SetFromLegacy(charInfo.Attributes);
const auto behavior = TextAttributeBehavior::Stored;
return OutputCellView(glyph, dbcsAttr, textAttr, behavior);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// Arguments:
// - cell - A reference to the cell for which we will make the read-only view
// Return Value:
// - Object representing the view into this cell
OutputCellView OutputCellIterator::s_GenerateView(const OutputCell& cell)
{
return OutputCellView(cell.Chars(), cell.DbcsAttr(), cell.TextAttr(), cell.TextAttrBehavior());
}
// Routine Description:
// - Gets the distance between two iterators relative to the input data given in.
// Return Value:
// - The number of items of the input run consumed between these two iterators.
ptrdiff_t OutputCellIterator::GetInputDistance(OutputCellIterator other) const noexcept
{
return _pos - other._pos;
}
// Routine Description:
// - Gets the distance between two iterators relative to the number of cells inserted.
// Return Value:
// - The number of cells in the backing buffer filled between these two iterators.
ptrdiff_t OutputCellIterator::GetCellDistance(OutputCellIterator other) const noexcept
{
return _distance - other._distance;
}

View File

@ -0,0 +1,124 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- OutputCellIterator.hpp
Abstract:
- Read-only view into an entire batch of data to be written into the output buffer.
- This is done for performance reasons (avoid heap allocs and copies).
Author:
- Michael Niksa (MiNiksa) 06-Oct-2018
Revision History:
- Based on work from OutputCell.hpp/cpp by Austin Diviness (AustDi)
--*/
#pragma once
#include "TextAttribute.hpp"
#include "OutputCell.hpp"
#include "OutputCellView.hpp"
class OutputCellIterator final
{
public:
using iterator_category = std::input_iterator_tag;
using value_type = OutputCellView;
using difference_type = ptrdiff_t;
using pointer = OutputCellView*;
using reference = OutputCellView&;
OutputCellIterator(const wchar_t& wch, const size_t fillLimit = 0);
OutputCellIterator(const TextAttribute& attr, const size_t fillLimit = 0);
OutputCellIterator(const wchar_t& wch, const TextAttribute& attr, const size_t fillLimit = 0);
OutputCellIterator(const CHAR_INFO& charInfo, const size_t fillLimit = 0);
OutputCellIterator(const std::wstring_view utf16Text);
OutputCellIterator(const std::wstring_view utf16Text, const TextAttribute attribute);
OutputCellIterator(const std::basic_string_view<WORD> legacyAttributes, const bool unused);
OutputCellIterator(const std::basic_string_view<CHAR_INFO> charInfos);
OutputCellIterator(const std::basic_string_view<OutputCell> cells);
~OutputCellIterator() = default;
OutputCellIterator& operator=(const OutputCellIterator& it) = default;
operator bool() const noexcept;
ptrdiff_t GetCellDistance(OutputCellIterator other) const noexcept;
ptrdiff_t GetInputDistance(OutputCellIterator other) const noexcept;
friend ptrdiff_t operator-(OutputCellIterator one, OutputCellIterator two) = delete;
OutputCellIterator& operator++();
OutputCellIterator operator++(int);
const OutputCellView& operator*() const;
const OutputCellView* operator->() const;
private:
enum class Mode
{
// Loose mode is where we're given text and attributes in a raw sort of form
// like while data is being inserted from an API call.
Loose,
// Loose mode with only text is where we're given just text and we want
// to use the attribute already in the buffer when writing
LooseTextOnly,
// Fill mode is where we were given one thing and we just need to keep giving
// that back over and over for eternity.
Fill,
// Given a run of legacy attributes, convert each of them and insert only attribute data.
LegacyAttr,
// CharInfo mode is where we've been given a pair of text and attribute for each
// cell in the legacy format from an API call.
CharInfo,
// Cell mode is where we have an already fully structured cell data usually
// from accessing/copying data already put into the OutputBuffer.
Cell,
};
Mode _mode;
std::basic_string_view<WORD> _legacyAttrs;
std::variant<
std::wstring_view,
std::basic_string_view<CHAR_INFO>,
std::basic_string_view<OutputCell>,
std::monostate> _run;
TextAttribute _attr;
bool _TryMoveTrailing();
static OutputCellView s_GenerateView(const std::wstring_view view);
static OutputCellView s_GenerateView(const std::wstring_view view,
const TextAttribute attr);
static OutputCellView s_GenerateView(const std::wstring_view view,
const TextAttribute attr,
const TextAttributeBehavior behavior);
static OutputCellView s_GenerateView(const wchar_t& wch);
static OutputCellView s_GenerateViewLegacyAttr(const WORD& legacyAttr);
static OutputCellView s_GenerateView(const TextAttribute& attr);
static OutputCellView s_GenerateView(const wchar_t& wch, const TextAttribute& attr);
static OutputCellView s_GenerateView(const CHAR_INFO& charInfo);
static OutputCellView s_GenerateView(const OutputCell& cell);
OutputCellView _currentView;
size_t _pos;
size_t _distance;
size_t _fillLimit;
};

View File

@ -0,0 +1,99 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "OutputCellRect.hpp"
// Routine Description:
// - Constucts an empty in-memory region for holding output buffer cell data.
OutputCellRect::OutputCellRect() :
_rows(0),
_cols(0)
{
}
// Routine Description:
// - Constructs an in-memory region for holding a copy of output buffer cell data.
// - NOTE: This creatively skips the constructors for every cell. You must fill
// every single cell in this rectangle before iterating/reading for it to be valid.
// - NOTE: This is designed for perf-sensitive paths ONLY. Take care.
// Arguments:
// - rows - Rows in the rectangle (height)
// - cols - Columns in the rectangle (width)
OutputCellRect::OutputCellRect(const size_t rows, const size_t cols) :
_rows(rows),
_cols(cols)
{
size_t totalCells;
THROW_IF_FAILED(SizeTMult(rows, cols, &totalCells));
_storage.resize(totalCells);
}
// Routine Description:
// - Gets a read/write span over a single row inside the rectangle.
// Arguments:
// - row - The Y position or row index in the buffer.
// Return Value:
// - Read/write span of OutputCells
gsl::span<OutputCell> OutputCellRect::GetRow(const size_t row)
{
return gsl::span<OutputCell>(_FindRowOffset(row), _cols);
}
// Routine Description:
// - Gets a read-only iterator view over a single row of the rectangle.
// Arguments:
// - row - The Y position or row index in the buffer.
// Return Value:
// - Read-only iterator of OutputCells
OutputCellIterator OutputCellRect::GetRowIter(const size_t row) const
{
const std::basic_string_view<OutputCell> view(_FindRowOffset(row), _cols);
return OutputCellIterator(view);
}
// Routine Description:
// - Internal helper to find the pointer to the specific row offset in the giant
// contiguous block of memory allocated for this rectangle.
// Arguments:
// - row - The Y position or row index in the buffer.
// Return Value:
// - Pointer to the location in the rectangle that represents the start of the requested row.
OutputCell* OutputCellRect::_FindRowOffset(const size_t row)
{
return (_storage.data() + (row * _cols));
}
// Routine Description:
// - Internal helper to find the pointer to the specific row offset in the giant
// contiguous block of memory allocated for this rectangle.
// Arguments:
// - row - The Y position or row index in the buffer.
// Return Value:
// - Pointer to the location in the rectangle that represents the start of the requested row.
const OutputCell* OutputCellRect::_FindRowOffset(const size_t row) const
{
return (_storage.data() + (row * _cols));
}
// Routine Description:
// - Gets the height of the rectangle
// Return Value:
// - Height
size_t OutputCellRect::Height() const noexcept
{
return _rows;
}
// Routine Description:
// - Gets the width of the rectangle
// Return Value:
// - Width
size_t OutputCellRect::Width() const noexcept
{
return _cols;
}

View File

@ -0,0 +1,49 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- OutputCellRect.hpp
Abstract:
- Designed to hold a rectangular area of OutputCells where the column/row count is known ahead of time.
- This is done for performance reasons (one big heap allocation block with appropriate views instead of tiny allocations.)
- NOTE: For cases where the internal buffer will not change during your call, use Iterators and Views to completely
avoid any copy or allocate at all. Only use this when a copy of your content or the buffer is needed.
Author:
- Michael Niksa (MiNiksa) 12-Oct-2018
Revision History:
- Based on work from OutputCell.hpp/cpp by Austin Diviness (AustDi)
--*/
#pragma once
#include "DbcsAttribute.hpp"
#include "TextAttribute.hpp"
#include "OutputCell.hpp"
#include "OutputCellIterator.hpp"
class OutputCellRect final
{
public:
OutputCellRect();
OutputCellRect(const size_t rows, const size_t cols);
gsl::span<OutputCell> GetRow(const size_t row);
OutputCellIterator GetRowIter(const size_t row) const;
size_t Height() const noexcept;
size_t Width() const noexcept;
private:
std::vector<OutputCell> _storage;
OutputCell* _FindRowOffset(const size_t row);
const OutputCell* _FindRowOffset(const size_t row) const;
size_t _cols;
size_t _rows;
};

View File

@ -0,0 +1,108 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "OutputCellView.hpp"
// Routine Description:
// - Constructs a read-only view of data formatted as a single output buffer cell
// Arguments:
// - view - String data for the text displayed on screen
// - dbcsAttr - Describes column width information (double byte character data)
// - textAttr - Describes color and formatting data
// - behavior - Describes where to retrieve color/format data. From this view? From defaults? etc.
OutputCellView::OutputCellView(const std::wstring_view view,
const DbcsAttribute dbcsAttr,
const TextAttribute textAttr,
const TextAttributeBehavior behavior) :
_view(view),
_dbcsAttr(dbcsAttr),
_textAttr(textAttr),
_behavior(behavior)
{
}
// Routine Description:
// - Returns reference to view over text data
// Return Value:
// - Reference to UTF-16 character data
const std::wstring_view& OutputCellView::Chars() const noexcept
{
return _view;
}
// Routine Description:
// - Reports how many columns we expect the Chars() text data to consume
// Return Value:
// - Count of column cells on the screen
size_t OutputCellView::Columns() const noexcept
{
if (DbcsAttr().IsSingle())
{
return 1;
}
else if (DbcsAttr().IsLeading())
{
return 2;
}
else if (DbcsAttr().IsTrailing())
{
return 1;
}
return 1;
}
// Routine Description:
// - Retrieves character cell width data
// Return Value:
// - DbcsAttribute data
DbcsAttribute OutputCellView::DbcsAttr() const noexcept
{
return _dbcsAttr;
}
// Routine Description:
// - Retrieves text color/formatting information
// Return Value:
// - TextAttribute with encoded formatting data
TextAttribute OutputCellView::TextAttr() const noexcept
{
return _textAttr;
}
// Routine Description:
// - Retrieves behavior for inserting this cell into the buffer. See enum for details.
// Return Value:
// - TextAttributeBehavior enum value
TextAttributeBehavior OutputCellView::TextAttrBehavior() const noexcept
{
return _behavior;
}
// Routine Description:
// - Compares two views
// Arguments:
// - it - Other view to compare to this one
// Return Value:
// - True if all contents/references are equal. False otherwise.
bool OutputCellView::operator==(const OutputCellView& it) const noexcept
{
return _view == it._view &&
_dbcsAttr == it._dbcsAttr &&
_textAttr == it._textAttr &&
_behavior == it._behavior;
}
// Routine Description:
// - Compares two views for inequality
// Arguments:
// - it - Other view to compare tot his one.
// Return Value:
// - True if any contents or references are inequal. False if they're all equal.
bool OutputCellView::operator!=(const OutputCellView& it) const noexcept
{
return !(*this == it);
}

View File

@ -0,0 +1,48 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- OutputCellView.hpp
Abstract:
- Read-only view into a single cell of data that someone is attempting to write into the output buffer.
- This is done for performance reasons (avoid heap allocs and copies).
Author:
- Michael Niksa (MiNiksa) 06-Oct-2018
Revision History:
- Based on work from OutputCell.hpp/cpp by Austin Diviness (AustDi)
--*/
#pragma once
#include "DbcsAttribute.hpp"
#include "TextAttribute.hpp"
class OutputCellView
{
public:
OutputCellView(const std::wstring_view view,
const DbcsAttribute dbcsAttr,
const TextAttribute textAttr,
const TextAttributeBehavior behavior);
const std::wstring_view& Chars() const noexcept;
size_t Columns() const noexcept;
DbcsAttribute DbcsAttr() const noexcept;
TextAttribute TextAttr() const noexcept;
TextAttributeBehavior TextAttrBehavior() const noexcept;
bool operator==(const OutputCellView& view) const noexcept;
bool operator!=(const OutputCellView& view) const noexcept;
private:
std::wstring_view _view;
DbcsAttribute _dbcsAttr;
TextAttribute _textAttr;
TextAttributeBehavior _behavior;
};

222
src/buffer/out/Row.cpp Normal file
View File

@ -0,0 +1,222 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "Row.hpp"
#include "CharRow.hpp"
#include "textBuffer.hpp"
#include "../types/inc/convert.hpp"
// Routine Description:
// - constructor
// Arguments:
// - rowId - the row index in the text buffer
// - rowWidth - the width of the row, cell elements
// - fillAttribute - the default text attribute
// - pParent - the text buffer that this row belongs to
// Return Value:
// - constructed object
ROW::ROW(const SHORT rowId, const short rowWidth, const TextAttribute fillAttribute, TextBuffer* const pParent) :
_id{ rowId },
_rowWidth{ gsl::narrow<size_t>(rowWidth) },
_charRow{ gsl::narrow<size_t>(rowWidth), this },
_attrRow{ gsl::narrow<UINT>(rowWidth), fillAttribute },
_pParent{ pParent }
{
}
size_t ROW::size() const noexcept
{
return _rowWidth;
}
const CharRow& ROW::GetCharRow() const
{
return _charRow;
}
CharRow& ROW::GetCharRow()
{
return const_cast<CharRow&>(static_cast<const ROW* const>(this)->GetCharRow());
}
const ATTR_ROW& ROW::GetAttrRow() const noexcept
{
return _attrRow;
}
ATTR_ROW& ROW::GetAttrRow() noexcept
{
return const_cast<ATTR_ROW&>(static_cast<const ROW* const>(this)->GetAttrRow());
}
SHORT ROW::GetId() const noexcept
{
return _id;
}
void ROW::SetId(const SHORT id) noexcept
{
_id = id;
}
// Routine Description:
// - Sets all properties of the ROW to default values
// Arguments:
// - Attr - The default attribute (color) to fill
// Return Value:
// - <none>
bool ROW::Reset(const TextAttribute Attr)
{
_charRow.Reset();
try
{
_attrRow.Reset(Attr);
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
return false;
}
return true;
}
// Routine Description:
// - resizes ROW to new width
// Arguments:
// - width - the new width, in cells
// Return Value:
// - S_OK if successful, otherwise relevant error
[[nodiscard]]
HRESULT ROW::Resize(const size_t width)
{
RETURN_IF_FAILED(_charRow.Resize(width));
try
{
_attrRow.Resize(width);
}
CATCH_RETURN();
_rowWidth = width;
return S_OK;
}
// Routine Description:
// - clears char data in column in row
// Arguments:
// - column - 0-indexed column index
// Return Value:
// - <none>
void ROW::ClearColumn(const size_t column)
{
THROW_HR_IF(E_INVALIDARG, column >= _charRow.size());
_charRow.ClearCell(column);
}
// Routine Description:
// - gets the text of the row as it would be shown on the screen
// Return Value:
// - wstring containing text for the row
std::wstring ROW::GetText() const
{
return _charRow.GetText();
}
RowCellIterator ROW::AsCellIter(const size_t startIndex) const
{
return AsCellIter(startIndex, size() - startIndex);
}
RowCellIterator ROW::AsCellIter(const size_t startIndex, const size_t count) const
{
return RowCellIterator(*this, startIndex, count);
}
UnicodeStorage& ROW::GetUnicodeStorage()
{
return _pParent->GetUnicodeStorage();
}
const UnicodeStorage& ROW::GetUnicodeStorage() const
{
return _pParent->GetUnicodeStorage();
}
// Routine Description:
// - writes cell data to the row
// Arguments:
// - it - custom console iterator to use for seeking input data. bool() false when it becomes invalid while seeking.
// - index - column in row to start writing at
// - setWrap - set the wrap flags if we hit the end of the row while writing and there's still more data in the iterator.
// - limitRight - right inclusive column ID for the last write in this row. (optional, will just write to the end of row if nullopt)
// Return Value:
// - iterator to first cell that was not written to this row.
OutputCellIterator ROW::WriteCells(OutputCellIterator it, const size_t index, const bool setWrap, std::optional<size_t> limitRight)
{
THROW_HR_IF(E_INVALIDARG, index >= _charRow.size());
THROW_HR_IF(E_INVALIDARG, limitRight.value_or(0) >= _charRow.size());
size_t currentIndex = index;
// If we're given a right-side column limit, use it. Otherwise, the write limit is the final column index available in the char row.
const auto finalColumnInRow = limitRight.value_or(_charRow.size() - 1);
while (it && currentIndex <= finalColumnInRow)
{
// Fill the color if the behavior isn't set to keeping the current color.
if (it->TextAttrBehavior() != TextAttributeBehavior::Current)
{
const TextAttributeRun attrRun{ 1, it->TextAttr() };
LOG_IF_FAILED(_attrRow.InsertAttrRuns({ &attrRun, 1 },
currentIndex,
currentIndex,
_charRow.size()));
}
// Fill the text if the behavior isn't set to saying there's only a color stored in this iterator.
if (it->TextAttrBehavior() != TextAttributeBehavior::StoredOnly)
{
const bool fillingLastColumn = currentIndex == finalColumnInRow;
// TODO: MSFT: 19452170 - We need to ensure when writing any trailing byte that the one to the left
// is a matching leading byte. Likewise, if we're writing a leading byte, we need to make sure we still have space in this loop
// for the trailing byte coming up before writing it.
// If we're trying to fill the first cell with a trailing byte, pad it out instead by clearing it.
// Don't increment iterator. We'll advance the index and try again with this value on the next round through the loop.
if (currentIndex == 0 && it->DbcsAttr().IsTrailing())
{
_charRow.ClearCell(currentIndex);
}
// If we're trying to fill the last cell with a leading byte, pad it out instead by clearing it.
// Don't increment iterator. We'll exit because we couldn't write a lead at the end of a line.
else if (fillingLastColumn && it->DbcsAttr().IsLeading())
{
_charRow.ClearCell(currentIndex);
_charRow.SetDoubleBytePadded(true);
}
// Otherwise, copy the data given and increment the iterator.
else
{
_charRow.DbcsAttrAt(currentIndex) = it->DbcsAttr();
_charRow.GlyphAt(currentIndex) = it->Chars();
++it;
}
// If we're asked to set the wrap status and we just filled the last column with some text, set wrap status on the row.
if (setWrap && fillingLastColumn)
{
_charRow.SetWrapForced(true);
}
}
else
{
++it;
}
// Move to the next cell for the next time through the loop.
++currentIndex;
}
return it;
}

84
src/buffer/out/Row.hpp Normal file
View File

@ -0,0 +1,84 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- Row.hpp
Abstract:
- data structure for information associated with one row of screen buffer
Author(s):
- Michael Niksa (miniksa) 10-Apr-2014
- Paul Campbell (paulcam) 10-Apr-2014
Revision History:
- From components of output.h/.c
by Therese Stowell (ThereseS) 1990-1991
- Pulled into its own file from textBuffer.hpp/cpp (AustDi, 2017)
--*/
#pragma once
#include "AttrRow.hpp"
#include "OutputCell.hpp"
#include "OutputCellIterator.hpp"
#include "CharRow.hpp"
#include "RowCellIterator.hpp"
#include "UnicodeStorage.hpp"
class TextBuffer;
class ROW final
{
public:
ROW(const SHORT rowId, const short rowWidth, const TextAttribute fillAttribute, TextBuffer* const pParent);
size_t size() const noexcept;
const CharRow& GetCharRow() const;
CharRow& GetCharRow();
const ATTR_ROW& GetAttrRow() const noexcept;
ATTR_ROW& GetAttrRow() noexcept;
SHORT GetId() const noexcept;
void SetId(const SHORT id) noexcept;
bool Reset(const TextAttribute Attr);
[[nodiscard]]
HRESULT Resize(const size_t width);
void ClearColumn(const size_t column);
std::wstring GetText() const;
RowCellIterator AsCellIter(const size_t startIndex) const;
RowCellIterator AsCellIter(const size_t startIndex, const size_t count) const;
UnicodeStorage& GetUnicodeStorage();
const UnicodeStorage& GetUnicodeStorage() const;
OutputCellIterator WriteCells(OutputCellIterator it, const size_t index, const bool setWrap, std::optional<size_t> limitRight = std::nullopt);
friend bool operator==(const ROW& a, const ROW& b) noexcept;
#ifdef UNIT_TESTING
friend class RowTests;
#endif
private:
CharRow _charRow;
ATTR_ROW _attrRow;
SHORT _id;
size_t _rowWidth;
TextBuffer* _pParent; // non ownership pointer
};
inline bool operator==(const ROW& a, const ROW& b) noexcept
{
return (a._charRow == b._charRow &&
a._attrRow == b._attrRow &&
a._rowWidth == b._rowWidth &&
a._pParent == b._pParent &&
a._id == b._id);
}

View File

@ -0,0 +1,111 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "RowCellIterator.hpp"
#include "Row.hpp"
#include "../../types/inc/convert.hpp"
#include "../../types/inc/Utf16Parser.hpp"
RowCellIterator::RowCellIterator(const ROW& row, const size_t start, const size_t length) :
_row(row),
_start(start),
_length(length),
_pos(start),
_view(s_GenerateView(row, start))
{
}
RowCellIterator::operator bool() const noexcept
{
// In lieu of using start and end, this custom iterator type simply becomes bool false
// when we run out of items to iterate over.
return _pos < (_start + _length);
}
bool RowCellIterator::operator==(const RowCellIterator& it) const noexcept
{
return _row == it._row &&
_start == it._start &&
_length == it._length &&
_pos == it._pos;
}
bool RowCellIterator::operator!=(const RowCellIterator& it) const noexcept
{
return !(*this == it);
}
RowCellIterator& RowCellIterator::operator+=(const ptrdiff_t& movement)
{
_pos += movement;
return (*this);
}
RowCellIterator& RowCellIterator::operator++()
{
return this->operator+=(1);
}
RowCellIterator RowCellIterator::operator++(int)
{
auto temp(*this);
operator++();
return temp;
}
RowCellIterator RowCellIterator::operator+(const ptrdiff_t& movement)
{
auto temp(*this);
temp += movement;
return temp;
}
const OutputCellView& RowCellIterator::operator*() const
{
return _view;
}
const OutputCellView* RowCellIterator::operator->() const
{
return &_view;
}
// Routine Description:
// - Member function to update the view to the current position in the buffer with
// the data held on this object.
// Arguments:
// - <none>
// Return Value:
// - <none>
void RowCellIterator::_RefreshView()
{
_view = s_GenerateView(_row, _pos);
}
// Routine Description:
// - Static function to create a view.
// - It's pulled out statically so it can be used during construction with just the given
// variables (so OutputCellView doesn't need an empty default constructor)
// - This will infer the width of the glyph and apply the appropriate attributes to the view.
// Arguments:
// - view - View representing characters corresponding to a single glyph
// - attr - Color attributes to apply to the text
// Return Value:
// - Object representing the view into this cell
OutputCellView RowCellIterator::s_GenerateView(const ROW& row,
const size_t pos)
{
const auto& charRow = row.GetCharRow();
const auto glyph = charRow.GlyphAt(pos);
const auto dbcsAttr = charRow.DbcsAttrAt(pos);
const auto textAttr = row.GetAttrRow().GetAttrByColumn(pos);
const auto behavior = TextAttributeBehavior::Stored;
return OutputCellView(glyph, dbcsAttr, textAttr, behavior);
}

Some files were not shown because too many files have changed in this diff Show More