using System; using System.Collections.Generic; using System.Threading.Tasks; namespace PKISharp.WACS.Services { public interface IInputService { Task ChooseOptional(string what, IEnumerable options, Func> creator, string nullChoiceLabel) where TResult : class; Task ChooseRequired(string what, IEnumerable options, Func> creator); Task ChooseFromMenu(string what, List> choices, Func>? unexpected = null); Task PromptYesNo(string message, bool defaultOption); Task ReadPassword(string what); Task RequestString(string what); Task RequestString(string[] what); void CreateSpace(); void Show(string? label, string? value = null, int level = 0); Task Wait(string message = "Press to continue"); Task WritePagedList(IEnumerable listItems); string FormatDate(DateTime date); } public class Choice { public static Choice Create( TItem item, string? description = null, string? command = null, bool @default = false, (bool, string?)? disabled = null, ConsoleColor? color = null) { var newItem = new Choice(item); if (disabled == null) { disabled = (false, null); } // Default description is item.ToString, but it may // be overruled by the optional parameter here if (!string.IsNullOrEmpty(description)) { newItem.Description = description; } newItem.Command = command; newItem.Color = color; newItem.Disabled = disabled.Value.Item1; newItem.DisabledReason = disabled.Value.Item2; newItem.Default = @default; return newItem; } public string? Command { get; set; } public string? Description { get; set; } public bool Default { get; set; } public bool Disabled { get; set; } public string? DisabledReason { get; set; } public ConsoleColor? Color { get; set; } } public class Choice : Choice { public Choice(T item) { Item = item; if (item != null) { Description = item.ToString(); } } public T Item { get; } } }