Skip to content

Commit f20a8e8

Browse files
eerhardtTomFinley
authored andcommitted
Remove CmdParser.GetConsoleWindowWidth. (#879)
This method is available on the Console class, thus we don't need to have our own API for it. Fix #878.
1 parent 627ad79 commit f20a8e8

File tree

2 files changed

+3
-67
lines changed

2 files changed

+3
-67
lines changed

src/Microsoft.ML.Core/CommandLine/CmdParser.cs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -503,70 +503,6 @@ public static string ArgumentsUsage(IHostEnvironment env, Type type, object defa
503503
return parser.GetUsageString(env, info, showRsp, columns);
504504
}
505505

506-
#if CORECLR
507-
/// <summary>
508-
/// Fix the window width for the Core build to remove the kernel32.dll dependency.
509-
/// </summary>
510-
/// <returns></returns>
511-
public static int GetConsoleWindowWidth()
512-
{
513-
return 120;
514-
}
515-
#else
516-
private const int StdOutputHandle = -11;
517-
518-
private struct Coord
519-
{
520-
internal Int16 X;
521-
internal Int16 Y;
522-
}
523-
524-
private struct SmallRect
525-
{
526-
internal Int16 Left;
527-
internal Int16 Top;
528-
internal Int16 Right;
529-
internal Int16 Bottom;
530-
}
531-
532-
private struct ConsoleScreenBufferInfo
533-
{
534-
internal Coord DwSize;
535-
internal Coord DwCursorPosition;
536-
internal Int16 WAttributes;
537-
internal SmallRect SrWindow;
538-
internal Coord DwMaximumWindowSize;
539-
}
540-
541-
[DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
542-
private static extern int GetStdHandle(int nStdHandle);
543-
544-
[DllImport("kernel32.dll", EntryPoint = "GetConsoleScreenBufferInfo", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
545-
private static extern int GetConsoleScreenBufferInfo(int hConsoleOutput, ref ConsoleScreenBufferInfo lpConsoleScreenBufferInfo);
546-
547-
/// <summary>
548-
/// Returns the number of columns in the current console window
549-
/// </summary>
550-
/// <returns>Returns the number of columns in the current console window</returns>
551-
public static int GetConsoleWindowWidth()
552-
{
553-
int screenWidth;
554-
ConsoleScreenBufferInfo csbi = new ConsoleScreenBufferInfo();
555-
// Just to remove the warning messages...
556-
csbi.DwCursorPosition.X = 0;
557-
csbi.DwCursorPosition.Y = 0;
558-
csbi.SrWindow.Bottom = 0;
559-
csbi.SrWindow.Top = 0;
560-
csbi.SrWindow.Left = 0;
561-
csbi.SrWindow.Right = 0;
562-
563-
int rc;
564-
rc = GetConsoleScreenBufferInfo(GetStdHandle(StdOutputHandle), ref csbi);
565-
screenWidth = csbi.DwSize.X;
566-
return screenWidth;
567-
}
568-
#endif
569-
570506
private CmdParser(IHostEnvironment env)
571507
{
572508
_host = env.Register("CmdParser");
@@ -1009,7 +945,7 @@ public ArgumentHelpStrings(string syntax, string help)
1009945
/// </summary>
1010946
private string GetUsageString(IExceptionContext ectx, ArgumentInfo info, bool showRsp = true, int? columns = null)
1011947
{
1012-
int screenWidth = columns ?? GetConsoleWindowWidth();
948+
int screenWidth = columns ?? Console.BufferWidth;
1013949
if (screenWidth <= 0)
1014950
screenWidth = 80;
1015951

src/Microsoft.ML.Maml/HelpCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ private void ShowFormattedSummary(IndentingTextWriter writer, string summary, in
343343
return;
344344

345345
// REVIEW: should we replace consecutive spaces with a single space as a preprocessing step?
346-
int screenWidth = (columns ?? CmdParser.GetConsoleWindowWidth()) - 1;
346+
int screenWidth = (columns ?? Console.BufferWidth) - 1;
347347

348-
// GetConsoleWindowWidth returns 0 if command redirection operator is used
348+
// Console.BufferWidth returns 0 if command redirection operator is used
349349
if (screenWidth <= 0)
350350
screenWidth = 80;
351351

0 commit comments

Comments
 (0)