Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2818,40 +2818,6 @@ internal static bool IsCJKOutputCodePage(out uint codePage)

#region Cursor

/// <summary>
/// Wraps Win32 SetConsoleCursorPosition.
/// </summary>
/// <param name="consoleHandle">
/// handle for the console where cursor position is set
/// </param>
/// <param name="cursorPosition">
/// location to which the cursor will be set
/// </param>
/// <exception cref="HostException">
/// If Win32's SetConsoleCursorPosition fails
/// </exception>
internal static void SetConsoleCursorPosition(ConsoleHandle consoleHandle, Coordinates cursorPosition)
{
Dbg.Assert(!consoleHandle.IsInvalid, "ConsoleHandle is not valid");
Dbg.Assert(!consoleHandle.IsClosed, "ConsoleHandle is closed");

ConsoleControl.COORD c;

c.X = (short)cursorPosition.X;
c.Y = (short)cursorPosition.Y;

bool result = NativeMethods.SetConsoleCursorPosition(consoleHandle.DangerousGetHandle(), c);

if (!result)
{
int err = Marshal.GetLastWin32Error();

HostException e = CreateHostException(err, "SetConsoleCursorPosition",
ErrorCategory.ResourceUnavailable, ConsoleControlStrings.SetConsoleCursorPositionExceptionTemplate);
throw e;
}
}

/// <summary>
/// Wraps Win32 GetConsoleCursorInfo.
/// </summary>
Expand Down Expand Up @@ -3159,10 +3125,6 @@ out DWORD numberOfEventsRead
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetConsoleCtrlHandler(BreakHandler handlerRoutine, bool add);

[DllImport(PinvokeDllNames.SetConsoleCursorPositionDllName, SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetConsoleCursorPosition(NakedWin32Handle consoleOutput, COORD cursorPosition);

[DllImport(PinvokeDllNames.SetConsoleModeDllName, SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetConsoleMode(NakedWin32Handle consoleHandle, DWORD mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,15 @@ public override

set
{
// cursor position can't be outside the buffer area

ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO bufferInfo;

ConsoleHandle handle = GetBufferInfo(out bufferInfo);

CheckCoordinateWithinBuffer(ref value, ref bufferInfo, "value");
ConsoleControl.SetConsoleCursorPosition(handle, value);
try
{
Console.SetCursorPosition(value.X, value.Y);
Comment thread
SteveL-MSFT marked this conversation as resolved.
}
catch (ArgumentOutOfRangeException)
{
// if screen buffer has changed, we cannot set it anywhere reasonable as the screen buffer
// might change again, so we ignore this
}
}
}

Expand Down
43 changes: 21 additions & 22 deletions src/System.Management.Automation/utils/PInvokeDllNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,26 @@ internal static class PinvokeDllNames
internal const string PeekConsoleInputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*103*/
internal const string GetNumberOfConsoleInputEventsDllName = "api-ms-win-core-console-l1-1-0.dll"; /*104*/
internal const string SetConsoleCtrlHandlerDllName = "api-ms-win-core-console-l1-1-0.dll"; /*105*/
internal const string SetConsoleCursorPositionDllName = "api-ms-win-core-console-l2-1-0.dll"; /*106*/
Comment thread
SteveL-MSFT marked this conversation as resolved.
internal const string SetConsoleModeDllName = "api-ms-win-core-console-l1-1-0.dll"; /*107*/
internal const string SetConsoleScreenBufferSizeDllName = "api-ms-win-core-console-l2-1-0.dll"; /*108*/
internal const string SetConsoleTextAttributeDllName = "api-ms-win-core-console-l2-1-0.dll"; /*109*/
internal const string SetConsoleWindowInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*110*/
internal const string WriteConsoleOutputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*111*/
internal const string ReadConsoleOutputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*112*/
internal const string ScrollConsoleScreenBufferDllName = "api-ms-win-core-console-l2-1-0.dll"; /*113*/
internal const string SendInputDllName = "ext-ms-win-ntuser-keyboard-l1-2-1.dll"; /*114*/
internal const string GetConsoleCursorInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*115*/
internal const string SetConsoleCursorInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*116*/
internal const string ReadConsoleInputDllName = "api-ms-win-core-console-l1-1-0.dll"; /*117*/
internal const string GetVersionExDllName = "api-ms-win-core-sysinfo-l1-1-0.dll"; /*118*/
internal const string FormatMessageDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*119*/
internal const string CreateToolhelp32SnapshotDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*120*/
internal const string Process32FirstDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*121*/
internal const string Process32NextDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*122*/
internal const string GetACPDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*123*/
internal const string DeleteServiceDllName = "api-ms-win-service-management-l1-1-0.dll"; /*124*/
internal const string QueryServiceConfigDllName = "api-ms-win-service-management-l2-1-0.dll"; /*125*/
internal const string QueryServiceConfig2DllName = "api-ms-win-service-management-l2-1-0.dll"; /*126*/
internal const string SetServiceObjectSecurityDllName = "api-ms-win-service-management-l2-1-0.dll"; /*127*/
internal const string SetConsoleModeDllName = "api-ms-win-core-console-l1-1-0.dll"; /*106*/
internal const string SetConsoleScreenBufferSizeDllName = "api-ms-win-core-console-l2-1-0.dll"; /*107*/
internal const string SetConsoleTextAttributeDllName = "api-ms-win-core-console-l2-1-0.dll"; /*108*/
internal const string SetConsoleWindowInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*109*/
internal const string WriteConsoleOutputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*110*/
internal const string ReadConsoleOutputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*111*/
internal const string ScrollConsoleScreenBufferDllName = "api-ms-win-core-console-l2-1-0.dll"; /*112*/
internal const string SendInputDllName = "ext-ms-win-ntuser-keyboard-l1-2-1.dll"; /*113*/
internal const string GetConsoleCursorInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*114*/
internal const string SetConsoleCursorInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*115*/
internal const string ReadConsoleInputDllName = "api-ms-win-core-console-l1-1-0.dll"; /*116*/
internal const string GetVersionExDllName = "api-ms-win-core-sysinfo-l1-1-0.dll"; /*117*/
internal const string FormatMessageDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*118*/
internal const string CreateToolhelp32SnapshotDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*119*/
internal const string Process32FirstDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*120*/
internal const string Process32NextDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*121*/
internal const string GetACPDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*122*/
internal const string DeleteServiceDllName = "api-ms-win-service-management-l1-1-0.dll"; /*123*/
internal const string QueryServiceConfigDllName = "api-ms-win-service-management-l2-1-0.dll"; /*124*/
internal const string QueryServiceConfig2DllName = "api-ms-win-service-management-l2-1-0.dll"; /*125*/
internal const string SetServiceObjectSecurityDllName = "api-ms-win-service-management-l2-1-0.dll"; /*126*/
}
}