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
8 changes: 7 additions & 1 deletion src/Tools/Common/Commands/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Collections.Generic;
using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tools.Common;

namespace Microsoft.Internal.Common.Utils
{
Expand Down Expand Up @@ -147,7 +148,12 @@ internal sealed class LineRewriter
{
public int LineToClear { get; set; }

public LineRewriter() { }
private IConsole Console { get; }

public LineRewriter(IConsole console)
{
Console = console;
}

// ANSI escape codes:
// [2K => clear current line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using Microsoft.Diagnostics.Tools.Common;

namespace Microsoft.Diagnostics.Tools.Counters.Exporters
namespace Microsoft.Diagnostics.Tools.Common
{
/// <summary>
/// The default implementation of IConsole maps everything to System.Console. In the future
Expand All @@ -27,10 +29,24 @@ public DefaultConsole(bool useAnsi)
public bool CursorVisible { get => Console.CursorVisible; set { Console.CursorVisible = value; } }
#pragma warning restore CA1416

public int CursorLeft => Console.CursorLeft;

public int CursorTop => Console.CursorTop;

public int BufferWidth => Console.BufferWidth;

public int BufferHeight => Console.BufferHeight;

public bool IsOutputRedirected => Console.IsOutputRedirected;

public bool IsInputRedirected => Console.IsInputRedirected;

public bool KeyAvailable => Console.KeyAvailable;

public TextWriter Out => Console.Out;

public TextWriter Error => Console.Error;

public void Clear()
{
if (_useAnsi)
Expand All @@ -57,5 +73,7 @@ public void SetCursorPosition(int col, int row)
public void Write(string text) => Console.Write(text);
public void WriteLine(string text) => Console.WriteLine(text);
public void WriteLine() => Console.WriteLine();
public ConsoleKeyInfo ReadKey() => Console.ReadKey();
public ConsoleKeyInfo ReadKey(bool intercept) => Console.ReadKey(intercept);
}
}
36 changes: 36 additions & 0 deletions src/Tools/Common/IConsole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;

namespace Microsoft.Diagnostics.Tools.Common
{
/// <summary>
/// Abstraction over console operations so tools can render to custom consoles in tests.
/// Mirrors the APIs dotnet-counters and dotnet-trace need for their renderers.
/// </summary>
internal interface IConsole
{
int WindowHeight { get; }
int WindowWidth { get; }
bool CursorVisible { get; set; }
int CursorLeft { get; }
int CursorTop { get; }
int BufferWidth { get; }
int BufferHeight { get; }
bool IsOutputRedirected { get; }
bool IsInputRedirected { get; }
bool KeyAvailable { get; }
TextWriter Out { get; }
TextWriter Error { get; }

void Clear();
void SetCursorPosition(int col, int row);
void Write(string text);
void WriteLine();
void WriteLine(string text);
ConsoleKeyInfo ReadKey();
ConsoleKeyInfo ReadKey(bool intercept);
}
}
1 change: 1 addition & 0 deletions src/Tools/dotnet-counters/CounterMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Diagnostics.Monitoring;
using Microsoft.Diagnostics.Monitoring.EventPipe;
using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tools.Common;
using Microsoft.Diagnostics.Tools.Counters.Exporters;
using Microsoft.Internal.Common.Utils;

Expand Down
1 change: 1 addition & 0 deletions src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.Linq;
using Microsoft.Diagnostics.Monitoring.EventPipe;
using Microsoft.Diagnostics.Tools.Common;

namespace Microsoft.Diagnostics.Tools.Counters.Exporters
{
Expand Down
32 changes: 0 additions & 32 deletions src/Tools/dotnet-counters/Exporters/IConsole.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Tools/dotnet-counters/dotnet-counters.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
<Compile Include="..\Common\WindowsProcessExtension\WindowsProcessExtension.cs" Link="WindowsProcessExtension.cs" />
<Compile Include="..\Common\CommandLineErrorException.cs" Link="CommandLineErrorException.cs" />
<Compile Include="..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
</ItemGroup>
<Compile Include="..\Common\IConsole.cs" Link="IConsole.cs" />
<Compile Include="..\Common\DefaultConsole.cs" Link="DefaultConsole.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Diagnostics.NETCore.Client\Microsoft.Diagnostics.NETCore.Client.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion src/Tools/dotnet-dump/dotnet-dump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<Compile Include="$(MSBuildThisFileDirectory)..\Common\Commands\Utils.cs" Link="Utils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\Common\ProcessNativeMethods\ProcessNativeMethods.cs" Link="ProcessNativeMethods.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\Common\WindowsProcessExtension\WindowsProcessExtension.cs" Link="WindowsProcessExtension.cs" />
<Compile Include="..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\Common\IConsole.cs" Link="IConsole.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Tools/dotnet-gcdump/dotnet-gcdump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Compile Include="..\Common\ProcessNativeMethods\ProcessNativeMethods.cs" Link="ProcessNativeMethods.cs" />
<Compile Include="..\Common\WindowsProcessExtension\WindowsProcessExtension.cs" Link="WindowsProcessExtension.cs" />
<Compile Include="..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
<Compile Include="..\Common\IConsole.cs" Link="IConsole.cs" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Tools/dotnet-stack/dotnet-stack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Compile Include="..\Common\ProcessNativeMethods\ProcessNativeMethods.cs" Link="ProcessNativeMethods.cs" />
<Compile Include="..\Common\WindowsProcessExtension\WindowsProcessExtension.cs" Link="WindowsProcessExtension.cs" />
<Compile Include="..\Common\DsRouterProcessLauncher.cs" Link="DsRouterProcessLauncher.cs" />
<Compile Include="..\Common\IConsole.cs" Link="IConsole.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading