Skip to content
21 changes: 18 additions & 3 deletions src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public ObservedTagSet(string tags)
private readonly object _lock = new object();
private readonly Dictionary<string, ObservedProvider> _providers = new Dictionary<string, ObservedProvider>(); // Tracks observed providers and counters.
private const int Indent = 4; // Counter name indent size.
private int _maxNameLength = 40; // Allow room for 40 character counter names by default.
private const int CounterValueLength= 20;

private int _maxNameLength = 60; // Allow room for 60 character counter names by default.
private int _statusRow; // Row # of where we print the status of dotnet-counters
private int _topRow;
private bool _paused = false;
Expand All @@ -69,6 +70,9 @@ public ObservedTagSet(string tags)
private int _maxRow = -1;
private bool _useAnsi = false;

private int _consoleHeight = -1;
private int _consoleWidth = -1;

public ConsoleWriter(bool useAnsi)
{
this._useAnsi = useAnsi;
Expand Down Expand Up @@ -126,9 +130,15 @@ public void AssignRowsAndInitializeDisplay()
{
Clear();

_consoleWidth = Console.WindowWidth;
_consoleHeight = Console.WindowHeight;
_maxNameLength = _consoleWidth < 80 ? _consoleWidth - CounterValueLength: 60; // truncate the display name when the window width is less than 80

int row = Console.CursorTop;
_topRow = row;
Console.WriteLine("Press p to pause, r to resume, q to quit."); row++;

string instructions = "Press p to pause, r to resume, q to quit.";
Console.WriteLine((instructions.Length < _consoleWidth) ? instructions : instructions.Substring(0, _consoleWidth)); row++;
Console.WriteLine($" Status: {GetStatus()}"); _statusRow = row++;
if (_errorText != null)
{
Expand All @@ -146,7 +156,7 @@ public void AssignRowsAndInitializeDisplay()
counter.Row = row++;
if (counter.RenderValueInline)
{
Console.WriteLine($"{name} {FormatValue(counter.LastValue)}");
Console.WriteLine((_consoleWidth > CounterValueLength) ? $"{name} {FormatValue(counter.LastValue)}" : $"{FormatValue(counter.LastValue)}");
}
else
{
Expand Down Expand Up @@ -222,6 +232,11 @@ public void CounterPayloadReceived(CounterPayload payload, bool pauseCmdSet)
redraw = true;
}

if(Console.WindowWidth != _consoleWidth || Console.WindowHeight != _consoleHeight)
{
redraw=true;
}

if (redraw)
{
AssignRowsAndInitializeDisplay();
Expand Down