Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph flicker fix #120

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions powerping_todo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
beep with no argument
flood doesnt work

graph flicker
graph not fill screen
graph break when console buffer is big enough
graph scale is fucked
139 changes: 131 additions & 8 deletions src/Commands/Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,22 @@ private void Clear()
// Set cursor position to start of plot
Console.SetCursorPosition(m_PlotStartX, m_yAxisStart);//m_PlotStartY);

string blankRow = new string(' ', m_xAxisLength);
string padding = new string(' ', m_PlotStartX);
string blankRow = padding + new string(' ', m_xAxisLength);
string bottomRow = new string('─', m_xAxisLength);

//Console.CursorTop = m_PlotStartY;

for (int x = 0; x <= m_yAxisLength; x++) { //21; x++) {
// Draw black spaces
Console.Write(blankRow);
Console.WriteLine(blankRow);
Console.CursorLeft = m_PlotStartX;
Console.CursorTop = m_PlotStartY - x;
//Console.CursorTop = m_PlotStartY - x;
}

// Draw bottom row
Console.CursorTop = m_PlotStartY;
Console.Write(bottomRow);
Console.WriteLine(bottomRow);

// Reset cursor to starting position
Console.SetCursorPosition(cursorPositionX, cursorPositionY);
Expand Down Expand Up @@ -275,6 +278,7 @@ private void AddResponseToGraph(double responseTime)
}
}

List<int> count = new List<int>();
/// <summary>
/// Draw all graph coloums/bars
/// </summary>
Expand All @@ -283,8 +287,125 @@ private void DrawColumns()
// Clear columns space before drawing
Clear();

List<string[]> columns = new List<string[]>();
foreach (var response in m_ResponseTimes) {
columns.Add(CreateColumn(response));
}

bool alternating = true;
Console.CursorTop = 1;
for (int x = m_yAxisLength; x > 0; x--) {
string test = "";
Console.CursorLeft = m_PlotStartX;// m_yAxisLeftPadding;
for (int i = 0; i < columns.Count; i++) {
if (x >= columns[i].Length)
test += " ";
else
test += columns[i][x];

}

if (alternating)
Console.ForegroundColor = ConsoleColor.Gray;
else
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(test);
alternating = !alternating;
}

Console.ResetColor();


List<string[]> timeoutColumns = new List<string[]>();
bool startTimeout = false;
for (int i = 0; i < m_ResponseTimes.Count; i++) { //foreach (var response in m_ResponseTimes) {
string[] column = new string[m_yAxisLength + 1];
if (m_ResponseTimes[i] == 0) {
for (int x = 0; x < column.Length; x++) {
column[x] = "|";
}
column[0] = "┴";

} else {
string tempChar = "#";


for (int x = 0; x < column.Length; x++) {
column[x] = tempChar;
}
column[0] = tempChar;
}
timeoutColumns.Add(column);
}

Console.CursorTop = 1;
List<int> offsets = new List<int>();
List<string> sections = new List<string>();
for (int y = m_yAxisLength; y > 0; y--) {

//Console.CursorLeft = m_PlotStartX;// m_yAxisLeftPadding;

string test = "";
int offset = m_PlotStartX;
int currentIndex = 0;
bool timeoutSection = false;
for (int x = 0; x < timeoutColumns.Count; x++) {
if (y >= timeoutColumns[x].Length) {
test += " ";
} else {
offset++;

string piece = timeoutColumns[x][y];
if (piece == "#") {
continue;
} else if (piece == "|" || piece == "┴") {
test += piece;

if (!timeoutSection) {
offsets.Add(offset);
sections.Add(piece);
}
else {
sections[currentIndex] += piece;
//currentIndex++;
}

timeoutSection = !timeoutSection;
} else if (piece == " ") {
//test += piece;
sections[currentIndex] += piece;
}


//if (x == timeoutColumns.Count) {
// sections.Add(test);
// test = "";
//}
}
}

Console.ForegroundColor = ConsoleColor.Red;
//int currentOffset = m_PlotStartX;
for (int j = 0; j < offsets.Count; j++) {
//currentOffset += offsets[j];// + 1;
Console.CursorLeft = offsets[j] - 1;//currentOffset;// - offsets.Count;// m_PlotStartX + offsets[j] + 1;
Console.Write(sections[j]);
//currentOffset += sections[j].Length;
}

Console.CursorLeft = m_PlotStartX;
Console.WriteLine();
Console.ResetColor();

offsets.Clear();
sections.Clear();
}

return;


for (int x = 0; x < m_ResponseTimes.Count; x++) {

// This causes us to draw a continous lower line of red when we are continously timing out
// Instead of always drawing big red lines, we draw them at either end of the continous zone
// I think it will just look nicer, it will cause slightly hackier code but oh well
Expand All @@ -311,7 +432,9 @@ private void DrawColumns()
drawTimeoutSegment = true;
}

DrawSingleColumn(CreateColumn(m_ResponseTimes[x]), current, timeout, drawTimeoutSegment);
var c = CreateColumn(m_ResponseTimes[x]);
DrawSingleColumn(c, current, timeout, drawTimeoutSegment);
count.Add(c.Length);

Console.CursorLeft++;
}
Expand Down Expand Up @@ -345,9 +468,9 @@ private string[] CreateColumn(double replyTime)
// If no reply dont draw column
string[] timeoutBar = new string[m_yAxisLength + 1];
for (int x = 0; x < timeoutBar.Length; x++) {
timeoutBar[x] = "|";
timeoutBar[x] = " ";// "|";
}
timeoutBar[0] = "┴";
timeoutBar[0] = " ";//"┴";
return timeoutBar;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Ping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Ping {
private int m_PacketSize = 0;
private IPEndPoint m_RemoteEndpoint = null;
private readonly CancellationToken m_CancellationToken;
private bool m_Debug = false;
private bool m_Debug = true;

private ushort m_CurrentSequenceNumber = 0;
private int m_CurrentReceiveTimeout = 0;
Expand Down