Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Solve the issue of console flicker (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y authored and erikzhang committed Jan 21, 2019
1 parent ad4c87e commit 93ac65e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions neo-cli/Shell/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,22 +821,29 @@ private bool OnShowPoolCommand(string[] args)
private bool OnShowStateCommand(string[] args)
{
bool stop = false;
Task.Run(() =>
Console.CursorVisible = false;
Console.Clear();
Task task = Task.Run(() =>
{
while (!stop)
{
Console.SetCursorPosition(0, 0);
uint wh = 0;
if (Program.Wallet != null)
wh = (Program.Wallet.WalletHeight > 0) ? Program.Wallet.WalletHeight - 1 : 0;
Console.Clear();
Console.WriteLine($"block: {wh}/{Blockchain.Singleton.Height}/{Blockchain.Singleton.HeaderHeight} connected: {LocalNode.Singleton.ConnectedCount} unconnected: {LocalNode.Singleton.UnconnectedCount}");
WriteLineWithoutFlicker($"block: {wh}/{Blockchain.Singleton.Height}/{Blockchain.Singleton.HeaderHeight} connected: {LocalNode.Singleton.ConnectedCount} unconnected: {LocalNode.Singleton.UnconnectedCount}");
foreach (RemoteNode node in LocalNode.Singleton.GetRemoteNodes().Take(Console.WindowHeight - 2))
Console.WriteLine($" ip: {node.Remote.Address}\tport: {node.Remote.Port}\tlisten: {node.ListenerPort}\theight: {node.Version?.StartHeight}");
WriteLineWithoutFlicker($" ip: {node.Remote.Address}\tport: {node.Remote.Port}\tlisten: {node.ListenerPort}\theight: {node.Version?.StartHeight}");
while (Console.CursorTop + 1 < Console.WindowHeight)
WriteLineWithoutFlicker();
Thread.Sleep(500);
}
});
Console.ReadLine();
stop = true;
task.Wait();
Console.WriteLine();
Console.CursorVisible = true;
return true;
}

Expand Down Expand Up @@ -1039,5 +1046,11 @@ private static Wallet OpenWallet(WalletIndexer indexer, string path, string pass
return nep6wallet;
}
}

private static void WriteLineWithoutFlicker(string message = "")
{
Console.Write(message);
Console.Write(new string(' ', Console.BufferWidth - Console.CursorLeft));

This comment has been minimized.

Copy link
@jsolman

jsolman Mar 2, 2019

Contributor

This is basically broken on Linux. Console.CursorLeft can take seconds to minutes to return; see https://github.com/dotnet/corefx/issues/31517

This comment has been minimized.

Copy link
@jsolman

jsolman Mar 2, 2019

Contributor

Fixed in #306

}
}
}

0 comments on commit 93ac65e

Please sign in to comment.