public static async Task <string> Readline(WorkItemManager manager, WorkItem wi, PropertyDescriptor propertyDescriptor, string currentValue) { ReadLine.ClearHistory(); ReadLine.AutoCompletionHandler = null; if (propertyDescriptor.ValueProvider != null) { var valueProvider = manager.ValidationManager.CreateValueProvider(wi, propertyDescriptor.ValueProvider); if (valueProvider.IsUserExpierenceEnumerable) { foreach (var providedValue in await valueProvider.ProvideAllValuesAsync()) { ReadLine.AddHistory(providedValue.Value); } } ReadLine.AutoCompletionHandler = new ValueProviderReadLineAutoCompletion(valueProvider); } string result; if (string.IsNullOrWhiteSpace(currentValue)) { result = ReadLine.Read($"{propertyDescriptor.Name}: "); } else { result = ReadLine.Read($"{propertyDescriptor.Name} [{currentValue}]: "); } return(result); }
private static void SaveHistory() { if (ReadLine.HistoryEnabled) { //remove empty line var data = ReadLine.GetHistory().Where(a => !string.IsNullOrWhiteSpace(a)); ReadLine.ClearHistory(); ReadLine.AddHistory(data.ToArray()); File.WriteAllLines(GetHistoryFile(), data.Skip(Math.Max(0, data.Count() - 100))); } }
private static void CmdHistory(TextWriter output, CommandLineApplication app, bool onlyResult) { app.Command("history", cmd => { cmd.Description = "Show history command"; cmd.AddName("h"); var optEnabled = cmd.OptionEnum("--enabled|-e", "Enabled/Disable history", "0", "1"); cmd.OnExecute(() => { if (optEnabled.HasValue()) { ReadLine.HistoryEnabled = optEnabled.Value() == "1"; if (ReadLine.HistoryEnabled) { LoadHistory(); } else { ReadLine.ClearHistory(); } } else { if (!ReadLine.HistoryEnabled) { if (!onlyResult) { output.WriteLine("History disabled!"); } } else { var lineNum = 0; foreach (var item in ReadLine.GetHistory()) { output.WriteLine($"{lineNum} {item}"); lineNum++; } } } }); }); }
private static object Clear(params string[] args) { if (args.Length > 0) { foreach (var arg in args) { switch (arg) { case "screen": Console.Clear(); break; case "history": ReadLine.ClearHistory(); break; case "results": Common.Resuls.Clear(); break; case "variables": Common.CustomVariables.Clear(); break; case "all": case "*": Common.CustomVariables.Clear(); Common.Resuls.Clear(); ReadLine.ClearHistory(); Console.Clear(); break; } } } else { Console.Clear(); } GC.Collect(); return(null); }
public void Dispose() { // If all above tests pass // clear history works ReadLine.ClearHistory(); }