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

User friendly cli console write system #812

Merged
merged 33 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e06b2bb
user friendly cli log system
Jim8y Aug 14, 2021
cfd6831
add log class
Jim8y Aug 14, 2021
49c9813
add more log to wallet
Jim8y Aug 14, 2021
0673677
fix format
Jim8y Aug 14, 2021
e9504f2
change `consolelog` to `consolewrite`
Jim8y Aug 15, 2021
48d32fd
remove `WriteLine`
Jim8y Aug 15, 2021
5aa1153
Update ConsoleWrite.cs
shargon Aug 17, 2021
935db80
static class
erikzhang Aug 18, 2021
3397d76
Rename
erikzhang Aug 18, 2021
99af593
use colorset
Jim8y Aug 18, 2021
b257e8f
Update ConsoleHelper.cs
erikzhang Aug 18, 2021
b7fddd5
Optimize
erikzhang Aug 18, 2021
eac96f6
Update
erikzhang Aug 18, 2021
8994602
Update MainService.Plugins.cs
erikzhang Aug 18, 2021
ad5eab6
remove "\r"
Jim8y Aug 18, 2021
ac46dec
fix `list asset` color
Jim8y Aug 18, 2021
9e1b985
check all console output with `ConsoleHelper`
Jim8y Aug 18, 2021
40cdc85
update more console output
Jim8y Aug 18, 2021
05b47c4
add more `ConsoleHelper.Info` output
Jim8y Aug 18, 2021
f65a00f
fix some output format.
Jim8y Aug 18, 2021
5589219
add comments
Jim8y Aug 19, 2021
3324a05
Update MainService.NEP17.cs
erikzhang Aug 19, 2021
80693a3
Merge branch 'master' into color-output
shargon Aug 20, 2021
d59e1cf
update comment
Jim8y Aug 21, 2021
398c9a2
Merge branch 'master' into color-output
Jim8y Aug 25, 2021
2ca1312
update log
Jim8y Aug 26, 2021
0c1ff4c
Merge branch 'master' into color-output
superboyiii Aug 30, 2021
f8acfbf
improve
superboyiii Aug 30, 2021
159b039
improve more
superboyiii Aug 31, 2021
1b9e552
fix
superboyiii Aug 31, 2021
3452ade
Optimize
erikzhang Aug 31, 2021
a8fe751
fix
superboyiii Aug 31, 2021
0f983f3
Merge branch 'color-output' of https://github.com/Liaojinghui/neo-nod…
superboyiii Aug 31, 2021
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
43 changes: 43 additions & 0 deletions Neo.ConsoleService/ConsoleLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

namespace Neo.ConsoleService
{
public class ConsoleLog
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
{
public static void WriteLine(string msg)
{
Console.WriteLine(msg);
}

public static void Info(params string[] values)
{
for (int i = 0; i < values.Length; i++)
{
Console.ForegroundColor = ConsoleColor.Cyan;
if (i % 2 == 1)
Console.ForegroundColor = ConsoleColor.White;
Console.Write(values[i]);
}
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
}

public static void Warning(string msg)
{
Log("Warning", ConsoleColor.Yellow, msg);
}

public static void Error(string msg)
{
Log("Error", ConsoleColor.Red, msg);
}

private static void Log(string tag, ConsoleColor tagColor, string msg, ConsoleColor msgColor = ConsoleColor.White)
{
Console.ForegroundColor = tagColor;
Console.Write($"{tag}: ");
Console.ForegroundColor = msgColor;
Console.WriteLine(msg);
}
}
}
10 changes: 5 additions & 5 deletions Neo.ConsoleService/ConsoleServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public void Run(string[] args)
{
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
{
Console.WriteLine("Only support for installing services on Windows.");
ConsoleLog.Warning("Only support for installing services on Windows.");
return;
}
string arguments = string.Format("create {0} start= auto binPath= \"{1}\"", ServiceName, Process.GetCurrentProcess().MainModule.FileName);
Expand All @@ -536,7 +536,7 @@ public void Run(string[] args)
{
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
{
Console.WriteLine("Only support for installing services on Windows.");
ConsoleLog.Warning("Only support for installing services on Windows.");
return;
}
Process process = Process.Start(new ProcessStartInfo
Expand Down Expand Up @@ -609,16 +609,16 @@ public virtual void RunConsole()
{
if (!OnCommand(line))
{
Console.WriteLine("error: Command not found");
ConsoleLog.Error("Command not found");
}
}
catch (TargetInvocationException ex)
{
Console.WriteLine($"error: {ex.InnerException.Message}");
ConsoleLog.Error($" {ex.InnerException.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"error: {ex.Message}");
ConsoleLog.Error($" {ex.Message}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion neo-cli/CLI/MainService.NEP17.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void OnTransferCommand(UInt160 tokenHash, UInt160 to, decimal amount, UI
}
catch (InvalidOperationException e)
{
Console.WriteLine("Error: " + GetExceptionMessage(e));
ConsoleLog.Error(GetExceptionMessage(e));
return;
}
if (!ReadUserInput("Relay tx(no|yes)").IsYes())
Expand Down
10 changes: 5 additions & 5 deletions neo-cli/CLI/MainService.Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void OnBroadcastAddressCommand(IPAddress payload, ushort port)
{
if (payload == null)
{
Console.WriteLine("You must input the payload to relay.");
ConsoleLog.Warning("You must input the payload to relay.");
return;
}

Expand Down Expand Up @@ -124,7 +124,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay)
{
if (jsonObjectToRelay == null)
{
Console.WriteLine("You must input JSON object to relay.");
ConsoleLog.Warning("You must input JSON object to relay.");
return;
}

Expand All @@ -133,12 +133,12 @@ private void OnRelayCommand(JObject jsonObjectToRelay)
ContractParametersContext context = ContractParametersContext.Parse(jsonObjectToRelay.ToString(), NeoSystem.StoreView);
if (!context.Completed)
{
Console.WriteLine("The signature is incomplete.");
ConsoleLog.Error("The signature is incomplete.");
return;
}
if (!(context.Verifiable is Transaction tx))
{
Console.WriteLine($"Only support to relay transaction.");
ConsoleLog.Warning($"Only support to relay transaction.");
return;
}
tx.Witnesses = context.GetWitnesses();
Expand All @@ -147,7 +147,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay)
}
catch (Exception e)
{
Console.WriteLine("Error: " + GetExceptionMessage(e));
ConsoleLog.Error(GetExceptionMessage(e));
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions neo-cli/CLI/MainService.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ private void OnShowStateCommand()
int linesWritten = 1;
foreach (RemoteNode node in LocalNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray())
{
Console.WriteLine(
$" ip: {node.Remote.Address,-15}\tport: {node.Remote.Port,-5}\tlisten: {node.ListenerTcpPort,-5}\theight: {node.LastBlockIndex,-7}");
ConsoleLog.Info($"\r ip: ",
$"{ node.Remote.Address,-15}\t",
$"port: ",
$"{node.Remote.Port,-5}\t",
$"listen: ",
$"{node.ListenerTcpPort,-5}\t",
$"height: ",
$"{node.LastBlockIndex,-7}");
linesWritten++;
}

Expand Down
10 changes: 5 additions & 5 deletions neo-cli/CLI/MainService.Plugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void OnInstallCommand(string pluginName)
try
{
zip.ExtractToDirectory(".");
Console.WriteLine($"Install successful, please restart neo-cli.");
ConsoleLog.Warning($"Install successful, please restart neo-cli.");
}
catch (IOException)
{
Expand All @@ -73,12 +73,12 @@ private void OnUnInstallCommand(string pluginName)
var plugin = Plugin.Plugins.FirstOrDefault(p => p.Name == pluginName);
if (plugin is null)
{
Console.WriteLine("Plugin not found");
ConsoleLog.Warning("Plugin not found");
return;
}
if (plugin is Logger)
{
Console.WriteLine("You cannot uninstall a built-in plugin.");
ConsoleLog.Error("You cannot uninstall a built-in plugin.");
return;
}

Expand All @@ -91,7 +91,7 @@ private void OnUnInstallCommand(string pluginName)
catch (IOException)
{
}
Console.WriteLine($"Uninstall successful, please restart neo-cli.");
ConsoleLog.Warning($"Uninstall successful, please restart neo-cli.");
}

/// <summary>
Expand All @@ -106,7 +106,7 @@ private void OnPluginsCommand()
foreach (Plugin plugin in Plugin.Plugins)
{
if (plugin is Logger) continue;
Console.WriteLine($"\t{plugin.Name,-20}{plugin.Description}");
ConsoleLog.Info($"\t{plugin.Name,-20}", $"{plugin.Description}");
}
}
else
Expand Down
28 changes: 14 additions & 14 deletions neo-cli/CLI/MainService.Vote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ private void OnRegisterCandidateCommand(UInt160 account)

if (NoWallet())
{
Console.WriteLine("Need open wallet!");
ConsoleLog.Warning("Need open wallet!");
return;
}

WalletAccount currentAccount = CurrentWallet.GetAccount(account);

if (currentAccount == null)
{
Console.WriteLine("This address isn't in your wallet!");
ConsoleLog.Warning("This address isn't in your wallet!");
return;
}
else
{
if (currentAccount.Lock || currentAccount.WatchOnly)
{
Console.WriteLine("Locked or WatchOnly address.");
ConsoleLog.Warning("Locked or WatchOnly address.");
return;
}
}
Expand All @@ -65,22 +65,22 @@ private void OnUnregisterCandidateCommand(UInt160 account)
{
if (NoWallet())
{
Console.WriteLine("Need open wallet!");
ConsoleLog.Warning("Need open wallet!");
return;
}

WalletAccount currentAccount = CurrentWallet.GetAccount(account);

if (currentAccount == null)
{
Console.WriteLine("This address isn't in your wallet!");
ConsoleLog.Warning("This address isn't in your wallet!");
return;
}
else
{
if (currentAccount.Lock || currentAccount.WatchOnly)
{
Console.WriteLine("Locked or WatchOnly address.");
ConsoleLog.Warning("Locked or WatchOnly address.");
return;
}
}
Expand All @@ -106,7 +106,7 @@ private void OnVoteCommand(UInt160 senderAccount, ECPoint publicKey)
{
if (NoWallet())
{
Console.WriteLine("Need open wallet!");
ConsoleLog.Warning("Need open wallet!");
return;
}

Expand All @@ -129,7 +129,7 @@ private void OnUnvoteCommand(UInt160 senderAccount)
{
if (NoWallet())
{
Console.WriteLine("Need open wallet!");
ConsoleLog.Warning("Need open wallet!");
return;
}

Expand All @@ -156,7 +156,7 @@ private void OnGetCandidatesCommand()
if (resJArray.Count > 0)
{
Console.WriteLine();
Console.WriteLine("Candidates:");
ConsoleLog.Info("Candidates:");

foreach (var item in resJArray)
{
Expand All @@ -181,7 +181,7 @@ private void OnGetCommitteeCommand()
if (resJArray.Count > 0)
{
Console.WriteLine();
Console.WriteLine("Committee:");
ConsoleLog.Info("Committee:");

foreach (var item in resJArray)
{
Expand All @@ -203,7 +203,7 @@ private void OnGetNextBlockValidatorsCommand()
if (resJArray.Count > 0)
{
Console.WriteLine();
Console.WriteLine("Next validators:");
ConsoleLog.Info("Next validators:");

foreach (var item in resJArray)
{
Expand Down Expand Up @@ -240,9 +240,9 @@ private void OnGetAccountState(UInt160 address)
}
}
var publickey = ECPoint.Parse(((ByteString)resJArray?[2])?.GetSpan().ToHexString(), ECCurve.Secp256r1);
Console.WriteLine("Voted: " + Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion));
Console.WriteLine("Amount: " + new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals));
Console.WriteLine("Block: " + ((Integer)resJArray?[1]).GetInteger());
ConsoleLog.Info("Voted: ", Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion));
ConsoleLog.Info("Amount: ", $"{new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals)}");
ConsoleLog.Info("Block: ", $"{((Integer)resJArray?[1]).GetInteger()}");
}
}
}
Loading