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
4 changes: 2 additions & 2 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<add key="dotnet10-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet10-transport/nuget/v3/index.json" />
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
<add key="dotnet9-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9-transport/nuget/v3/index.json" />
<!-- Need this for the old version of System.CommandLine we use -->
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
<!-- Need this for System.CommandLine -->
<add key="dotnet-libraries" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
<add key="dotnet-diagnostics-tests" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-diagnostics-tests/nuget/v3/index.json" />
Expand Down
3 changes: 1 addition & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
<MicrosoftExtensionsLoggingConsoleVersion>6.0.0</MicrosoftExtensionsLoggingConsoleVersion>
<!-- Need version that understands UseAppFilters sentinel. -->
<MicrosoftExtensionsLoggingEventSourceVersion>5.0.1</MicrosoftExtensionsLoggingEventSourceVersion>
<SystemCommandLineVersion>2.0.0-beta1.20468.1</SystemCommandLineVersion>
<SystemCommandLineRenderingVersion>2.0.0-beta1.20074.1</SystemCommandLineRenderingVersion>
<SystemCommandLineVersion>2.0.0-beta4.25072.1</SystemCommandLineVersion>
<SystemComponentModelAnnotationsVersion>5.0.0</SystemComponentModelAnnotationsVersion>
<SystemBuffersVersion>4.5.1</SystemBuffersVersion>
<SystemMemoryVersion>4.5.5</SystemMemoryVersion>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text;

namespace System.CommandLine
{
// class copied from https://raw.githubusercontent.com/dotnet/command-line-api/060374e56c1b2e741b6525ca8417006efb54fbd7/src/System.CommandLine.DragonFruit/StringExtensions.cs
internal static class StringExtensions
{
public static string ToKebabCase(this string value)
{
if (string.IsNullOrEmpty(value))
{
return value;
}

StringBuilder sb = new();
int i = 0;
bool addDash = false;

// handles beginning of string, breaks on first letter or digit. addDash might be better named "canAddDash"
for (; i < value.Length; i++)
{
char ch = value[i];
if (char.IsLetterOrDigit(ch))
{
addDash = !char.IsUpper(ch);
sb.Append(char.ToLowerInvariant(ch));
i++;
break;
}
}

// reusing i, start at the same place
for (; i < value.Length; i++)
{
char ch = value[i];
if (char.IsUpper(ch))
{
if (addDash)
{
addDash = false;
sb.Append('-');
}

sb.Append(char.ToLowerInvariant(ch));
}
else if (char.IsLetterOrDigit(ch))
{
addDash = true;
sb.Append(ch);
}
else //this coverts all non letter/digits to dash - specifically periods and underscores. Is this needed?
{
addDash = false;
sb.Append('-');
}
}

return sb.ToString();
}
}
}
2 changes: 1 addition & 1 deletion src/SOS/SOS.UnitTests/Scripts/DumpGen.script
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ VERIFY: invalid is not a supported generation

!IFDEF:LLDB
EXTCOMMAND_FAIL: dumpgen gen0 -mt
VERIFY: Required argument missing for option: -mt
VERIFY: Required argument missing for option: '-mt'.

EXTCOMMAND_FAIL: dumpgen gen1 -mt zzzzz
VERIFY: Hexadecimal address expected for -mt option
Expand Down
39 changes: 0 additions & 39 deletions src/Tools/Common/CommandExtensions.cs

This file was deleted.

26 changes: 13 additions & 13 deletions src/Tools/Common/Commands/ProcessStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Binding;
using System.CommandLine.IO;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Internal.Common.Utils;
using Microsoft.Internal.Common;
using Microsoft.Internal.Common.Utils;
using Process = System.Diagnostics.Process;

namespace Microsoft.Internal.Common.Commands
{
public class ProcessStatusCommandHandler
{
public static Command ProcessStatusCommand(string description) =>
new(name: "ps", description)
{
HandlerDescriptor.FromDelegate((ProcessStatusDelegate)ProcessStatus).GetCommandHandler()
};

private delegate void ProcessStatusDelegate(IConsole console);
public static Command ProcessStatusCommand(string description)
{
Command statusCommand = new(name: "ps", description);
statusCommand.SetAction((parseResult, ct) => Task.FromResult(ProcessStatus(parseResult.Configuration.Output, parseResult.Configuration.Error)));
return statusCommand;
}

private static void MakeFixedWidth(string text, int width, StringBuilder sb, bool leftPad = false, bool truncateFront = false)
{
Expand Down Expand Up @@ -76,7 +74,7 @@ private struct ProcessDetails
/// <summary>
/// Print the current list of available .NET core processes for diagnosis, their statuses and the command line arguments that are passed to them.
/// </summary>
public static void ProcessStatus(IConsole console)
public static int ProcessStatus(TextWriter stdOut, TextWriter stdError)
{
int GetColumnWidth(IEnumerable<int> fieldWidths)
{
Expand Down Expand Up @@ -170,11 +168,13 @@ void FormatTableRows(List<ProcessDetails> rows, StringBuilder tableText)
}
}
FormatTableRows(printInfo, sb);
console.Out.WriteLine(sb.ToString());
stdOut.WriteLine(sb.ToString());
return 0;
}
catch (Exception ex)
{
console.Out.WriteLine(ex.ToString());
stdError.WriteLine(ex.ToString());
return 1;
}
}

Expand Down
34 changes: 34 additions & 0 deletions src/Tools/Common/Rendering/Interop.Windows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;

namespace System.CommandLine.Rendering
{
internal static partial class Interop
{
public const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;

public const uint ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;

public const uint DISABLE_NEWLINE_AUTO_RETURN = 0x0008;

public const int STD_OUTPUT_HANDLE = -11;

public const int STD_INPUT_HANDLE = -10;

[LibraryImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool GetConsoleMode(IntPtr handle, out uint mode);

[LibraryImport("kernel32.dll")]
public static partial uint GetLastError();

[LibraryImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool SetConsoleMode(IntPtr handle, uint mode);

[LibraryImport("kernel32.dll", SetLastError = true)]
public static partial IntPtr GetStdHandle(int handle);
}
}
105 changes: 105 additions & 0 deletions src/Tools/Common/Rendering/VirtualTerminalMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using static System.CommandLine.Rendering.Interop;

namespace System.CommandLine.Rendering
{
/// <summary>
/// This file is a copy of https://github.com/dotnet/command-line-api/blob/060374e56c1b2e741b6525ca8417006efb54fbd7/src/System.CommandLine.Rendering/Interop.Windows.cs
/// which is no longer supported.
/// </summary>
public sealed class VirtualTerminalMode : IDisposable
{
private readonly IntPtr _stdOutHandle;
private readonly IntPtr _stdInHandle;
private readonly uint _originalOutputMode;
private readonly uint _originalInputMode;

private VirtualTerminalMode(bool isEnabled)
{
IsEnabled = isEnabled;
GC.SuppressFinalize(this); // ctor used only on Unix, where there is nothing to cleanup
}

private VirtualTerminalMode(
IntPtr stdOutHandle,
uint originalOutputMode,
IntPtr stdInHandle,
uint originalInputMode)
{
_stdOutHandle = stdOutHandle;
_originalOutputMode = originalOutputMode;
_stdInHandle = stdInHandle;
_originalInputMode = originalInputMode;
}

public bool IsEnabled { get; }

public static VirtualTerminalMode TryEnable()
{
if (OperatingSystem.IsWindows())
{
IntPtr stdOutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
IntPtr stdInHandle = GetStdHandle(STD_INPUT_HANDLE);

if (!GetConsoleMode(stdOutHandle, out uint originalOutputMode))
{
return null;
}

if (!GetConsoleMode(stdInHandle, out uint originalInputMode))
{
return null;
}

uint requestedOutputMode = originalOutputMode |
ENABLE_VIRTUAL_TERMINAL_PROCESSING |
DISABLE_NEWLINE_AUTO_RETURN;

if (!SetConsoleMode(stdOutHandle, requestedOutputMode))
{
return null;
}

return new VirtualTerminalMode(stdOutHandle,
originalOutputMode,
stdInHandle,
originalInputMode);
}
else
{
string terminalName = Environment.GetEnvironmentVariable("TERM");

bool isXterm = !string.IsNullOrEmpty(terminalName)
&& terminalName.StartsWith("xterm", StringComparison.OrdinalIgnoreCase);

// TODO: Is this a reasonable default?
return new VirtualTerminalMode(isXterm);
}
}

private void RestoreConsoleMode()
{
if (IsEnabled)
{
if (_stdOutHandle != IntPtr.Zero)
{
SetConsoleMode(_stdOutHandle, _originalOutputMode);
}
}
}

public void Dispose()
{
RestoreConsoleMode();
GC.SuppressFinalize(this);
}

~VirtualTerminalMode()
{
RestoreConsoleMode();
}
}
}
Loading
Loading