terminal/src/host/_stream.h

98 lines
4.4 KiB
C
Raw Permalink Normal View History

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- _stream.h
Abstract:
- Process stream written content into the text buffer
Author:
- KazuM Jun.09.1997
Revision History:
- Remove FE/Non-FE separation in preparation for refactoring. (MiNiksa, 2014)
--*/
#pragma once
#include "../server/IWaitRoutine.h"
#include "writeData.hpp"
/*++
Routine Description:
This routine updates the cursor position. Its input is the non-special
cased new location of the cursor. For example, if the cursor were being
moved one space backwards from the left edge of the screen, the X
coordinate would be -1. This routine would set the X coordinate to
the right edge of the screen and decrement the Y coordinate by one.
Arguments:
pScreenInfo - Pointer to screen buffer information structure.
coordCursor - New location of cursor.
fKeepCursorVisible - TRUE if changing window origin desirable when hit right edge
Return Value:
--*/
[[nodiscard]] NTSTATUS AdjustCursorPosition(SCREEN_INFORMATION& screenInfo,
_In_ COORD coordCursor,
const BOOL fKeepCursorVisible,
_Inout_opt_ PSHORT psScrollY);
/*++
Routine Description:
This routine writes a string to the screen, processing any embedded
unicode characters. The string is also copied to the input buffer, if
the output mode is line mode.
Arguments:
ScreenInfo - Pointer to screen buffer information structure.
lpBufferBackupLimit - Pointer to beginning of buffer.
lpBuffer - Pointer to buffer to copy string to. assumed to be at least
as long as lpRealUnicodeString. This pointer is updated to point to the
next position in the buffer.
lpRealUnicodeString - Pointer to string to write.
NumBytes - On input, number of bytes to write. On output, number of
bytes written.
NumSpaces - On output, the number of spaces consumed by the written characters.
dwFlags -
WC_DESTRUCTIVE_BACKSPACE backspace overwrites characters.
WC_KEEP_CURSOR_VISIBLE change window origin desirable when hit rt. edge
WC_PRINTABLE_CONTROL_CHARS if control characters should be expanded (as in, to "^X")
Return Value:
Note:
This routine does not process tabs and backspace properly. That code
will be implemented as part of the line editing services.
--*/
[[nodiscard]] NTSTATUS WriteCharsLegacy(SCREEN_INFORMATION& screenInfo,
_In_range_(<=, pwchBuffer) const wchar_t* const pwchBufferBackupLimit,
_In_ const wchar_t* pwchBuffer,
_In_reads_bytes_(*pcb) const wchar_t* pwchRealUnicode,
_Inout_ size_t* const pcb,
_Out_opt_ size_t* const pcSpaces,
const SHORT sOriginalXPosition,
const DWORD dwFlags,
_Inout_opt_ PSHORT const psScrollY);
// The new entry point for WriteChars to act as an intercept in case we place a Virtual Terminal processor in the way.
[[nodiscard]] NTSTATUS WriteChars(SCREEN_INFORMATION& screenInfo,
_In_range_(<=, pwchBuffer) const wchar_t* const pwchBufferBackupLimit,
_In_ const wchar_t* pwchBuffer,
_In_reads_bytes_(*pcb) const wchar_t* pwchRealUnicode,
_Inout_ size_t* const pcb,
_Out_opt_ size_t* const pcSpaces,
const SHORT sOriginalXPosition,
const DWORD dwFlags,
_Inout_opt_ PSHORT const psScrollY);
// NOTE: console lock must be held when calling this routine
// String has been translated to unicode at this point.
[[nodiscard]] NTSTATUS DoWriteConsole(_In_reads_bytes_(*pcbBuffer) PWCHAR pwchBuffer,
_Inout_ size_t* const pcbBuffer,
SCREEN_INFORMATION& screenInfo,
Reintroduce a color compatibility hack, but only for PowerShells (#6810) There is going to be a very long tail of applications that will explicitly request VT SGR 40/37 when what they really want is to SetConsoleTextAttribute() with a black background/white foreground. Instead of making those applications look bad (and therefore making us look bad, because we're releasing this as an update to something that "looks good" already), we're introducing this compatibility quirk. Before the color reckoning in #6698 + #6506, *every* color was subject to being spontaneously and erroneously turned into the default color. Now, only the 16-color palette value that matches the active console background/foreground color will be destroyed, and only when received from specific applications. Removal will be tracked by #6807. Michael and I discussed what layer this quirk really belonged in. I originally believed it would be sufficient to detect a background color that matched the legacy default background, but @j4james provided an example of where that wouldn't work out (powershell setting the foreground color to white/gray). In addition, it was too heavyhanded: it re-broke black backgrounds for every application. Michael thought that it should live in the server, as a small VT parser that righted the wrongs coming directly out of the application. On further investigation, however, I realized that we'd need to push more information up into the server (so that it could make the decision about which VT was wrong and which was right) than should be strictly necessary. The host knows which colors are right and wrong, and it gets final say in what ends up in the buffer. Because of that, I chose to push the quirk state down through WriteConsole to DoWriteConsole and toggle state on the SCREEN_INFORMATION that indicates whether the colors coming out of the application are to be distrusted. This quirk _only applies to pwsh.exe and powershell.exe._ NOTE: This doesn't work for PowerShell the .NET Global tool, because it is run as an assembly through dotnet.exe. I have no opinion on how to fix this, or whether it is worth fixing. VALIDATION ---------- I configured my terminals to have an incredibly garish color scheme to show exactly what's going to happen as a result of this. The _default terminal background_ is purple or red, and the foreground green. I've printed out a heap of test colors to see how black interacts with them. Pull request #6810 contains the images generated from this test. The only color lines that change are the ones where black as a background or white as a foreground is selected out of the 16-color palette explicitly. Reverse video still works fine (because black is in the foreground!), and it's even possible to represent "black on default" and reverse it into "default on black", despite the black in question having been `40`. Fixes #6767.
2020-07-11 00:25:39 +02:00
bool requiresVtQuirk,
std::unique_ptr<WriteData>& waiter);