private static void RunEvalLoop() { while (true) { try { if (Terminal != Terminal.Cmder) { Colorful.Console.ForegroundColor = ColorScheme.Text; } const int bufferSize = 1024 * 16; string statement; using (Stream inStream = System.Console.OpenStandardInput(bufferSize)) { Colorful.Console.SetIn(new StreamReader(inStream, Colorful.Console.InputEncoding, false, bufferSize)); CliConsole.WriteLessImportant("nethermind> "); statement = Terminal == Terminal.Cygwin ? Colorful.Console.ReadLine() : ReadLine.Read(); statement = RemoveDangerousCharacters(statement); HistoryManager.UpdateHistory(statement); } if (statement == "exit") { break; } JsValue result = Engine.Execute(statement); WriteResult(result); } catch (Exception e) { CliConsole.WriteException(e); } } }
public void Warn(string text) { CliConsole.WriteLessImportant(text); }
private static void RunEvalLoop() { try { if (File.Exists(HistoryFilePath)) { foreach (string line in File.ReadLines(HistoryFilePath).TakeLast(60)) { if (line != _removedString) { ReadLine.AddHistory(line); } } } } catch (Exception e) { CliConsole.WriteErrorLine($"Could not load cmd history from {HistoryFilePath} {e.Message}"); } ReadLine.AutoCompletionHandler = new AutoCompletionHandler(); while (true) { try { if (_terminal != Terminal.Cmder) { Console.ForegroundColor = ColorScheme.Text; } int bufferSize = 1024 * 16; string statement; using (Stream inStream = System.Console.OpenStandardInput(bufferSize)) { Console.SetIn(new StreamReader(inStream, Console.InputEncoding, false, bufferSize)); CliConsole.WriteLessImportant("nethermind> "); statement = _terminal == Terminal.Cygwin ? Console.ReadLine() : ReadLine.Read(); CleanStatement(statement); if (!File.Exists(HistoryFilePath)) { File.Create(HistoryFilePath).Dispose(); } if (!SecuredCommands.Any(sc => statement.Contains(sc))) { ReadLine.AddHistory(statement); using (var fileStream = File.AppendText(HistoryFilePath)) { fileStream.WriteLine(statement); } } else { ReadLine.AddHistory(_removedString); } } if (statement == "exit") { break; } JsValue result = _engine.Execute(statement); if (result.IsObject() && result.AsObject().Class == "Function") { CliConsole.WriteGood(result.ToString()); CliConsole.WriteLine(); } else if (!result.IsNull()) { string text = Serializer.Serialize(result.ToObject(), true); // File.AppendAllText("C:\\temp\\cli.txt", text); CliConsole.WriteGood(text); } else { CliConsole.WriteLessImportant("null"); CliConsole.WriteLine(); } // bool isNull = result.IsNull(); // if (!isNull) // { // CliConsole.WriteString(result); // } } catch (Exception e) { CliConsole.WriteException(e); } } }