diff --git a/ExtendedConsole/ExConsole.cs b/ExtendedConsole/ExConsole.cs index 2444053..eac0b24 100644 --- a/ExtendedConsole/ExConsole.cs +++ b/ExtendedConsole/ExConsole.cs @@ -26,15 +26,17 @@ public class ExConsole /// /// Markup text to write. /// Thrown when markup text isn't properly formatted xml. + /// The current instance of . /// /// Write "Hello World!", cyan on a dark gray background. /// /// exConsole.Write("<c f='cyan' b='darkgray'>Hello World!<c>"); /// /// - public void Write(string markup) + public ExConsole Write(string markup) { Parser.ParseMarkeup(markup).Write(); + return this; } /// @@ -42,6 +44,7 @@ public void Write(string markup) /// /// Markup text to write. /// Thrown when markup text isn't properly formatted xml. + /// The current instance of . /// /// Write "Hello World!", black on a white background, /// and advance the cursor to the next line. @@ -49,9 +52,10 @@ public void Write(string markup) /// exConsole.WriteLine("<c b='white' f='black'>Hello World!<c>"); /// /// - public void WriteLine(string markup) + public ExConsole WriteLine(string markup) { Parser.ParseMarkeup(markup).WriteLine(); + return this; } /// @@ -59,6 +63,7 @@ public void WriteLine(string markup) /// /// Lines of markup text to write. /// Thrown when markup text isn't properly formatted xml. + /// The current instance of . /// /// Write "Hello World!" in yellow, /// "This is exConsole writing multiple markup lines" in the next line, with exConsole in green, and @@ -71,12 +76,13 @@ public void WriteLine(string markup) /// ); /// /// - public void WriteLines(params string[] lines) + public ExConsole WriteLines(params string[] lines) { foreach(var line in lines) { WriteLine(line); } + return this; } /// @@ -87,16 +93,15 @@ public void WriteLines(params string[] lines) /// Foreground color. /// Background color. /// Thrown when markup text isn't properly formatted xml. + /// The current instance of . /// /// Write "Hello World!" in magenta, followed by "How are you?" in black on a white background. Advance the cursor to the next line. /// /// exConsole.WriteLine("Hello world! <c b='white' f='black'>How are you?<c>", ConsoleColor.Magenta, null); /// /// - public void WriteLine(string markup, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor) - { - WriteInColor(() => WriteLine(markup), foregroundColor, backgroundColor); - } + public ExConsole WriteLine(string markup, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor) + => WriteInColor(() => WriteLine(markup), foregroundColor, backgroundColor); /// /// Changes console colors to the specified colors, and writes the specified markup to the console. @@ -105,17 +110,15 @@ public void WriteLine(string markup, ConsoleColor? foregroundColor, ConsoleColor /// Foreground color. /// Background color. /// Thrown when markup text isn't properly formatted xml. + /// The current instance of . /// /// Write "Hello World!" in black on a magenta background, followed by "How are you?" in black on a white background. /// /// exConsole.Write("Hello world! <c b='white' f='black'>How are you?<c>", ConsoleColor.Black, ConsoleColor.Magenta); /// /// - public void Write(string markup, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor) - { - - WriteInColor(() => Write(markup), foregroundColor, backgroundColor); - } + public ExConsole Write(string markup, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor) + => WriteInColor(() => Write(markup), foregroundColor, backgroundColor); // // Writes the specified text with the specified colors, @@ -125,7 +128,8 @@ public void Write(string markup, ConsoleColor? foregroundColor, ConsoleColor? ba // Foreground color. // Background color. // Thrown when markup text isn't properly formatted xml. - private void WriteInColor(Action action, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor) + // The current instance of. + private ExConsole WriteInColor(Action action, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor) { var (Foreground, Background) = (Console.ForegroundColor, Console.BackgroundColor); Console.ForegroundColor = foregroundColor ?? Foreground; @@ -135,6 +139,8 @@ private void WriteInColor(Action action, ConsoleColor? foregroundColor, ConsoleC Console.ForegroundColor = Foreground; Console.BackgroundColor = Background; + + return this; } } } diff --git a/ExtendedConsole/ExConsoleChooseFromEnum.cs b/ExtendedConsole/ExConsoleChooseFromEnum.cs new file mode 100644 index 0000000..32be456 --- /dev/null +++ b/ExtendedConsole/ExConsoleChooseFromEnum.cs @@ -0,0 +1,256 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ExtendedConsole +{ + /// + /// Provides extension methods for ExConsole to support simple menus based on enum values. + /// + public static class ExConsoleChooseFromEnum + { + /// + /// Displays enum members as a menu for the user to choose from. + /// + /// The type of the enum. + /// The current instance of ExConsole. + /// The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + /// An instance of the class holding the display configuration of the enum based menu. + /// The member of the enum the user selected, or null if the user selected the "quit" menu item. + /// Thrown when , or any of its properties, or are null. + /// Thrown when any of the string properties of or are empty. + /// Thrown when any of the string properties of or are not properly formatted xml. + /// + /// Display the names of the members of the ConsoleColor enum, + /// asking the user to choose a color from the list, or "none". + /// the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + /// + /// var color = exConsole.ChooseFromEnum<ConsoleColor>( + /// "<c f='red'>none</c>", + /// new MenuDisplayArgs( + /// "Choose a foreground color", + /// "Please choose a color or <c f='red>none</c> to keep current color.", + /// invalidSelectionErrorMessage:"Please choose from the above list.") + /// ); + /// + /// + public static T? ChooseFromEnum(this ExConsole self, string quitText, MenuDisplayArgs displayArgs) where T : struct, Enum + { + if (quitText is null) throw new ArgumentNullException(nameof(quitText)); + if (quitText == "") throw new ArgumentException(nameof(quitText) + " can't be empty.", nameof(quitText)); + + var names = Enum.GetNames(typeof(T)).ToList(); + names.Insert(0, quitText); + var result = ExConsoleMenu.Menu(self, displayArgs, names.ToArray()); + if (result == 0) return null; + + return (T?)Enum.Parse(typeof(T), names[result]); + } + + /// + /// Displays enum members as a menu for the user to choose from. + /// + /// The type of the enum. + /// The current instance of ExConsole. + /// An instance of the class holding the display configuration of the enum based menu. + /// The member of the enum the user selected. + /// Thrown when , or any of its properties are null. + /// Thrown when any of the string properties of are empty. + /// Thrown when any of the string properties of are not properly formatted xml. + /// + /// Display the names of the members of the ConsoleColor enum, + /// asking the user to choose a color from the list. + /// the color variable is of type ConsoleColor. + /// + /// var color = exConsole.ChooseFromEnum<ConsoleColor>( + /// new MenuDisplayArgs( + /// "Choose a foreground color", + /// "Please choose a color.", + /// false, + /// "Please choose from the above list.") + /// ); + /// + /// + public static T ChooseFromEnum(this ExConsole self, MenuDisplayArgs displayArgs) where T : Enum + { + var names = Enum.GetNames(typeof(T)); + var result = ExConsoleMenu.Menu(self, displayArgs, names); + return (T)Enum.Parse(typeof(T), names[result]); + } + + /// + /// Note: + /// + /// This method is deprecated and will be removed in future versions. + /// Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + /// + /// + /// Displays enum members as a menu for the user to choose from. + /// + /// + /// The type of the enum. + /// The current instance of . + /// The title of the menu. + /// A boolean value to determine + /// whether the menu should still be displayed after the user have chosen an option. + /// The member of the enum the user selected. + /// Thrown when or are null. + /// Thrown when is empty. + /// Thrown when isn't properly formatted xml. + /// + /// Display the names of the members of the ConsoleColor enum, + /// asking the user to choose a color from the list. + /// the color variable is of type ConsoleColor. + /// + /// var color = exConsole.ChooseFromEnum<ConsoleColor>( + /// "Choose a foreground color", + /// true + /// ); + /// + /// + [Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the ChooseFromEnum overload that takes an instance of MenuDisplayArgs as an argument instead.")] + public static T ChooseFromEnum(this ExConsole self, string title, bool clearWhenSelected) where T : Enum + { + var names = Enum.GetNames(typeof(T)); + var result = ExConsoleMenu.Menu(self, title, clearWhenSelected, names); + return (T)Enum.Parse(typeof(T), names[result]); + } + + /// + /// Note: + /// + /// This method is deprecated and will be removed in future versions. + /// Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + /// + /// + /// Displays enum members as a menu for the user to choose from. + /// + /// + /// The type of the enum. + /// The current instance of ExConsole. + /// The title of the menu. + /// The text to show below the menu. + /// The text to show when the user enters an invalid value. + /// A boolean value to determine + /// whether the menu should still be displayed after the user have chosen an option. + /// The member of the enum the user selected. + /// Thrown when , , or are null. + /// Thrown when any of , or is empty. + /// Thrown when , or are not properly formatted xml. + /// + /// Display the names of the members of the ConsoleColor enum, + /// asking the user to choose a color from the list. + /// the color variable is of type ConsoleColor. + /// + /// var color = exConsole.ChooseFromEnum<ConsoleColor>( + /// "Choose a foreground color", + /// "Please choose a color.", + /// "Please choose from the above list.", + /// true + /// ); + /// + /// + [Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the ChooseFromEnum overload that takes an instance of MenuDisplayArgs as an argument instead.")] + public static T ChooseFromEnum(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected) where T : Enum + { + var names = Enum.GetNames(typeof(T)); + var result = ExConsoleMenu.Menu(self, title, pleaseSelectText, invalidSelectionText, clearWhenSelected, names); + return (T)Enum.Parse(typeof(T), names[result]); + } + + /// + /// Note: + /// + /// This method is deprecated and will be removed in future versions. + /// Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + /// + /// + /// Displays enum members as a menu for the user to choose from. + /// + /// + /// The type of the enum. + /// The current instance of ExConsole. + /// The title of the menu. + /// The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + /// A boolean value to determine + /// whether the menu should still be displayed after the user have chosen an option. + /// The member of the enum the user selected. + /// Thrown when or are null. + /// Thrown when is empty. + /// Thrown when isn't properly formatted xml. + /// + /// Display the names of the members of the ConsoleColor enum, + /// asking the user to choose a color from the list, or "none". + /// the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + /// + /// var color = exConsole.ChooseFromEnum<ConsoleColor>( + /// "Choose a foreground color, or <c f='red>none</c> to keep current color.", + /// "<c f='red'>none</c>", + /// true + /// ); + /// + /// + [Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the ChooseFromEnum overload that takes a string and an instance of MenuDisplayArgs as an argument instead.")] + public static T? ChooseFromEnum(this ExConsole self, string title, string quitText, bool clearWhenSelected) where T : struct, Enum + { + var names = Enum.GetNames(typeof(T)).ToList(); + names.Insert(0, quitText); + var result = ExConsoleMenu.Menu(self, title, clearWhenSelected, names.ToArray()); + if (result == 0) return null; + + return (T?)Enum.Parse(typeof(T), names[result]); + } + + /// + /// Note: + /// + /// This method is deprecated and will be removed in future versions. + /// Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + /// + /// + /// Displays enum members as a menu for the user to choose from. + /// + /// + /// The type of the enum. + /// The current instance of ExConsole. + /// The title of the menu. + /// The text to show below the menu. + /// The text to show when the user enters an invalid value. + /// The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + /// A boolean value to determine + /// whether the menu should still be displayed after the user have chosen an option. + /// The member of the enum the user selected. + /// Thrown when , , , or are null. + /// Thrown when any of , , or is empty. + /// Thrown when , , or are not properly formatted xml. + /// + /// Display the names of the members of the ConsoleColor enum, + /// asking the user to choose a color from the list, or "none". + /// the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + /// + /// var color = exConsole.ChooseFromEnum<ConsoleColor>( + /// "Choose a foreground color", + /// "Please choose a color or <c f='red>none</c> to keep current color.", + /// "Please choose from the above list.", + /// "<c f='red'>none</c>", + /// true + /// ); + /// + /// + [Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the ChooseFromEnum overload that takes a string and an instance of MenuDisplayArgs as an argument instead.")] + public static T? ChooseFromEnum(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, string quitText, bool clearWhenSelected) where T : struct, Enum + { + if (quitText is null) throw new ArgumentNullException(nameof(quitText)); + if (quitText == "") throw new ArgumentException(nameof(quitText) + " can't be empty.", nameof(quitText)); + + var names = Enum.GetNames(typeof(T)).ToList(); + names.Insert(0, quitText); + var result = ExConsoleMenu.Menu(self, title, pleaseSelectText, invalidSelectionText, clearWhenSelected, names.ToArray()); + if (result == 0) return null; + + return (T?)Enum.Parse(typeof(T), names[result]); + } + + } +} diff --git a/ExtendedConsole/ExConsoleClearLines.cs b/ExtendedConsole/ExConsoleClearLines.cs index 05fe24e..65afcbc 100644 --- a/ExtendedConsole/ExConsoleClearLines.cs +++ b/ExtendedConsole/ExConsoleClearLines.cs @@ -8,6 +8,21 @@ namespace ExtendedConsole /// public static class ExConsoleClearLines { + /// + /// Clears all text from the current line. + /// + /// The current instance of ExConsole. + /// The current instance of . + /// + /// Clears the current line of the console. + /// + /// exConsole.ClearCurrentLine(); + /// + /// + public static ExConsole ClearCurrentLine(this ExConsole self) + { + return ClearLine(self, Console.CursorTop); + } /// /// Clears all text from a specific line. @@ -15,52 +30,59 @@ public static class ExConsoleClearLines /// The current instance of ExConsole. /// Line index to clear. /// Thrown if is less than zero. + /// The current instance of . /// /// Clear the second line from the top. /// /// exConsole.ClearLine(1); /// /// - public static void ClearLine(this ExConsole self, int lineIndex) + public static ExConsole ClearLine(this ExConsole self, int lineIndex) { if (lineIndex < 0) throw new ArgumentOutOfRangeException($"{nameof(lineIndex)} can't be a negative value."); Console.SetCursorPosition(0, lineIndex); Console.WriteLine(new string(' ', Console.BufferWidth)); Console.SetCursorPosition(0, lineIndex); + + return self; } + /// /// Clears all text from the last line. /// /// The current instance of ExConsole. + /// The current instance of . /// /// Clear the last line. /// /// exConsole.ClearLastLine(); /// /// - public static void ClearLastLine(this ExConsole self) + public static ExConsole ClearLastLine(this ExConsole self) { if (Console.CursorTop > 0) { ClearLine(self, Console.CursorTop - 1); } + return self; } /// /// Clears all text from the last lines. /// - /// The current instance of ExConsole. + /// The current instance of . /// The number of lines to clear (count up from last line) /// Thrown if is less than one. + /// The current instance of . /// /// Clear the last three lines. /// /// exConsole.ClearLastLines(3); /// /// - public static void ClearLastLines(this ExConsole self, int numberOfLines) + public static ExConsole ClearLastLines(this ExConsole self, int numberOfLines) { if (numberOfLines < 1) throw new ArgumentOutOfRangeException($"{nameof(numberOfLines)} must be a positive value."); @@ -68,6 +90,27 @@ public static void ClearLastLines(this ExConsole self, int numberOfLines) { ClearLastLine(self); } + return self; + } + + /// + /// Clears all the text on the console, and returns the current instance of ExConsole. + /// + /// The current instance of . + /// The current instance of . + /// + /// Pause, clear all lines, and ask the user to enter an integer value: + /// + /// exConsole + /// .Pause("Press any key to continue") + /// .ClearAllLines() + /// .ReadInt("Please enter a number:"); + /// + /// + public static ExConsole ClearAllLines(this ExConsole self) + { + Console.Clear(); + return self; } } } diff --git a/ExtendedConsole/ExConsoleMenu.cs b/ExtendedConsole/ExConsoleMenu.cs index acfee1f..cbf57d5 100644 --- a/ExtendedConsole/ExConsoleMenu.cs +++ b/ExtendedConsole/ExConsoleMenu.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; namespace ExtendedConsole @@ -13,6 +14,102 @@ public static class ExConsoleMenu /// Displays a menu to the user and invokes the action the user chooses. /// /// The current instance of ExConsole. + /// An instance of the class holding the display configuration of the menu. + /// The items of the menu. + /// Each item contains a title and an action to perform, should the user choses this item. + /// null can be passed in as the action if the item selection should perform no action. + /// An integer representing the user's choice. + /// Thrown when or or any of it's properties are null. + /// Thrown when is empty or when are not supplied. + /// Thrown when any of the text properties of isn't properly formatted xml. + /// + /// Create and run a menu with the specified title and items, that will disapear after the user selected an item. + /// + /// var selection = exConsole.Menu( + /// new MenuDisplayArgs("What to do next?"), + /// ("<c f='Yellow'>quit<c>", null), + /// ("Do this", () => DoThis(3)), + /// ("Do that", DoThat) + /// ); + /// + /// + public static int Menu(this ExConsole self, MenuDisplayArgs displayArgs, params (string Title, Action Action)[] items) + { + var result = Menu(self, displayArgs, items.Select(i => i.Title).ToArray()); + items[result].Action?.Invoke(); + return result; + } + + /// + /// Displays a menu to the user and invokes the action the user chooses. + /// + /// The current instance of ExConsole. + /// An instance of the class holding the display configuration of the menu. + /// The items of the menu. + /// An integer representing the user's choice. + /// Thrown when or or any of it's properties are null. + /// Thrown when is empty or when are not supplied. + /// Thrown when any of the text properties of isn't properly formatted xml. + /// + /// Create and run a menu with the specified items, "What to do next?" as a title, + /// "Please enter the number of your selection." displayed below the items, + /// and "Invalid number entered. Please try again.", if the user enters an invalid value. + /// This menu does not execute anything, it only returns the zero-based index of the item selected by the user + /// + /// var selection = exConsole.Menu( + /// new MenuDisplayArgs("What to do next?", "Please enter the number of your selection.", invalidSelectionErrorMessage:"Invalid number entered. Please try again." ) + /// "<c f='Yellow'>quit<c>", + /// "Do this", + /// "Do that" + /// ); + /// + /// + public static int Menu(this ExConsole self, MenuDisplayArgs displayArgs, params string[] items) + { + ValidateArguments(); + + var cursorTop = Console.CursorTop; + self.WriteLine(displayArgs.Title); + for (var i = 0; i < items.Length; i++) + { + self.WriteLine($"{i}. {items[i]}"); + } + var result = ExConsoleRead.ReadInt(self, displayArgs.PleaseSelectText, displayArgs.InvalidSelectionErrorMessage, i => i > -1 && i < items.Length); + if (displayArgs.ClearWhenSelected) + { + self.ClearLastLines(Console.CursorTop - cursorTop); + } + return result; + + void ValidateArguments() + { + if (self is null) throw new ArgumentNullException(nameof(self)); + + if (displayArgs.Title is null) throw new ArgumentNullException(nameof(displayArgs.Title)); + if (displayArgs.Title == "") throw new ArgumentException(nameof(displayArgs.Title) + " can't be empty.", nameof(displayArgs.Title)); + + if (displayArgs.PleaseSelectText is null) throw new ArgumentNullException(nameof(displayArgs.PleaseSelectText)); + if (displayArgs.PleaseSelectText == "") throw new ArgumentException(nameof(displayArgs.PleaseSelectText) + " can't be empty.", nameof(displayArgs.PleaseSelectText)); + + if (displayArgs.InvalidSelectionErrorMessage is null) throw new ArgumentNullException(nameof(displayArgs.InvalidSelectionErrorMessage)); + if (displayArgs.InvalidSelectionErrorMessage == "") throw new ArgumentException(nameof(displayArgs.InvalidSelectionErrorMessage) + " can't be empty.", nameof(displayArgs.InvalidSelectionErrorMessage)); + + if (items.Length == 0) throw new ArgumentException("A menu must include at least one item", nameof(items)); + + } + } + + /// + /// Note: + /// + /// This method is deprecated and will be removed in future versions. + /// Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + /// + /// + /// Displays a menu to the user and invokes the action the user chooses. + /// + /// + /// The current instance of ExConsole. /// The title of the menu. /// A boolean value to determine /// whether the menu should still be displayed after the user have chosen an option. @@ -35,6 +132,7 @@ public static class ExConsoleMenu /// ); /// /// + [Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the Menu overload that takes an instance of MenuDisplayArgs as an argument instead.")] public static int Menu(this ExConsole self, string title, bool clearWhenSelected, params (string Title, Action Action)[] items) { var result = Menu(self, title, clearWhenSelected, items.Select(i => i.Title).ToArray()); @@ -43,7 +141,14 @@ public static int Menu(this ExConsole self, string title, bool clearWhenSelected } /// + /// Note: + /// + /// This method is deprecated and will be removed in future versions. + /// Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + /// + /// /// Displays a menu to the user and invokes the action the user chooses. + /// /// /// The current instance of ExConsole. /// The title of the menu. @@ -75,6 +180,7 @@ public static int Menu(this ExConsole self, string title, bool clearWhenSelected ///); /// /// + [Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the Menu overload that takes an instance of MenuDisplayArgs as an argument instead.")] public static int Menu(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected, params (string Title, Action Action)[] items) { var result = Menu(self, title, pleaseSelectText, invalidSelectionText, clearWhenSelected, items.Select(i => i.Title).ToArray()); @@ -83,7 +189,14 @@ public static int Menu(this ExConsole self, string title, string pleaseSelectTex } /// + /// Note: + /// + /// This method is deprecated and will be removed in future versions. + /// Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + /// + /// /// Displays a menu to the user and returns the index of the item the user chooses. + /// /// /// The current instance of ExConsole. /// The title of the menu. @@ -108,13 +221,21 @@ public static int Menu(this ExConsole self, string title, string pleaseSelectTex /// // Do something with the selection here. /// /// + [Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the Menu overload that takes an instance of MenuDisplayArgs as an argument instead.")] public static int Menu(this ExConsole self, string title, bool clearWhenSelected, params string[] items) { return Menu(self, title, "Please select an item from the menu.", "Invalid value entered.", clearWhenSelected, items); } /// + /// Note: + /// + /// This method is deprecated and will be removed in future versions. + /// Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + /// + /// /// Displays a menu to the user and returns the index of the item the user chooses. + /// /// /// The current instance of ExConsole. /// The title of the menu. @@ -145,197 +266,10 @@ public static int Menu(this ExConsole self, string title, bool clearWhenSelected /// // Do something with the selection here. /// /// + [Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the Menu overload that takes an instance of MenuDisplayArgs as an argument instead.")] public static int Menu(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected, params string[] items) { - return ShowMenu(self, title, pleaseSelectText, invalidSelectionText, clearWhenSelected, items); + return Menu(self, new MenuDisplayArgs(title, pleaseSelectText, clearWhenSelected, invalidSelectionText), items); } - - /// - /// Displays enum members as a menu for the user to choose from. - /// - /// The type of the enum. - /// The current instance of ExConsole. - /// The title of the menu. - /// A boolean value to determine - /// whether the menu should still be displayed after the user have chosen an option. - /// The member of the enum the user selected. - /// Thrown when or are null. - /// Thrown when is empty. - /// Thrown when isn't properly formatted xml. - /// - /// Display the names of the members of the ConsoleColor enum, - /// asking the user to choose a color from the list. - /// the color variable is of type ConsoleColor. - /// - /// var color = exConsole.ChooseFromEnum<ConsoleColor>( - /// "Choose a foreground color", - /// true - /// ); - /// - /// - public static T ChooseFromEnum(this ExConsole self, string title, bool clearWhenSelected) where T : Enum - { - var names = Enum.GetNames(typeof(T)); - var result = Menu(self, title, clearWhenSelected, names); - return (T)Enum.Parse(typeof(T), names[result]); - } - - /// - /// Displays enum members as a menu for the user to choose from. - /// - /// The type of the enum. - /// The current instance of ExConsole. - /// The title of the menu. - /// The text to show below the menu. - /// The text to show when the user enters an invalid value. - /// A boolean value to determine - /// whether the menu should still be displayed after the user have chosen an option. - /// The member of the enum the user selected. - /// Thrown when , , or are null. - /// Thrown when any of , or is empty. - /// Thrown when , or are not properly formatted xml. - /// - /// Display the names of the members of the ConsoleColor enum, - /// asking the user to choose a color from the list. - /// the color variable is of type ConsoleColor. - /// - /// var color = exConsole.ChooseFromEnum<ConsoleColor>( - /// "Choose a foreground color", - /// "Please choose a color.", - /// "Please choose from the above list.", - /// true - /// ); - /// - /// - public static T ChooseFromEnum(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected) where T : Enum - { - var names = Enum.GetNames(typeof(T)); - var result = Menu(self, title, pleaseSelectText, invalidSelectionText, clearWhenSelected, names); - return (T)Enum.Parse(typeof(T), names[result]); - } - - /// - /// Displays enum members as a menu for the user to choose from. - /// - /// The type of the enum. - /// The current instance of ExConsole. - /// The title of the menu. - /// The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - /// A boolean value to determine - /// whether the menu should still be displayed after the user have chosen an option. - /// The member of the enum the user selected. - /// Thrown when or are null. - /// Thrown when is empty. - /// Thrown when isn't properly formatted xml. - /// - /// Display the names of the members of the ConsoleColor enum, - /// asking the user to choose a color from the list, or "none". - /// the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". - /// - /// var color = exConsole.ChooseFromEnum<ConsoleColor>( - /// "Choose a foreground color, or <c f='red>none</c> to keep current color.", - /// "<c f='red'>none</c>", - /// true - /// ); - /// - /// - public static T? ChooseFromEnum(this ExConsole self, string title, string quitText, bool clearWhenSelected) where T : struct, Enum - { - var names = Enum.GetNames(typeof(T)).ToList(); - names.Insert(0, quitText); - var result = Menu(self, title, clearWhenSelected, names.ToArray()); - if (result == 0) return null; - - return (T?)Enum.Parse(typeof(T), names[result]); - } - - /// - /// Displays enum members as a menu for the user to choose from. - /// - /// The type of the enum. - /// The current instance of ExConsole. - /// The title of the menu. - /// The text to show below the menu. - /// The text to show when the user enters an invalid value. - /// The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - /// A boolean value to determine - /// whether the menu should still be displayed after the user have chosen an option. - /// The member of the enum the user selected. - /// Thrown when , , , or are null. - /// Thrown when any of , , or is empty. - /// Thrown when , , or are not properly formatted xml. - /// - /// Display the names of the members of the ConsoleColor enum, - /// asking the user to choose a color from the list, or "none". - /// the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". - /// - /// var color = exConsole.ChooseFromEnum<ConsoleColor>( - /// "Choose a foreground color", - /// "Please choose a color or <c f='red>none</c> to keep current color.", - /// "Please choose from the above list.", - /// "<c f='red'>none</c>", - /// true - /// ); - /// - /// - public static T? ChooseFromEnum(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, string quitText, bool clearWhenSelected) where T : struct, Enum - { - if (quitText is null) throw new ArgumentNullException(nameof(quitText)); - if (quitText == "") throw new ArgumentException(nameof(quitText) + " can't be empty.", nameof(quitText)); - - var names = Enum.GetNames(typeof(T)).ToList(); - names.Insert(0, quitText); - var result = Menu(self, title, pleaseSelectText, invalidSelectionText, clearWhenSelected, names.ToArray()); - if (result == 0) return null; - - return (T?)Enum.Parse(typeof(T), names[result]); - } - - #region private methods - - // - // Displays a menu to the user and returns the index of the item the user chooses. - // - // The current instance of ExConsole. - // The title of the menu. - // The text to show below the menu. - // The text to show if the user entered an invalid selection. - // A boolean value to determine - // whether the menu should still be displayed after the user have chosen an option. - // The items of the menu. - // An integer representing the user's choice. - // Thrown when , , or are null. - // Thrown when any of , or is empty or when are not supplied. - // Thrown when , or are not properly formatted xml. - private static int ShowMenu(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected, params string[] items) - { - if (self is null) throw new ArgumentNullException(nameof(self)); - - if (title is null) throw new ArgumentNullException(nameof(title)); - if (title == "") throw new ArgumentException(nameof(title) + " can't be empty.", nameof(title)); - - if (pleaseSelectText is null) throw new ArgumentNullException(nameof(pleaseSelectText)); - if (pleaseSelectText == "") throw new ArgumentException(nameof(pleaseSelectText) + " can't be empty.", nameof(pleaseSelectText)); - - if (invalidSelectionText is null) throw new ArgumentNullException(nameof(invalidSelectionText)); - if (invalidSelectionText == "") throw new ArgumentException(nameof(invalidSelectionText) + " can't be empty.", nameof(invalidSelectionText)); - - if (items.Length == 0) throw new ArgumentException("A menu must include at least one item", nameof(items)); - - var cursorTop = Console.CursorTop; - self.WriteLine(title); - for (var i = 0; i < items.Length; i++) - { - self.WriteLine($"{i}. {items[i]}"); - } - var result = ExConsoleRead.ReadInt(self, pleaseSelectText, invalidSelectionText, i => i > -1 && i < items.Length); - if (clearWhenSelected) - { - self.ClearLastLines(Console.CursorTop - cursorTop); - } - return result; - } - - #endregion private methods } } diff --git a/ExtendedConsole/ExConsoleMultipleSelectMenu.cs b/ExtendedConsole/ExConsoleMultipleSelectMenu.cs new file mode 100644 index 0000000..b94e259 --- /dev/null +++ b/ExtendedConsole/ExConsoleMultipleSelectMenu.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace ExtendedConsole +{ + + /// + /// Provides extension methods for ExConsole to support multiple select menus. + /// + public static class ExConsoleMultipleSelectMenu + { + /// + /// Displays a multiple select menu to the user and returns the item(s) the user selected. + /// + /// The type of items for the user to select from. + /// The current instance of . + /// An instance of the class holding the display configuration of the menu. + /// The items of the menu. + /// An containing the values selected by the user. + /// Thrown when any of the parameters is null. + /// Thrown when any of the text properties of are empty, or when contain less than two items. + /// Thrown when any of the text properties of aren't properly formatted xml. + /// + /// Show the user a list of dates to choose from, return an where T is . + /// + /// var dates = exConsole.MultipleSelectMenu( + /// new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + /// DateTime.Now, + /// DateTime.Now.AddHours(1), + /// DateTime.Now.AddHours(2), + /// DateTime.Now.AddHours(3) + /// ); + /// + /// After the user selects the desired values, the `dates` variable will contain the user's selection. + /// + public static IEnumerable MultipleSelectMenu( + this ExConsole self, + MultipleSelectDisplayArgs displayArgs, + params T[] items + ) => MultipleSelectMenu(self, displayArgs, s => s.ToString(), items); + + /// + /// Displays a multiple select menu to the user and returns the item(s) the user selected. + /// + /// The type of items for the user to select from. + /// The current instance of . + /// An instance of the class holding the display configuration of the menu. + /// A to be used to display the items on the console, TResult is a . + /// The items of the menu. + /// An containing the values selected by the user. + /// Thrown when any of the parameters is null. + /// Thrown when any of the text properties of are empty, or when contain less than two items. + /// Thrown when any of the text properties of aren't properly formatted xml. + /// + /// Show the user a list of dates to choose from, as yyyy-mm-dd, return an where T is . + /// + /// var dates = exConsole.MultipleSelectMenu( + /// new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + /// d => d.ToString("yyyy-mm-dd"), + /// DateTime.Now, + /// DateTime.Now.AddHours(1), + /// DateTime.Now.AddHours(2), + /// DateTime.Now.AddHours(3) + /// ); + /// + /// After the user selects the desired values, the `dates` variable will contain the user's selection. + /// + + public static IEnumerable MultipleSelectMenu( + this ExConsole self, + MultipleSelectDisplayArgs displayArgs, + Func toString, + params T[] items + ) + { + ValidateArguments(); + + var menuItems = items.Select(v => new MultipleSelectMenuItem(v, toString)).ToList(); + self.WriteLines(displayArgs.Title, "", displayArgs.PleaseSelectText); + + var menuTop = Console.CursorTop; + menuItems[0].IsFocused = true; + + ShowMenu(); + SelectItems(); + + if (displayArgs.ClearWhenSelected) + { + self.ClearLastLines(Console.CursorTop - menuTop); + } + + return menuItems.Where(i => i.IsSelected).Select(i => i.Value); + + #region local methods + + void ShowMenu() + { + var foreground = Console.ForegroundColor; + foreach (var item in menuItems) + { + Console.ForegroundColor = item.IsFocused ? displayArgs.FocusedItemColor : foreground; + self.WriteLine(item.ToString()); + } + Console.ForegroundColor = foreground; + } + + void SelectItems() + { + var key = ConsoleKey.A; + var prevKey = key; + var done = false; + var index = 0; + + do + { + key = Console.KeyAvailable ? Console.ReadKey(true).Key : ConsoleKey.A; + if (key == prevKey) continue; + KeyPressed(); + self.ClearLastLines(Console.CursorTop - menuTop); + ShowMenu(); + prevKey = key; + } while (!done); + + void KeyPressed() + { + switch (key) + { + case ConsoleKey.UpArrow: + if (index > 0) + { + menuItems[index].IsFocused = false; + index--; + menuItems[index].IsFocused = true; + } + break; + case ConsoleKey.DownArrow: + if (index < menuItems.Count-1) + { + menuItems[index].IsFocused = false; + index++; + menuItems[index].IsFocused = true; + } + break; + case ConsoleKey.Spacebar: + menuItems[index].IsSelected = !menuItems[index].IsSelected; + break; + case ConsoleKey.Enter: + if (menuItems.Any(m => m.IsSelected)) + { + done = true; + } + else + { + self.Write(displayArgs.RequiredErrorMessage); + key = Console.ReadKey(true).Key; + Console.WriteLine(); + self.ClearLastLine(); + KeyPressed(); + } + break; + } + } + } + + void ValidateArguments() + { + if (self is null) throw new ArgumentNullException(nameof(self)); + + if (toString is null) throw new ArgumentNullException(nameof(toString)); + + if (items.Length < 2) throw new ArgumentException("Multiple choise menu must include at least two items", nameof(items)); + + if (displayArgs.Title is null) throw new ArgumentNullException(nameof(displayArgs.Title)); + if (displayArgs.Title == "") throw new ArgumentException(nameof(displayArgs.Title) + " can't be empty.", nameof(displayArgs.Title)); + + if (displayArgs.PleaseSelectText is null) throw new ArgumentNullException(nameof(displayArgs.PleaseSelectText)); + if (displayArgs.PleaseSelectText == "") throw new ArgumentException(nameof(displayArgs.PleaseSelectText) + " can't be empty.", nameof(displayArgs.PleaseSelectText)); + + if (displayArgs.RequiredErrorMessage is null) throw new ArgumentNullException(nameof(displayArgs.RequiredErrorMessage)); + if (displayArgs.RequiredErrorMessage == "") throw new ArgumentException(nameof(displayArgs.RequiredErrorMessage) + " can't be empty.", nameof(displayArgs.RequiredErrorMessage)); + } + + #endregion local methods + } + + private class MultipleSelectMenuItem + { + private readonly Func _toString; + public MultipleSelectMenuItem(T value, Func toString) + { + Value = value; + _toString = toString; + } + + public T Value { get; } + + public bool IsFocused { get; set; } + + public bool IsSelected { get; set; } + + public override string ToString() + { + var checkbox = IsSelected ? "[*] " : "[ ] "; + return checkbox + _toString(Value); + } + + } + } +} diff --git a/ExtendedConsole/ExConsoleRead.cs b/ExtendedConsole/ExConsoleRead.cs index c4d4908..8e91f5a 100644 --- a/ExtendedConsole/ExConsoleRead.cs +++ b/ExtendedConsole/ExConsoleRead.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; namespace ExtendedConsole { @@ -16,6 +17,7 @@ public static class ExConsoleRead /// /// The current instance of ExConsole. /// Thrown when is null. + /// The current instance of . /// /// Write "Press any key to continue." to the console, /// and wait for the user to press a key. Advance the cursor to the next line. @@ -23,9 +25,9 @@ public static class ExConsoleRead /// exConsole.Pause(); /// /// - public static void Pause(this ExConsole self) + public static ExConsole Pause(this ExConsole self) { - Pause(self, "Press any key to continue."); + return Pause(self, "Press any key to continue."); } /// @@ -36,6 +38,7 @@ public static void Pause(this ExConsole self) /// Thrown when or are null. /// Thrown when is empty. /// Thrown when isn't properly formatted xml. + /// The current instance of . /// /// Write "Press any key to continue." to the console, where "any key" is in yellow, /// and wait for the user to press a key. Advance the cursor to the next line. @@ -43,14 +46,15 @@ public static void Pause(this ExConsole self) /// exConsole.Pause("Press <c f='yellow'>any key</c> to continue."); /// /// - public static void Pause(this ExConsole self, string title) + public static ExConsole Pause(this ExConsole self, string title) { if (self is null) throw new ArgumentNullException(nameof(self)); if (title is null) throw new ArgumentNullException(nameof(title)); if (title == "") throw new ArgumentException(nameof(title) + " can't be empty.", nameof(title)); self.WriteLine(title); - Console.ReadKey(); + Console.ReadKey(true); + return self; } /// @@ -345,12 +349,9 @@ public static bool ReadBool(this ExConsole self, ConsoleKey keyForTrue, string t if (self is null) throw new ArgumentNullException(nameof(self)); if (title is null) throw new ArgumentNullException(nameof(title)); if (title == "") throw new ArgumentException(nameof(title) + " can't be empty.", nameof(title)); - self.Write(title + " "); - - var key = Console.ReadKey().Key; - Console.WriteLine(); - self.ClearLastLine(); + var key = Console.ReadKey(true).Key; + self.ClearCurrentLine(); return key == keyForTrue; } @@ -386,16 +387,12 @@ public static bool ReadBool(this ExConsole self, ConsoleKey keyForTrue, ConsoleK self.Write(title + " "); while (true) { - var key = Console.ReadKey().Key; + var key = Console.ReadKey(true).Key; if (key == keyForTrue || key == keyForFalse) { - Console.WriteLine(); - self.ClearLastLine(); + self.ClearCurrentLine(); return key == keyForTrue; } - Console.CursorLeft--; - Console.Write(" "); - Console.CursorLeft--; } } @@ -475,10 +472,11 @@ public static int ReadInt(this ExConsole self, string title, string errorMessage self, title, errorMessage, - str => (int.TryParse(str, out var res) && (condition?.Invoke(res) ?? true), res) + str => (int.TryParse(str, out var result) && (condition?.Invoke(result) ?? true), result) ); } + #endregion int #region datetime @@ -507,7 +505,7 @@ public static int ReadInt(this ExConsole self, string title, string errorMessage self, title, errorMessage, - str => (DateTime.TryParse(str, out var res), res) + str => (DateTime.TryParse(str, out var result), result) ); } @@ -541,7 +539,7 @@ public static int ReadInt(this ExConsole self, string title, string errorMessage self, title, errorMessage, - str => (DateTime.TryParse(str, formatProvider, dateTimeStyles, out var res), res) + str => (DateTime.TryParse(str, formatProvider, dateTimeStyles, out var result), result) ); } @@ -578,7 +576,7 @@ public static int ReadInt(this ExConsole self, string title, string errorMessage self, title, errorMessage, - str => (DateTime.TryParseExact(str, format, formatProvider, dateTimeStyles, out var res), res) + str => (DateTime.TryParseExact(str, format, formatProvider, dateTimeStyles, out var result), result) ); } @@ -615,7 +613,7 @@ public static int ReadInt(this ExConsole self, string title, string errorMessage self, title, errorMessage, - str => (DateTime.TryParseExact(str, formats, formatProvider, dateTimeStyles, out var res), res) + str => (DateTime.TryParseExact(str, formats, formatProvider, dateTimeStyles, out var result), result) ); } diff --git a/ExtendedConsole/ExtendedConsole.csproj b/ExtendedConsole/ExtendedConsole.csproj index 0ca87d3..382d816 100644 --- a/ExtendedConsole/ExtendedConsole.csproj +++ b/ExtendedConsole/ExtendedConsole.csproj @@ -13,13 +13,16 @@ true 7.3 Changes from previous version: - -1. Fixed a small bug in markup parser that caused spaces between xml tags to disapear. - 1.0.5 +1. Added a class called MenuDisplayArgs to reduce the number of overloads and simplify the work. +2. Added a new static class called ExConsoleChooseFromEnum, containing methods that once where in ExConsoleMenu class. +3. Added new functionality - multiple select menues, in ExConsoleMultipleSelectMenu class. +This change also comes with a MultipleSelectDisplayArgs class to hold display configuration for the multiple select menu. +4. Changed void methods to return the current instance of the ExConsole class to enable fluent usage. + 1.1.0 https://raw.githubusercontent.com/Peled-Zohar/ExtendedConsole/master/ExtendedConsole.png extendedconsole.ico - 1.0.5.0 - 1.0.5.0 + 1.1.0.0 + 1.1.0.0 diff --git a/ExtendedConsole/ExtendedConsole.xml b/ExtendedConsole/ExtendedConsole.xml index e560f2b..3179225 100644 --- a/ExtendedConsole/ExtendedConsole.xml +++ b/ExtendedConsole/ExtendedConsole.xml @@ -29,6 +29,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", cyan on a dark gray background. @@ -42,6 +43,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", black on a white background, and advance the cursor to the next line. @@ -56,6 +58,7 @@ Lines of markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in yellow, "This is exConsole writing multiple markup lines" in the next line, with exConsole in green, and @@ -78,6 +81,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in magenta, followed by "How are you?" in black on a white background. Advance the cursor to the next line. @@ -93,6 +97,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in black on a magenta background, followed by "How are you?" in black on a white background. @@ -100,11 +105,222 @@ + + + Provides extension methods for ExConsole to support simple menus based on enum values. + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected, or null if the user selected the "quit" menu item. + Thrown when , or any of its properties, or are null. + Thrown when any of the string properties of or are empty. + Thrown when any of the string properties of or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "<c f='red'>none</c>", + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + invalidSelectionErrorMessage:"Please choose from the above list.") + ); + + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected. + Thrown when , or any of its properties are null. + Thrown when any of the string properties of are empty. + Thrown when any of the string properties of are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color.", + false, + "Please choose from the above list.") + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of . + The title of the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , or are null. + Thrown when any of , or is empty. + Thrown when , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color.", + "Please choose from the above list.", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color, or <c f='red>none</c> to keep current color.", + "<c f='red'>none</c>", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , , or are null. + Thrown when any of , , or is empty. + Thrown when , , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + "Please choose from the above list.", + "<c f='red'>none</c>", + true + ); + + + Provides extension methods for ExConsole for clearing specific console lines. + + + Clears all text from the current line. + + The current instance of ExConsole. + The current instance of . + + Clears the current line of the console. + + exConsole.ClearCurrentLine(); + + + Clears all text from a specific line. @@ -112,6 +328,7 @@ The current instance of ExConsole. Line index to clear. Thrown if is less than zero. + The current instance of . Clear the second line from the top. @@ -124,6 +341,7 @@ Clears all text from the last line. The current instance of ExConsole. + The current instance of . Clear the last line. @@ -135,9 +353,10 @@ Clears all text from the last lines. - The current instance of ExConsole. + The current instance of . The number of lines to clear (count up from last line) Thrown if is less than one. + The current instance of . Clear the last three lines. @@ -145,14 +364,88 @@ + + + Clears all the text on the console, and returns the current instance of ExConsole. + + The current instance of . + The current instance of . + + Pause, clear all lines, and ask the user to enter an integer value: + + exConsole + .Pause("Press any key to continue") + .ClearAllLines() + .ReadInt("Please enter a number:"); + + + Provides extension methods for ExConsole to support simple menus. + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + Each item contains a title and an action to perform, should the user choses this item. + null can be passed in as the action if the item selection should perform no action. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified title and items, that will disapear after the user selected an item. + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?"), + ("<c f='Yellow'>quit<c>", null), + ("Do this", () => DoThis(3)), + ("Do that", DoThat) + ); + + + + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified items, "What to do next?" as a title, + "Please enter the number of your selection." displayed below the items, + and "Invalid number entered. Please try again.", if the user enters an invalid value. + This menu does not execute anything, it only returns the zero-based index of the item selected by the user + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?", "Please enter the number of your selection.", invalidSelectionErrorMessage:"Invalid number entered. Please try again." ) + "<c f='Yellow'>quit<c>", + "Do this", + "Do that" + ); + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -180,7 +473,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -215,7 +515,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -243,7 +550,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -275,116 +589,63 @@ - + - Displays enum members as a menu for the user to choose from. + Provides extension methods for ExConsole to support multiple select menus. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - true - ); - - - + - Displays enum members as a menu for the user to choose from. - - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , or are null. - Thrown when any of , or is empty. - Thrown when , or are not properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color.", - "Please choose from the above list.", - true - ); - - - - - - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color, or <c f='red>none</c> to keep current color.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. - + - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , , or are null. - Thrown when any of , , or is empty. - Thrown when , , or are not properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + A to be used to display the items on the console, TResult is a . + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, as yyyy-mm-dd, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color or <c f='red>none</c> to keep current color.", - "Please choose from the above list.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + d => d.ToString("yyyy-mm-dd"), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. @@ -398,6 +659,7 @@ The current instance of ExConsole. Thrown when is null. + The current instance of . Write "Press any key to continue." to the console, and wait for the user to press a key. Advance the cursor to the next line. @@ -415,6 +677,7 @@ Thrown when or are null. Thrown when is empty. Thrown when isn't properly formatted xml. + The current instance of . Write "Press any key to continue." to the console, where "any key" is in yellow, and wait for the user to press a key. Advance the cursor to the next line. @@ -472,14 +735,14 @@ - Reads an input line from the user and converts it to a nullable T. + Reads an input line from the user and converts it to a nullable . The underlying type of the nullable to convert to. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - An instance of T? that has a value unless the user entered ^Z. + A function that takes in a string and returns a of success and value. + An instance of ? that has a value unless the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -497,14 +760,14 @@ - Reads an input line from the user and converts it to T. + Reads an input line from the user and converts it to . The target type of the conversion. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - The T value converted from the input string, or null if the user entered ^Z. + A function that takes in a string and returns a of success and value. + The value converted from the input string, or null if the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -528,7 +791,7 @@ - Reads multiple values from the user, converts and returns them as an IEnumerable<T>. + Reads multiple values from the user, converts and returns them as an . Repeats until the user enters the quit text. The type of values to convert to. @@ -537,14 +800,14 @@ The error message to show the user if the conversion failed. A string the user should enter when they are done entering values. A function that takes in a string and returns a value tuple of bool success and T value. - An IEnumerable<T> containing values conveted from the user input. + An containing values conveted from the user input. Thrown when any of the parameters is null. Thrown when , or are empty. Thrown when or aren't properly formatted xml. Read a collection of int values from the user. - The integers vairable is of type IEnumerable<T>, and will never be null. - If the user enters "done" before entering any valid integers, the retun value is an empty IEnumerable<T>. + The integers vairable is of type , and will never be null. + If the user enters "done" before entering any valid integers, the retun value is an empty . var integers = _exConsole.ReadValues( "Please enter integer values, or <c f='red'>done</c> to quit.", @@ -764,6 +1027,84 @@ + + + Stores display arguments for menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the menu. + The text to be displayed below the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The error message to show if the user entered an invalid selection. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + + + + + Gets the error message to display if the user enters an invalid value. + + + + + Stores display arguments for multiple select menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the multiple select menu. + The text to be displayed between the title and the menu, instructing the user how to use the menu. + A boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + The fore color to use for the currently focused item of the menu. + The error message to display if the user did not select anything from the menu. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + + + + + Gets the fore color to use for the currently focused item of the menu. + + + + + Gets the error message to display if the user did not select anything from the menu. + + Parse markup text, creates and returns an instance of the class. diff --git a/ExtendedConsole/MenuDisplayArgs.cs b/ExtendedConsole/MenuDisplayArgs.cs new file mode 100644 index 0000000..50764d4 --- /dev/null +++ b/ExtendedConsole/MenuDisplayArgs.cs @@ -0,0 +1,50 @@ +namespace ExtendedConsole +{ + /// + /// Stores display arguments for menu. + /// + public class MenuDisplayArgs + { + /// + /// Creates a new instance of the class with the specified parmeters. + /// + /// The title of the menu. + /// The text to be displayed below the menu. + /// A boolean value to determine + /// whether the menu should still be displayed after the user have chosen an option. + /// The error message to show if the user entered an invalid selection. + public MenuDisplayArgs ( + string title, + string pleaseSelectText = "Please select an item from the menu.", + bool clearWhenSelected = true, + string invalidSelectionErrorMessage = "Invalid value entered." + ) + { + Title = title; + PleaseSelectText = pleaseSelectText; + ClearWhenSelected = clearWhenSelected; + InvalidSelectionErrorMessage = invalidSelectionErrorMessage; + } + + /// + /// Gets the title of the multiple select menu. + /// + public string Title { get; } + + /// + /// Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + /// + public string PleaseSelectText { get; } + + /// + /// Gets a boolean value to determine + /// whether the menu should still be displayed after the user have chosen an option. + /// + public bool ClearWhenSelected { get; } + + /// + /// Gets the error message to display if the user enters an invalid value. + /// + public string InvalidSelectionErrorMessage { get; } + } +} diff --git a/ExtendedConsole/MultipleSelectDisplayArgs.cs b/ExtendedConsole/MultipleSelectDisplayArgs.cs new file mode 100644 index 0000000..975f429 --- /dev/null +++ b/ExtendedConsole/MultipleSelectDisplayArgs.cs @@ -0,0 +1,60 @@ +using System; + +namespace ExtendedConsole +{ + /// + /// Stores display arguments for multiple select menu. + /// + public class MultipleSelectDisplayArgs + { + /// + /// Creates a new instance of the class with the specified parmeters. + /// + /// The title of the multiple select menu. + /// The text to be displayed between the title and the menu, instructing the user how to use the menu. + /// A boolean value to determine + /// whether the menu should still be displayed after the user have completed his selection. + /// The fore color to use for the currently focused item of the menu. + /// The error message to display if the user did not select anything from the menu. + public MultipleSelectDisplayArgs( + string title, + string pleaseSelectText = "Use arrow keys (up/down) to navigate, spece bar to select, and enter to submit selection.", + bool clearWhenSelected = true, + ConsoleColor focusedItemColor = ConsoleColor.Magenta, + string requiredErrorMessage = "You must select at least one item." + ) + { + Title = title; + PleaseSelectText = pleaseSelectText; + ClearWhenSelected = clearWhenSelected; + FocusedItemColor = focusedItemColor; + RequiredErrorMessage = requiredErrorMessage; + } + + /// + /// Gets the title of the multiple select menu. + /// + public string Title { get; } + + /// + /// Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + /// + public string PleaseSelectText { get; } + + /// + /// Gets a boolean value to determine + /// whether the menu should still be displayed after the user have completed his selection. + /// + public bool ClearWhenSelected { get; } + + /// + /// Gets the fore color to use for the currently focused item of the menu. + /// + public ConsoleColor FocusedItemColor { get; } + + /// + /// Gets the error message to display if the user did not select anything from the menu. + /// + public string RequiredErrorMessage { get; } + } +} diff --git a/ExtendedConsole/bin/Debug/ExtendedConsole.1.0.5.nupkg b/ExtendedConsole/bin/Debug/ExtendedConsole.1.0.5.nupkg index e89443d..465b2ee 100644 Binary files a/ExtendedConsole/bin/Debug/ExtendedConsole.1.0.5.nupkg and b/ExtendedConsole/bin/Debug/ExtendedConsole.1.0.5.nupkg differ diff --git a/ExtendedConsole/bin/Debug/ExtendedConsole.1.1.0.nupkg b/ExtendedConsole/bin/Debug/ExtendedConsole.1.1.0.nupkg new file mode 100644 index 0000000..f206156 Binary files /dev/null and b/ExtendedConsole/bin/Debug/ExtendedConsole.1.1.0.nupkg differ diff --git a/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.deps.json b/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.deps.json index d26708a..66f6d9e 100644 --- a/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.deps.json +++ b/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.deps.json @@ -7,7 +7,7 @@ "targets": { ".NETStandard,Version=v2.0": {}, ".NETStandard,Version=v2.0/": { - "ExtendedConsole/1.0.5": { + "ExtendedConsole/1.1.0": { "dependencies": { "NETStandard.Library": "2.0.3" }, @@ -24,7 +24,7 @@ } }, "libraries": { - "ExtendedConsole/1.0.5": { + "ExtendedConsole/1.1.0": { "type": "project", "serviceable": false, "sha512": "" diff --git a/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.dll b/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.dll index 7850bfb..ce4c5c0 100644 Binary files a/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.dll and b/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.dll differ diff --git a/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.pdb b/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.pdb index 7d48e53..983be8f 100644 Binary files a/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.pdb and b/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.pdb differ diff --git a/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.xml b/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.xml index e560f2b..3179225 100644 --- a/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.xml +++ b/ExtendedConsole/bin/Debug/netstandard2.0/ExtendedConsole.xml @@ -29,6 +29,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", cyan on a dark gray background. @@ -42,6 +43,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", black on a white background, and advance the cursor to the next line. @@ -56,6 +58,7 @@ Lines of markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in yellow, "This is exConsole writing multiple markup lines" in the next line, with exConsole in green, and @@ -78,6 +81,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in magenta, followed by "How are you?" in black on a white background. Advance the cursor to the next line. @@ -93,6 +97,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in black on a magenta background, followed by "How are you?" in black on a white background. @@ -100,11 +105,222 @@ + + + Provides extension methods for ExConsole to support simple menus based on enum values. + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected, or null if the user selected the "quit" menu item. + Thrown when , or any of its properties, or are null. + Thrown when any of the string properties of or are empty. + Thrown when any of the string properties of or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "<c f='red'>none</c>", + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + invalidSelectionErrorMessage:"Please choose from the above list.") + ); + + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected. + Thrown when , or any of its properties are null. + Thrown when any of the string properties of are empty. + Thrown when any of the string properties of are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color.", + false, + "Please choose from the above list.") + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of . + The title of the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , or are null. + Thrown when any of , or is empty. + Thrown when , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color.", + "Please choose from the above list.", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color, or <c f='red>none</c> to keep current color.", + "<c f='red'>none</c>", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , , or are null. + Thrown when any of , , or is empty. + Thrown when , , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + "Please choose from the above list.", + "<c f='red'>none</c>", + true + ); + + + Provides extension methods for ExConsole for clearing specific console lines. + + + Clears all text from the current line. + + The current instance of ExConsole. + The current instance of . + + Clears the current line of the console. + + exConsole.ClearCurrentLine(); + + + Clears all text from a specific line. @@ -112,6 +328,7 @@ The current instance of ExConsole. Line index to clear. Thrown if is less than zero. + The current instance of . Clear the second line from the top. @@ -124,6 +341,7 @@ Clears all text from the last line. The current instance of ExConsole. + The current instance of . Clear the last line. @@ -135,9 +353,10 @@ Clears all text from the last lines. - The current instance of ExConsole. + The current instance of . The number of lines to clear (count up from last line) Thrown if is less than one. + The current instance of . Clear the last three lines. @@ -145,14 +364,88 @@ + + + Clears all the text on the console, and returns the current instance of ExConsole. + + The current instance of . + The current instance of . + + Pause, clear all lines, and ask the user to enter an integer value: + + exConsole + .Pause("Press any key to continue") + .ClearAllLines() + .ReadInt("Please enter a number:"); + + + Provides extension methods for ExConsole to support simple menus. + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + Each item contains a title and an action to perform, should the user choses this item. + null can be passed in as the action if the item selection should perform no action. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified title and items, that will disapear after the user selected an item. + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?"), + ("<c f='Yellow'>quit<c>", null), + ("Do this", () => DoThis(3)), + ("Do that", DoThat) + ); + + + + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified items, "What to do next?" as a title, + "Please enter the number of your selection." displayed below the items, + and "Invalid number entered. Please try again.", if the user enters an invalid value. + This menu does not execute anything, it only returns the zero-based index of the item selected by the user + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?", "Please enter the number of your selection.", invalidSelectionErrorMessage:"Invalid number entered. Please try again." ) + "<c f='Yellow'>quit<c>", + "Do this", + "Do that" + ); + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -180,7 +473,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -215,7 +515,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -243,7 +550,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -275,116 +589,63 @@ - + - Displays enum members as a menu for the user to choose from. + Provides extension methods for ExConsole to support multiple select menus. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - true - ); - - - + - Displays enum members as a menu for the user to choose from. - - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , or are null. - Thrown when any of , or is empty. - Thrown when , or are not properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color.", - "Please choose from the above list.", - true - ); - - - - - - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color, or <c f='red>none</c> to keep current color.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. - + - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , , or are null. - Thrown when any of , , or is empty. - Thrown when , , or are not properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + A to be used to display the items on the console, TResult is a . + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, as yyyy-mm-dd, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color or <c f='red>none</c> to keep current color.", - "Please choose from the above list.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + d => d.ToString("yyyy-mm-dd"), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. @@ -398,6 +659,7 @@ The current instance of ExConsole. Thrown when is null. + The current instance of . Write "Press any key to continue." to the console, and wait for the user to press a key. Advance the cursor to the next line. @@ -415,6 +677,7 @@ Thrown when or are null. Thrown when is empty. Thrown when isn't properly formatted xml. + The current instance of . Write "Press any key to continue." to the console, where "any key" is in yellow, and wait for the user to press a key. Advance the cursor to the next line. @@ -472,14 +735,14 @@ - Reads an input line from the user and converts it to a nullable T. + Reads an input line from the user and converts it to a nullable . The underlying type of the nullable to convert to. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - An instance of T? that has a value unless the user entered ^Z. + A function that takes in a string and returns a of success and value. + An instance of ? that has a value unless the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -497,14 +760,14 @@ - Reads an input line from the user and converts it to T. + Reads an input line from the user and converts it to . The target type of the conversion. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - The T value converted from the input string, or null if the user entered ^Z. + A function that takes in a string and returns a of success and value. + The value converted from the input string, or null if the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -528,7 +791,7 @@ - Reads multiple values from the user, converts and returns them as an IEnumerable<T>. + Reads multiple values from the user, converts and returns them as an . Repeats until the user enters the quit text. The type of values to convert to. @@ -537,14 +800,14 @@ The error message to show the user if the conversion failed. A string the user should enter when they are done entering values. A function that takes in a string and returns a value tuple of bool success and T value. - An IEnumerable<T> containing values conveted from the user input. + An containing values conveted from the user input. Thrown when any of the parameters is null. Thrown when , or are empty. Thrown when or aren't properly formatted xml. Read a collection of int values from the user. - The integers vairable is of type IEnumerable<T>, and will never be null. - If the user enters "done" before entering any valid integers, the retun value is an empty IEnumerable<T>. + The integers vairable is of type , and will never be null. + If the user enters "done" before entering any valid integers, the retun value is an empty . var integers = _exConsole.ReadValues( "Please enter integer values, or <c f='red'>done</c> to quit.", @@ -764,6 +1027,84 @@ + + + Stores display arguments for menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the menu. + The text to be displayed below the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The error message to show if the user entered an invalid selection. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + + + + + Gets the error message to display if the user enters an invalid value. + + + + + Stores display arguments for multiple select menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the multiple select menu. + The text to be displayed between the title and the menu, instructing the user how to use the menu. + A boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + The fore color to use for the currently focused item of the menu. + The error message to display if the user did not select anything from the menu. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + + + + + Gets the fore color to use for the currently focused item of the menu. + + + + + Gets the error message to display if the user did not select anything from the menu. + + Parse markup text, creates and returns an instance of the class. diff --git a/ExtendedConsole/bin/Release/ExtendedConsole.1.1.0.nupkg b/ExtendedConsole/bin/Release/ExtendedConsole.1.1.0.nupkg new file mode 100644 index 0000000..638ca91 Binary files /dev/null and b/ExtendedConsole/bin/Release/ExtendedConsole.1.1.0.nupkg differ diff --git a/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.deps.json b/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.deps.json index d26708a..66f6d9e 100644 --- a/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.deps.json +++ b/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.deps.json @@ -7,7 +7,7 @@ "targets": { ".NETStandard,Version=v2.0": {}, ".NETStandard,Version=v2.0/": { - "ExtendedConsole/1.0.5": { + "ExtendedConsole/1.1.0": { "dependencies": { "NETStandard.Library": "2.0.3" }, @@ -24,7 +24,7 @@ } }, "libraries": { - "ExtendedConsole/1.0.5": { + "ExtendedConsole/1.1.0": { "type": "project", "serviceable": false, "sha512": "" diff --git a/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.dll b/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.dll index c65fa78..146abe0 100644 Binary files a/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.dll and b/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.dll differ diff --git a/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.pdb b/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.pdb index 0cb76ec..daf4eb5 100644 Binary files a/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.pdb and b/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.pdb differ diff --git a/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.xml b/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.xml index e560f2b..3179225 100644 --- a/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.xml +++ b/ExtendedConsole/bin/Release/netstandard2.0/ExtendedConsole.xml @@ -29,6 +29,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", cyan on a dark gray background. @@ -42,6 +43,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", black on a white background, and advance the cursor to the next line. @@ -56,6 +58,7 @@ Lines of markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in yellow, "This is exConsole writing multiple markup lines" in the next line, with exConsole in green, and @@ -78,6 +81,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in magenta, followed by "How are you?" in black on a white background. Advance the cursor to the next line. @@ -93,6 +97,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in black on a magenta background, followed by "How are you?" in black on a white background. @@ -100,11 +105,222 @@ + + + Provides extension methods for ExConsole to support simple menus based on enum values. + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected, or null if the user selected the "quit" menu item. + Thrown when , or any of its properties, or are null. + Thrown when any of the string properties of or are empty. + Thrown when any of the string properties of or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "<c f='red'>none</c>", + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + invalidSelectionErrorMessage:"Please choose from the above list.") + ); + + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected. + Thrown when , or any of its properties are null. + Thrown when any of the string properties of are empty. + Thrown when any of the string properties of are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color.", + false, + "Please choose from the above list.") + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of . + The title of the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , or are null. + Thrown when any of , or is empty. + Thrown when , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color.", + "Please choose from the above list.", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color, or <c f='red>none</c> to keep current color.", + "<c f='red'>none</c>", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , , or are null. + Thrown when any of , , or is empty. + Thrown when , , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + "Please choose from the above list.", + "<c f='red'>none</c>", + true + ); + + + Provides extension methods for ExConsole for clearing specific console lines. + + + Clears all text from the current line. + + The current instance of ExConsole. + The current instance of . + + Clears the current line of the console. + + exConsole.ClearCurrentLine(); + + + Clears all text from a specific line. @@ -112,6 +328,7 @@ The current instance of ExConsole. Line index to clear. Thrown if is less than zero. + The current instance of . Clear the second line from the top. @@ -124,6 +341,7 @@ Clears all text from the last line. The current instance of ExConsole. + The current instance of . Clear the last line. @@ -135,9 +353,10 @@ Clears all text from the last lines. - The current instance of ExConsole. + The current instance of . The number of lines to clear (count up from last line) Thrown if is less than one. + The current instance of . Clear the last three lines. @@ -145,14 +364,88 @@ + + + Clears all the text on the console, and returns the current instance of ExConsole. + + The current instance of . + The current instance of . + + Pause, clear all lines, and ask the user to enter an integer value: + + exConsole + .Pause("Press any key to continue") + .ClearAllLines() + .ReadInt("Please enter a number:"); + + + Provides extension methods for ExConsole to support simple menus. + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + Each item contains a title and an action to perform, should the user choses this item. + null can be passed in as the action if the item selection should perform no action. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified title and items, that will disapear after the user selected an item. + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?"), + ("<c f='Yellow'>quit<c>", null), + ("Do this", () => DoThis(3)), + ("Do that", DoThat) + ); + + + + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified items, "What to do next?" as a title, + "Please enter the number of your selection." displayed below the items, + and "Invalid number entered. Please try again.", if the user enters an invalid value. + This menu does not execute anything, it only returns the zero-based index of the item selected by the user + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?", "Please enter the number of your selection.", invalidSelectionErrorMessage:"Invalid number entered. Please try again." ) + "<c f='Yellow'>quit<c>", + "Do this", + "Do that" + ); + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -180,7 +473,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -215,7 +515,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -243,7 +550,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -275,116 +589,63 @@ - + - Displays enum members as a menu for the user to choose from. + Provides extension methods for ExConsole to support multiple select menus. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - true - ); - - - + - Displays enum members as a menu for the user to choose from. - - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , or are null. - Thrown when any of , or is empty. - Thrown when , or are not properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color.", - "Please choose from the above list.", - true - ); - - - - - - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color, or <c f='red>none</c> to keep current color.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. - + - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , , or are null. - Thrown when any of , , or is empty. - Thrown when , , or are not properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + A to be used to display the items on the console, TResult is a . + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, as yyyy-mm-dd, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color or <c f='red>none</c> to keep current color.", - "Please choose from the above list.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + d => d.ToString("yyyy-mm-dd"), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. @@ -398,6 +659,7 @@ The current instance of ExConsole. Thrown when is null. + The current instance of . Write "Press any key to continue." to the console, and wait for the user to press a key. Advance the cursor to the next line. @@ -415,6 +677,7 @@ Thrown when or are null. Thrown when is empty. Thrown when isn't properly formatted xml. + The current instance of . Write "Press any key to continue." to the console, where "any key" is in yellow, and wait for the user to press a key. Advance the cursor to the next line. @@ -472,14 +735,14 @@ - Reads an input line from the user and converts it to a nullable T. + Reads an input line from the user and converts it to a nullable . The underlying type of the nullable to convert to. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - An instance of T? that has a value unless the user entered ^Z. + A function that takes in a string and returns a of success and value. + An instance of ? that has a value unless the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -497,14 +760,14 @@ - Reads an input line from the user and converts it to T. + Reads an input line from the user and converts it to . The target type of the conversion. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - The T value converted from the input string, or null if the user entered ^Z. + A function that takes in a string and returns a of success and value. + The value converted from the input string, or null if the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -528,7 +791,7 @@ - Reads multiple values from the user, converts and returns them as an IEnumerable<T>. + Reads multiple values from the user, converts and returns them as an . Repeats until the user enters the quit text. The type of values to convert to. @@ -537,14 +800,14 @@ The error message to show the user if the conversion failed. A string the user should enter when they are done entering values. A function that takes in a string and returns a value tuple of bool success and T value. - An IEnumerable<T> containing values conveted from the user input. + An containing values conveted from the user input. Thrown when any of the parameters is null. Thrown when , or are empty. Thrown when or aren't properly formatted xml. Read a collection of int values from the user. - The integers vairable is of type IEnumerable<T>, and will never be null. - If the user enters "done" before entering any valid integers, the retun value is an empty IEnumerable<T>. + The integers vairable is of type , and will never be null. + If the user enters "done" before entering any valid integers, the retun value is an empty . var integers = _exConsole.ReadValues( "Please enter integer values, or <c f='red'>done</c> to quit.", @@ -764,6 +1027,84 @@ + + + Stores display arguments for menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the menu. + The text to be displayed below the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The error message to show if the user entered an invalid selection. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + + + + + Gets the error message to display if the user enters an invalid value. + + + + + Stores display arguments for multiple select menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the multiple select menu. + The text to be displayed between the title and the menu, instructing the user how to use the menu. + A boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + The fore color to use for the currently focused item of the menu. + The error message to display if the user did not select anything from the menu. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + + + + + Gets the fore color to use for the currently focused item of the menu. + + + + + Gets the error message to display if the user did not select anything from the menu. + + Parse markup text, creates and returns an instance of the class. diff --git a/ExtendedConsole/obj/Debug/ExtendedConsole.1.1.0.nuspec b/ExtendedConsole/obj/Debug/ExtendedConsole.1.1.0.nuspec new file mode 100644 index 0000000..4078697 --- /dev/null +++ b/ExtendedConsole/obj/Debug/ExtendedConsole.1.1.0.nuspec @@ -0,0 +1,28 @@ + + + + ExtendedConsole + 1.1.0 + Zohar Peled + Zohar Peled + false + https://github.com/Peled-Zohar/ExtendedConsole/blob/master/LICENSE + https://peled-zohar.github.io/ExtendedConsole/ + https://raw.githubusercontent.com/Peled-Zohar/ExtendedConsole/master/ExtendedConsole.png + Provides a set of methods to make your life as a programmer easier when writing a Console application. + Changes from previous version: +1. Added a class called MenuDisplayArgs to reduce the number of overloads and simplify the work. +2. Added a new static class called ExConsoleChooseFromEnum, containing methods that once where in ExConsoleMenu class. +3. Added new functionality - multiple select menues, in ExConsoleMultipleSelectMenu class. +This change also comes with a MultipleSelectDisplayArgs class to hold display configuration for the multiple select menu. +4. Changed void methods to return the current instance of the ExConsole class to enable fluent usage. + + + + + + + + + + \ No newline at end of file diff --git a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.AssemblyInfo.cs b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.AssemblyInfo.cs index fef6ca5..5d08425 100644 --- a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.AssemblyInfo.cs +++ b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.AssemblyInfo.cs @@ -15,11 +15,11 @@ [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyDescriptionAttribute("Provides a set of methods to make your life as a programmer easier when writing a" + " Console application.")] -[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.5.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.5")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.1.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.1.0")] [assembly: System.Reflection.AssemblyProductAttribute("ExtendedConsole")] [assembly: System.Reflection.AssemblyTitleAttribute("ExtendedConsole")] -[assembly: System.Reflection.AssemblyVersionAttribute("1.0.5.0")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.1.0.0")] [assembly: System.Resources.NeutralResourcesLanguageAttribute("en")] // Generated by the MSBuild WriteCodeFragment class. diff --git a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.AssemblyInfoInputs.cache b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.AssemblyInfoInputs.cache index 469d634..b00f5b1 100644 --- a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.AssemblyInfoInputs.cache +++ b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.AssemblyInfoInputs.cache @@ -1 +1 @@ -3823e8b0ed10f5505ad13c7a328e0aa5a56e3eed +3117071fe27058d273a9afca6345afe471e458d0 diff --git a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.csproj.CoreCompileInputs.cache b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.csproj.CoreCompileInputs.cache index 9bf8f81..d03f278 100644 --- a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.csproj.CoreCompileInputs.cache +++ b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -1eeb4faa63f5260e8b23a1893dfd1caddbbf630a +08aa7ecbb8d357781b837d621335f17515eae6f4 diff --git a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.dll b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.dll index 7850bfb..ce4c5c0 100644 Binary files a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.dll and b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.dll differ diff --git a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.pdb b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.pdb index 7d48e53..983be8f 100644 Binary files a/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.pdb and b/ExtendedConsole/obj/Debug/netstandard2.0/ExtendedConsole.pdb differ diff --git a/ExtendedConsole/obj/ExtendedConsole.csproj.nuget.cache b/ExtendedConsole/obj/ExtendedConsole.csproj.nuget.cache index ff28dd3..3003c88 100644 --- a/ExtendedConsole/obj/ExtendedConsole.csproj.nuget.cache +++ b/ExtendedConsole/obj/ExtendedConsole.csproj.nuget.cache @@ -1,5 +1,5 @@ { "version": 1, - "dgSpecHash": "hZyLDrXvy5BC7wdw24jq+2EoZr0u1xk9JCbh5/463EVkKYt5RrKVgu64rzDdzBPRr2uDpfT1EHn+Gw/UBUsm2w==", + "dgSpecHash": "eulTI3NxcRthT6ZYCczhKpZtx40s+WbaU/0e2ObWuMVVr0vCY94KV3EjArtkzomIvO1U1/X4mpFvKkqz2xaUWg==", "success": true } \ No newline at end of file diff --git a/ExtendedConsole/obj/Release/ExtendedConsole.1.1.0.nuspec b/ExtendedConsole/obj/Release/ExtendedConsole.1.1.0.nuspec new file mode 100644 index 0000000..ac495bb --- /dev/null +++ b/ExtendedConsole/obj/Release/ExtendedConsole.1.1.0.nuspec @@ -0,0 +1,28 @@ + + + + ExtendedConsole + 1.1.0 + Zohar Peled + Zohar Peled + false + https://github.com/Peled-Zohar/ExtendedConsole/blob/master/LICENSE + https://peled-zohar.github.io/ExtendedConsole/ + https://raw.githubusercontent.com/Peled-Zohar/ExtendedConsole/master/ExtendedConsole.png + Provides a set of methods to make your life as a programmer easier when writing a Console application. + Changes from previous version: +1. Added a class called MenuDisplayArgs to reduce the number of overloads and simplify the work. +2. Added a new static class called ExConsoleChooseFromEnum, containing methods that once where in ExConsoleMenu class. +3. Added new functionality - multiple select menues, in ExConsoleMultipleSelectMenu class. +This change also comes with a MultipleSelectDisplayArgs class to hold display configuration for the multiple select menu. +4. Changed void methods to return the current instance of the ExConsole class to enable fluent usage. + + + + + + + + + + \ No newline at end of file diff --git a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.AssemblyInfo.cs b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.AssemblyInfo.cs index ab672f4..dcc32ab 100644 --- a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.AssemblyInfo.cs +++ b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.AssemblyInfo.cs @@ -15,11 +15,11 @@ [assembly: System.Reflection.AssemblyConfigurationAttribute("Release")] [assembly: System.Reflection.AssemblyDescriptionAttribute("Provides a set of methods to make your life as a programmer easier when writing a" + " Console application.")] -[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.5.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.5")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.1.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.1.0")] [assembly: System.Reflection.AssemblyProductAttribute("ExtendedConsole")] [assembly: System.Reflection.AssemblyTitleAttribute("ExtendedConsole")] -[assembly: System.Reflection.AssemblyVersionAttribute("1.0.5.0")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.1.0.0")] [assembly: System.Resources.NeutralResourcesLanguageAttribute("en")] // Generated by the MSBuild WriteCodeFragment class. diff --git a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.AssemblyInfoInputs.cache b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.AssemblyInfoInputs.cache index 8c70bd9..2f35671 100644 --- a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.AssemblyInfoInputs.cache +++ b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.AssemblyInfoInputs.cache @@ -1 +1 @@ -e541d4be9e131ca819ba3b0d96ad42e340783e60 +a3ffde1c2a832d8a1682964c38782fff5eea5de9 diff --git a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.csproj.CoreCompileInputs.cache b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.csproj.CoreCompileInputs.cache index 28588a7..d03f278 100644 --- a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.csproj.CoreCompileInputs.cache +++ b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -ef8071651cf4e103b87806d4c4189735735f2b8e +08aa7ecbb8d357781b837d621335f17515eae6f4 diff --git a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.csproj.FileListAbsolute.txt b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.csproj.FileListAbsolute.txt index aaa9575..4c00e05 100644 --- a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.csproj.FileListAbsolute.txt +++ b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.csproj.FileListAbsolute.txt @@ -3,6 +3,7 @@ C:\Development\ExtendedConsole\ExtendedConsole\bin\Release\netstandard2.0\Extend C:\Development\ExtendedConsole\ExtendedConsole\bin\Release\netstandard2.0\ExtendedConsole.dll C:\Development\ExtendedConsole\ExtendedConsole\bin\Release\netstandard2.0\ExtendedConsole.pdb C:\Development\ExtendedConsole\ExtendedConsole\bin\Release\netstandard2.0\ExtendedConsole.xml +C:\Development\ExtendedConsole\ExtendedConsole\obj\Release\netstandard2.0\ExtendedConsole.csprojAssemblyReference.cache C:\Development\ExtendedConsole\ExtendedConsole\obj\Release\netstandard2.0\ExtendedConsole.csproj.CoreCompileInputs.cache C:\Development\ExtendedConsole\ExtendedConsole\obj\Release\netstandard2.0\ExtendedConsole.AssemblyInfoInputs.cache C:\Development\ExtendedConsole\ExtendedConsole\obj\Release\netstandard2.0\ExtendedConsole.AssemblyInfo.cs diff --git a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.dll b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.dll index c65fa78..146abe0 100644 Binary files a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.dll and b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.dll differ diff --git a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.pdb b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.pdb index 0cb76ec..daf4eb5 100644 Binary files a/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.pdb and b/ExtendedConsole/obj/Release/netstandard2.0/ExtendedConsole.pdb differ diff --git a/ExtendedConsole/obj/project.assets.json b/ExtendedConsole/obj/project.assets.json index a0bbc7b..19f8160 100644 --- a/ExtendedConsole/obj/project.assets.json +++ b/ExtendedConsole/obj/project.assets.json @@ -183,7 +183,7 @@ "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {} }, "project": { - "version": "1.0.5", + "version": "1.1.0", "restore": { "projectUniqueName": "C:\\Development\\ExtendedConsole\\ExtendedConsole\\ExtendedConsole.csproj", "projectName": "ExtendedConsole", diff --git a/UsingExtendedConsole/Program.cs b/UsingExtendedConsole/Program.cs index 773bc38..06c1ee0 100644 --- a/UsingExtendedConsole/Program.cs +++ b/UsingExtendedConsole/Program.cs @@ -12,7 +12,31 @@ class Program static void Main(string[] args) { Console.Title = "Using Extended Console"; - //ShowLogo(exConsole); + + exConsole.ChooseFromEnum("s", true); + + var boolean = exConsole.ReadBool(ConsoleKey.Y, ConsoleKey.N, "Please press y or n"); + if(boolean) + { + Console.WriteLine("You've entered y"); + exConsole.Pause(); + } + else + { + exConsole.WriteLine("You've entered n").Pause(); + } + + var arr = new MID[] + { + new MID(1, "Zohar"), + new MID(2, "Peled"), + new MID(3, "Vered"), + new MID(4, "Berco") + }; + + var a = exConsole.MultipleSelectMenu(new MultipleSelectDisplayArgs("Multiple select with args", focusedItemColor:ConsoleColor.Cyan), arr); + + var b = exConsole.MultipleSelectMenu(new MultipleSelectDisplayArgs("Multiple select with args and toString"), s => $"{s.Id} {s.Name}" , arr); var menus = new Func[] { StringsMenu, ActionsMenu }; var index = 0; @@ -27,15 +51,12 @@ static void Main(string[] args) } private static void ShowLogo(ExConsole exConsole) - { - exConsole.WriteLines( + => exConsole.WriteLines( "", ". Extended", ". Console", "" - ); - Console.ReadKey(); - } + ).Pause(); private static int StringsMenu() { @@ -72,8 +93,7 @@ private static int StringsMenu() } private static int ActionsMenu() - { - return exConsole.Menu( + => exConsole.Menu( "Demonstraiting ExConsole - actions menu, clearWhenSelected = true", true, ("Quit", null), @@ -83,13 +103,12 @@ private static int ActionsMenu() ("Clear lines", ClearLines), ("Try it yourself", TryItYourself) ); - } static void WriteLineMethods() { - exConsole.WriteLine("Hello world!"); - exConsole.WriteLine("Testing some unrelated tags."); - exConsole.WriteLine("And another with no text in it"); + exConsole.WriteLine("Hello world!") + .WriteLine("Testing some unrelated tags.") + .WriteLine("And another with no text in it"); exConsole.WriteLine("And another with yellow text in it."); } @@ -153,4 +172,19 @@ private static void TryItYourself() } while (exConsole.ReadBool(ConsoleKey.Y, "Press Y to go again")); } } + + public class MID + { + public MID(int id, string name) + { + Id = id; + Name = name; + } + + public int Id { get; } + + public string Name { get; } + + public override string ToString() => $"{Id} {Name}"; + } } \ No newline at end of file diff --git a/UsingExtendedConsole/bin/Debug/ExtendedConsole.dll b/UsingExtendedConsole/bin/Debug/ExtendedConsole.dll index 7850bfb..ce4c5c0 100644 Binary files a/UsingExtendedConsole/bin/Debug/ExtendedConsole.dll and b/UsingExtendedConsole/bin/Debug/ExtendedConsole.dll differ diff --git a/UsingExtendedConsole/bin/Debug/ExtendedConsole.pdb b/UsingExtendedConsole/bin/Debug/ExtendedConsole.pdb index 7d48e53..983be8f 100644 Binary files a/UsingExtendedConsole/bin/Debug/ExtendedConsole.pdb and b/UsingExtendedConsole/bin/Debug/ExtendedConsole.pdb differ diff --git a/UsingExtendedConsole/bin/Debug/ExtendedConsole.xml b/UsingExtendedConsole/bin/Debug/ExtendedConsole.xml index e560f2b..3179225 100644 --- a/UsingExtendedConsole/bin/Debug/ExtendedConsole.xml +++ b/UsingExtendedConsole/bin/Debug/ExtendedConsole.xml @@ -29,6 +29,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", cyan on a dark gray background. @@ -42,6 +43,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", black on a white background, and advance the cursor to the next line. @@ -56,6 +58,7 @@ Lines of markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in yellow, "This is exConsole writing multiple markup lines" in the next line, with exConsole in green, and @@ -78,6 +81,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in magenta, followed by "How are you?" in black on a white background. Advance the cursor to the next line. @@ -93,6 +97,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in black on a magenta background, followed by "How are you?" in black on a white background. @@ -100,11 +105,222 @@ + + + Provides extension methods for ExConsole to support simple menus based on enum values. + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected, or null if the user selected the "quit" menu item. + Thrown when , or any of its properties, or are null. + Thrown when any of the string properties of or are empty. + Thrown when any of the string properties of or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "<c f='red'>none</c>", + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + invalidSelectionErrorMessage:"Please choose from the above list.") + ); + + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected. + Thrown when , or any of its properties are null. + Thrown when any of the string properties of are empty. + Thrown when any of the string properties of are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color.", + false, + "Please choose from the above list.") + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of . + The title of the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , or are null. + Thrown when any of , or is empty. + Thrown when , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color.", + "Please choose from the above list.", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color, or <c f='red>none</c> to keep current color.", + "<c f='red'>none</c>", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , , or are null. + Thrown when any of , , or is empty. + Thrown when , , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + "Please choose from the above list.", + "<c f='red'>none</c>", + true + ); + + + Provides extension methods for ExConsole for clearing specific console lines. + + + Clears all text from the current line. + + The current instance of ExConsole. + The current instance of . + + Clears the current line of the console. + + exConsole.ClearCurrentLine(); + + + Clears all text from a specific line. @@ -112,6 +328,7 @@ The current instance of ExConsole. Line index to clear. Thrown if is less than zero. + The current instance of . Clear the second line from the top. @@ -124,6 +341,7 @@ Clears all text from the last line. The current instance of ExConsole. + The current instance of . Clear the last line. @@ -135,9 +353,10 @@ Clears all text from the last lines. - The current instance of ExConsole. + The current instance of . The number of lines to clear (count up from last line) Thrown if is less than one. + The current instance of . Clear the last three lines. @@ -145,14 +364,88 @@ + + + Clears all the text on the console, and returns the current instance of ExConsole. + + The current instance of . + The current instance of . + + Pause, clear all lines, and ask the user to enter an integer value: + + exConsole + .Pause("Press any key to continue") + .ClearAllLines() + .ReadInt("Please enter a number:"); + + + Provides extension methods for ExConsole to support simple menus. + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + Each item contains a title and an action to perform, should the user choses this item. + null can be passed in as the action if the item selection should perform no action. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified title and items, that will disapear after the user selected an item. + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?"), + ("<c f='Yellow'>quit<c>", null), + ("Do this", () => DoThis(3)), + ("Do that", DoThat) + ); + + + + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified items, "What to do next?" as a title, + "Please enter the number of your selection." displayed below the items, + and "Invalid number entered. Please try again.", if the user enters an invalid value. + This menu does not execute anything, it only returns the zero-based index of the item selected by the user + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?", "Please enter the number of your selection.", invalidSelectionErrorMessage:"Invalid number entered. Please try again." ) + "<c f='Yellow'>quit<c>", + "Do this", + "Do that" + ); + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -180,7 +473,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -215,7 +515,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -243,7 +550,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -275,116 +589,63 @@ - + - Displays enum members as a menu for the user to choose from. + Provides extension methods for ExConsole to support multiple select menus. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - true - ); - - - + - Displays enum members as a menu for the user to choose from. - - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , or are null. - Thrown when any of , or is empty. - Thrown when , or are not properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color.", - "Please choose from the above list.", - true - ); - - - - - - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color, or <c f='red>none</c> to keep current color.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. - + - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , , or are null. - Thrown when any of , , or is empty. - Thrown when , , or are not properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + A to be used to display the items on the console, TResult is a . + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, as yyyy-mm-dd, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color or <c f='red>none</c> to keep current color.", - "Please choose from the above list.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + d => d.ToString("yyyy-mm-dd"), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. @@ -398,6 +659,7 @@ The current instance of ExConsole. Thrown when is null. + The current instance of . Write "Press any key to continue." to the console, and wait for the user to press a key. Advance the cursor to the next line. @@ -415,6 +677,7 @@ Thrown when or are null. Thrown when is empty. Thrown when isn't properly formatted xml. + The current instance of . Write "Press any key to continue." to the console, where "any key" is in yellow, and wait for the user to press a key. Advance the cursor to the next line. @@ -472,14 +735,14 @@ - Reads an input line from the user and converts it to a nullable T. + Reads an input line from the user and converts it to a nullable . The underlying type of the nullable to convert to. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - An instance of T? that has a value unless the user entered ^Z. + A function that takes in a string and returns a of success and value. + An instance of ? that has a value unless the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -497,14 +760,14 @@ - Reads an input line from the user and converts it to T. + Reads an input line from the user and converts it to . The target type of the conversion. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - The T value converted from the input string, or null if the user entered ^Z. + A function that takes in a string and returns a of success and value. + The value converted from the input string, or null if the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -528,7 +791,7 @@ - Reads multiple values from the user, converts and returns them as an IEnumerable<T>. + Reads multiple values from the user, converts and returns them as an . Repeats until the user enters the quit text. The type of values to convert to. @@ -537,14 +800,14 @@ The error message to show the user if the conversion failed. A string the user should enter when they are done entering values. A function that takes in a string and returns a value tuple of bool success and T value. - An IEnumerable<T> containing values conveted from the user input. + An containing values conveted from the user input. Thrown when any of the parameters is null. Thrown when , or are empty. Thrown when or aren't properly formatted xml. Read a collection of int values from the user. - The integers vairable is of type IEnumerable<T>, and will never be null. - If the user enters "done" before entering any valid integers, the retun value is an empty IEnumerable<T>. + The integers vairable is of type , and will never be null. + If the user enters "done" before entering any valid integers, the retun value is an empty . var integers = _exConsole.ReadValues( "Please enter integer values, or <c f='red'>done</c> to quit.", @@ -764,6 +1027,84 @@ + + + Stores display arguments for menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the menu. + The text to be displayed below the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The error message to show if the user entered an invalid selection. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + + + + + Gets the error message to display if the user enters an invalid value. + + + + + Stores display arguments for multiple select menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the multiple select menu. + The text to be displayed between the title and the menu, instructing the user how to use the menu. + A boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + The fore color to use for the currently focused item of the menu. + The error message to display if the user did not select anything from the menu. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + + + + + Gets the fore color to use for the currently focused item of the menu. + + + + + Gets the error message to display if the user did not select anything from the menu. + + Parse markup text, creates and returns an instance of the class. diff --git a/UsingExtendedConsole/bin/Debug/UsingExtendedConsole.exe b/UsingExtendedConsole/bin/Debug/UsingExtendedConsole.exe index 1122c8b..d9e3a1a 100644 Binary files a/UsingExtendedConsole/bin/Debug/UsingExtendedConsole.exe and b/UsingExtendedConsole/bin/Debug/UsingExtendedConsole.exe differ diff --git a/UsingExtendedConsole/bin/Debug/UsingExtendedConsole.pdb b/UsingExtendedConsole/bin/Debug/UsingExtendedConsole.pdb index bf18d0f..9a13347 100644 Binary files a/UsingExtendedConsole/bin/Debug/UsingExtendedConsole.pdb and b/UsingExtendedConsole/bin/Debug/UsingExtendedConsole.pdb differ diff --git a/UsingExtendedConsole/bin/Release/ExtendedConsole.dll b/UsingExtendedConsole/bin/Release/ExtendedConsole.dll index c65fa78..146abe0 100644 Binary files a/UsingExtendedConsole/bin/Release/ExtendedConsole.dll and b/UsingExtendedConsole/bin/Release/ExtendedConsole.dll differ diff --git a/UsingExtendedConsole/bin/Release/ExtendedConsole.pdb b/UsingExtendedConsole/bin/Release/ExtendedConsole.pdb index 0cb76ec..daf4eb5 100644 Binary files a/UsingExtendedConsole/bin/Release/ExtendedConsole.pdb and b/UsingExtendedConsole/bin/Release/ExtendedConsole.pdb differ diff --git a/UsingExtendedConsole/bin/Release/ExtendedConsole.xml b/UsingExtendedConsole/bin/Release/ExtendedConsole.xml index e560f2b..3179225 100644 --- a/UsingExtendedConsole/bin/Release/ExtendedConsole.xml +++ b/UsingExtendedConsole/bin/Release/ExtendedConsole.xml @@ -29,6 +29,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", cyan on a dark gray background. @@ -42,6 +43,7 @@ Markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!", black on a white background, and advance the cursor to the next line. @@ -56,6 +58,7 @@ Lines of markup text to write. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in yellow, "This is exConsole writing multiple markup lines" in the next line, with exConsole in green, and @@ -78,6 +81,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in magenta, followed by "How are you?" in black on a white background. Advance the cursor to the next line. @@ -93,6 +97,7 @@ Foreground color. Background color. Thrown when markup text isn't properly formatted xml. + The current instance of . Write "Hello World!" in black on a magenta background, followed by "How are you?" in black on a white background. @@ -100,11 +105,222 @@ + + + Provides extension methods for ExConsole to support simple menus based on enum values. + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected, or null if the user selected the "quit" menu item. + Thrown when , or any of its properties, or are null. + Thrown when any of the string properties of or are empty. + Thrown when any of the string properties of or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "<c f='red'>none</c>", + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + invalidSelectionErrorMessage:"Please choose from the above list.") + ); + + + + + + Displays enum members as a menu for the user to choose from. + + The type of the enum. + The current instance of ExConsole. + An instance of the class holding the display configuration of the enum based menu. + The member of the enum the user selected. + Thrown when , or any of its properties are null. + Thrown when any of the string properties of are empty. + Thrown when any of the string properties of are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + new MenuDisplayArgs( + "Choose a foreground color", + "Please choose a color.", + false, + "Please choose from the above list.") + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of . + The title of the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , or are null. + Thrown when any of , or is empty. + Thrown when , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list. + the color variable is of type ConsoleColor. + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color.", + "Please choose from the above list.", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when or are null. + Thrown when is empty. + Thrown when isn't properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color, or <c f='red>none</c> to keep current color.", + "<c f='red'>none</c>", + true + ); + + + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. + + + Displays enum members as a menu for the user to choose from. + + + The type of the enum. + The current instance of ExConsole. + The title of the menu. + The text to show below the menu. + The text to show when the user enters an invalid value. + The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The member of the enum the user selected. + Thrown when , , , or are null. + Thrown when any of , , or is empty. + Thrown when , , or are not properly formatted xml. + + Display the names of the members of the ConsoleColor enum, + asking the user to choose a color from the list, or "none". + the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + + var color = exConsole.ChooseFromEnum<ConsoleColor>( + "Choose a foreground color", + "Please choose a color or <c f='red>none</c> to keep current color.", + "Please choose from the above list.", + "<c f='red'>none</c>", + true + ); + + + Provides extension methods for ExConsole for clearing specific console lines. + + + Clears all text from the current line. + + The current instance of ExConsole. + The current instance of . + + Clears the current line of the console. + + exConsole.ClearCurrentLine(); + + + Clears all text from a specific line. @@ -112,6 +328,7 @@ The current instance of ExConsole. Line index to clear. Thrown if is less than zero. + The current instance of . Clear the second line from the top. @@ -124,6 +341,7 @@ Clears all text from the last line. The current instance of ExConsole. + The current instance of . Clear the last line. @@ -135,9 +353,10 @@ Clears all text from the last lines. - The current instance of ExConsole. + The current instance of . The number of lines to clear (count up from last line) Thrown if is less than one. + The current instance of . Clear the last three lines. @@ -145,14 +364,88 @@ + + + Clears all the text on the console, and returns the current instance of ExConsole. + + The current instance of . + The current instance of . + + Pause, clear all lines, and ask the user to enter an integer value: + + exConsole + .Pause("Press any key to continue") + .ClearAllLines() + .ReadInt("Please enter a number:"); + + + Provides extension methods for ExConsole to support simple menus. + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + Each item contains a title and an action to perform, should the user choses this item. + null can be passed in as the action if the item selection should perform no action. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified title and items, that will disapear after the user selected an item. + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?"), + ("<c f='Yellow'>quit<c>", null), + ("Do this", () => DoThis(3)), + ("Do that", DoThat) + ); + + + + + + Displays a menu to the user and invokes the action the user chooses. + + The current instance of ExConsole. + An instance of the class holding the display configuration of the menu. + The items of the menu. + An integer representing the user's choice. + Thrown when or or any of it's properties are null. + Thrown when is empty or when are not supplied. + Thrown when any of the text properties of isn't properly formatted xml. + + Create and run a menu with the specified items, "What to do next?" as a title, + "Please enter the number of your selection." displayed below the items, + and "Invalid number entered. Please try again.", if the user enters an invalid value. + This menu does not execute anything, it only returns the zero-based index of the item selected by the user + + var selection = exConsole.Menu( + new MenuDisplayArgs("What to do next?", "Please enter the number of your selection.", invalidSelectionErrorMessage:"Invalid number entered. Please try again." ) + "<c f='Yellow'>quit<c>", + "Do this", + "Do that" + ); + + + + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -180,7 +473,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and invokes the action the user chooses. + The current instance of ExConsole. The title of the menu. @@ -215,7 +515,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -243,7 +550,14 @@ + Note: + + This method is deprecated and will be removed in future versions. + Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. + + Displays a menu to the user and returns the index of the item the user chooses. + The current instance of ExConsole. The title of the menu. @@ -275,116 +589,63 @@ - + - Displays enum members as a menu for the user to choose from. + Provides extension methods for ExConsole to support multiple select menus. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - true - ); - - - + - Displays enum members as a menu for the user to choose from. - - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , or are null. - Thrown when any of , or is empty. - Thrown when , or are not properly formatted xml. - - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list. - the color variable is of type ConsoleColor. - - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color.", - "Please choose from the above list.", - true - ); - - - - - - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when or are null. - Thrown when is empty. - Thrown when isn't properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color, or <c f='red>none</c> to keep current color.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. - + - Displays enum members as a menu for the user to choose from. + Displays a multiple select menu to the user and returns the item(s) the user selected. - The type of the enum. - The current instance of ExConsole. - The title of the menu. - The text to show below the menu. - The text to show when the user enters an invalid value. - The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. - A boolean value to determine - whether the menu should still be displayed after the user have chosen an option. - The member of the enum the user selected. - Thrown when , , , or are null. - Thrown when any of , , or is empty. - Thrown when , , or are not properly formatted xml. + The type of items for the user to select from. + The current instance of . + An instance of the class holding the display configuration of the menu. + A to be used to display the items on the console, TResult is a . + The items of the menu. + An containing the values selected by the user. + Thrown when any of the parameters is null. + Thrown when any of the text properties of are empty, or when contain less than two items. + Thrown when any of the text properties of aren't properly formatted xml. - Display the names of the members of the ConsoleColor enum, - asking the user to choose a color from the list, or "none". - the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none". + Show the user a list of dates to choose from, as yyyy-mm-dd, return an where T is . - var color = exConsole.ChooseFromEnum<ConsoleColor>( - "Choose a foreground color", - "Please choose a color or <c f='red>none</c> to keep current color.", - "Please choose from the above list.", - "<c f='red'>none</c>", - true + var dates = exConsole.MultipleSelectMenu( + new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), + d => d.ToString("yyyy-mm-dd"), + DateTime.Now, + DateTime.Now.AddHours(1), + DateTime.Now.AddHours(2), + DateTime.Now.AddHours(3) ); + After the user selects the desired values, the `dates` variable will contain the user's selection. @@ -398,6 +659,7 @@ The current instance of ExConsole. Thrown when is null. + The current instance of . Write "Press any key to continue." to the console, and wait for the user to press a key. Advance the cursor to the next line. @@ -415,6 +677,7 @@ Thrown when or are null. Thrown when is empty. Thrown when isn't properly formatted xml. + The current instance of . Write "Press any key to continue." to the console, where "any key" is in yellow, and wait for the user to press a key. Advance the cursor to the next line. @@ -472,14 +735,14 @@ - Reads an input line from the user and converts it to a nullable T. + Reads an input line from the user and converts it to a nullable . The underlying type of the nullable to convert to. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - An instance of T? that has a value unless the user entered ^Z. + A function that takes in a string and returns a of success and value. + An instance of ? that has a value unless the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -497,14 +760,14 @@ - Reads an input line from the user and converts it to T. + Reads an input line from the user and converts it to . The target type of the conversion. The current instance of ExConsole. The title to show the user before asking for input. The error message to show the user if the conversion failed. - A function that takes in a string and returns a value tuple of bool success and T value. - The T value converted from the input string, or null if the user entered ^Z. + A function that takes in a string and returns a of success and value. + The value converted from the input string, or null if the user entered ^Z. Thrown when any of the parameters is null. Thrown when or are empty. Thrown when or aren't properly formatted xml. @@ -528,7 +791,7 @@ - Reads multiple values from the user, converts and returns them as an IEnumerable<T>. + Reads multiple values from the user, converts and returns them as an . Repeats until the user enters the quit text. The type of values to convert to. @@ -537,14 +800,14 @@ The error message to show the user if the conversion failed. A string the user should enter when they are done entering values. A function that takes in a string and returns a value tuple of bool success and T value. - An IEnumerable<T> containing values conveted from the user input. + An containing values conveted from the user input. Thrown when any of the parameters is null. Thrown when , or are empty. Thrown when or aren't properly formatted xml. Read a collection of int values from the user. - The integers vairable is of type IEnumerable<T>, and will never be null. - If the user enters "done" before entering any valid integers, the retun value is an empty IEnumerable<T>. + The integers vairable is of type , and will never be null. + If the user enters "done" before entering any valid integers, the retun value is an empty . var integers = _exConsole.ReadValues( "Please enter integer values, or <c f='red'>done</c> to quit.", @@ -764,6 +1027,84 @@ + + + Stores display arguments for menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the menu. + The text to be displayed below the menu. + A boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + The error message to show if the user entered an invalid selection. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have chosen an option. + + + + + Gets the error message to display if the user enters an invalid value. + + + + + Stores display arguments for multiple select menu. + + + + + Creates a new instance of the class with the specified parmeters. + + The title of the multiple select menu. + The text to be displayed between the title and the menu, instructing the user how to use the menu. + A boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + The fore color to use for the currently focused item of the menu. + The error message to display if the user did not select anything from the menu. + + + + Gets the title of the multiple select menu. + + + + + Gets the text to be displayed between the title and the menu, instructing the user how to use the menu. + + + + + Gets a boolean value to determine + whether the menu should still be displayed after the user have completed his selection. + + + + + Gets the fore color to use for the currently focused item of the menu. + + + + + Gets the error message to display if the user did not select anything from the menu. + + Parse markup text, creates and returns an instance of the class. diff --git a/UsingExtendedConsole/bin/Release/UsingExtendedConsole.exe b/UsingExtendedConsole/bin/Release/UsingExtendedConsole.exe index 7d9e84e..0f8dcae 100644 Binary files a/UsingExtendedConsole/bin/Release/UsingExtendedConsole.exe and b/UsingExtendedConsole/bin/Release/UsingExtendedConsole.exe differ diff --git a/UsingExtendedConsole/bin/Release/UsingExtendedConsole.pdb b/UsingExtendedConsole/bin/Release/UsingExtendedConsole.pdb index 42f023f..af5b2e8 100644 Binary files a/UsingExtendedConsole/bin/Release/UsingExtendedConsole.pdb and b/UsingExtendedConsole/bin/Release/UsingExtendedConsole.pdb differ diff --git a/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.csprojAssemblyReference.cache b/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.csprojAssemblyReference.cache index 5691394..9d180f9 100644 Binary files a/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.csprojAssemblyReference.cache and b/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.csprojAssemblyReference.cache differ diff --git a/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.exe b/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.exe index 1122c8b..d9e3a1a 100644 Binary files a/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.exe and b/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.exe differ diff --git a/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.pdb b/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.pdb index bf18d0f..9a13347 100644 Binary files a/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.pdb and b/UsingExtendedConsole/obj/Debug/UsingExtendedConsole.pdb differ diff --git a/UsingExtendedConsole/obj/Release/UsingExtendedConsole.csproj.CoreCompileInputs.cache b/UsingExtendedConsole/obj/Release/UsingExtendedConsole.csproj.CoreCompileInputs.cache index 0361940..4cbe83b 100644 --- a/UsingExtendedConsole/obj/Release/UsingExtendedConsole.csproj.CoreCompileInputs.cache +++ b/UsingExtendedConsole/obj/Release/UsingExtendedConsole.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -e05278d5751508683ca180f5f2a0427425d2d0b4 +864b687ecfc5183ae312bdde490d1d7b399e0171 diff --git a/UsingExtendedConsole/obj/Release/UsingExtendedConsole.csprojAssemblyReference.cache b/UsingExtendedConsole/obj/Release/UsingExtendedConsole.csprojAssemblyReference.cache index ccdd2e0..2485a30 100644 Binary files a/UsingExtendedConsole/obj/Release/UsingExtendedConsole.csprojAssemblyReference.cache and b/UsingExtendedConsole/obj/Release/UsingExtendedConsole.csprojAssemblyReference.cache differ diff --git a/UsingExtendedConsole/obj/Release/UsingExtendedConsole.exe b/UsingExtendedConsole/obj/Release/UsingExtendedConsole.exe index 7d9e84e..0f8dcae 100644 Binary files a/UsingExtendedConsole/obj/Release/UsingExtendedConsole.exe and b/UsingExtendedConsole/obj/Release/UsingExtendedConsole.exe differ diff --git a/UsingExtendedConsole/obj/Release/UsingExtendedConsole.pdb b/UsingExtendedConsole/obj/Release/UsingExtendedConsole.pdb index 42f023f..af5b2e8 100644 Binary files a/UsingExtendedConsole/obj/Release/UsingExtendedConsole.pdb and b/UsingExtendedConsole/obj/Release/UsingExtendedConsole.pdb differ diff --git a/docs/api/ExtendedConsole.ExConsole.html b/docs/api/ExtendedConsole.ExConsole.html index 97044e8..ab49c01 100644 --- a/docs/api/ExtendedConsole.ExConsole.html +++ b/docs/api/ExtendedConsole.ExConsole.html @@ -10,7 +10,7 @@ - + @@ -130,7 +130,7 @@

Declaration
-
public void Write(string markup)
+
public ExConsole Write(string markup)
Parameters
@@ -146,6 +146,22 @@
Parameters
+ + +
System.String markup

Markup text to write.

+
+
Returns
+ + + + + + + + + + + @@ -179,7 +195,7 @@

Declaration
-
public void Write(string markup, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor)
+
public ExConsole Write(string markup, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor)
Parameters
TypeDescription
ExConsole

The current instance of ExConsole.

@@ -207,6 +223,22 @@
Parameters
+ + +
System.Nullable<System.ConsoleColor> backgroundColor

Background color.

+
+
Returns
+ + + + + + + + + + + @@ -240,7 +272,7 @@

Declaration
-
public void WriteLine(string markup)
+
public ExConsole WriteLine(string markup)
Parameters
TypeDescription
ExConsole

The current instance of ExConsole.

@@ -256,6 +288,22 @@
Parameters
+ + +
System.String markup

Markup text to write.

+
+
Returns
+ + + + + + + + + + + @@ -291,7 +339,7 @@

Declaration
-
public void WriteLine(string markup, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor)
+
public ExConsole WriteLine(string markup, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor)
Parameters
TypeDescription
ExConsole

The current instance of ExConsole.

@@ -319,6 +367,22 @@
Parameters
+ + +
System.Nullable<System.ConsoleColor> backgroundColor

Background color.

+
+
Returns
+ + + + + + + + + + + @@ -352,7 +416,7 @@

Declaration
-
public void WriteLines(params string[] lines)
+
public ExConsole WriteLines(params string[] lines)
Parameters
TypeDescription
ExConsole

The current instance of ExConsole.

@@ -368,6 +432,22 @@
Parameters
+ + +
System.String[] lines

Lines of markup text to write.

+
+
Returns
+ + + + + + + + + + + @@ -399,6 +479,27 @@
Exceptions
TypeDescription
ExConsole

The current instance of ExConsole.

Extension Methods

+ + + + + + + @@ -409,28 +510,31 @@

Extension Methods

ExConsoleClearLines.ClearLastLines(ExConsole, Int32) +
ExConsoleRead.Pause(ExConsole) @@ -490,7 +594,8 @@

Extension Methods

diff --git a/docs/api/ExtendedConsole.ExConsoleChooseFromEnum.html b/docs/api/ExtendedConsole.ExConsoleChooseFromEnum.html new file mode 100644 index 0000000..78e9edd --- /dev/null +++ b/docs/api/ExtendedConsole.ExConsoleChooseFromEnum.html @@ -0,0 +1,884 @@ + + + + + + + + Class ExConsoleChooseFromEnum + + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api/ExtendedConsole.ExConsoleClearLines.html b/docs/api/ExtendedConsole.ExConsoleClearLines.html index 58df58b..7a03c62 100644 --- a/docs/api/ExtendedConsole.ExConsoleClearLines.html +++ b/docs/api/ExtendedConsole.ExConsoleClearLines.html @@ -10,7 +10,7 @@ - + @@ -115,6 +115,107 @@

Methods

+ +

ClearAllLines(ExConsole)

+

Clears all the text on the console, and returns the current instance of ExConsole.

+
+
+
Declaration
+
+
public static ExConsole ClearAllLines(this ExConsole self)
+
+
Parameters
+ + + + + + + + + + + + + + + +
TypeNameDescription
ExConsoleself

The current instance of ExConsole.

+
+
Returns
+ + + + + + + + + + + + + +
TypeDescription
ExConsole

The current instance of ExConsole.

+
+
Examples
+

Pause, clear all lines, and ask the user to enter an integer value:

+
exConsole
+    .Pause("Press any key to continue")
+    .ClearAllLines()
+    .ReadInt("Please enter a number:");
+ + + + +

ClearCurrentLine(ExConsole)

+

Clears all text from the current line.

+
+
+
Declaration
+
+
public static ExConsole ClearCurrentLine(this ExConsole self)
+
+
Parameters
+ + + + + + + + + + + + + + + +
TypeNameDescription
ExConsoleself

The current instance of ExConsole.

+
+
Returns
+ + + + + + + + + + + + + +
TypeDescription
ExConsole

The current instance of ExConsole.

+
+
Examples
+

Clears the current line of the console.

+
exConsole.ClearCurrentLine();
+ + +

ClearLastLine(ExConsole)

Clears all text from the last line.

@@ -122,7 +223,7 @@

Declaration
-
public static void ClearLastLine(this ExConsole self)
+
public static ExConsole ClearLastLine(this ExConsole self)
Parameters
@@ -138,6 +239,22 @@
Parameters
+ + +
ExConsole self

The current instance of ExConsole.

+
+
Returns
+ + + + + + + + + + + @@ -155,7 +272,7 @@

Declaration
-
public static void ClearLastLines(this ExConsole self, int numberOfLines)
+
public static ExConsole ClearLastLines(this ExConsole self, int numberOfLines)
Parameters
TypeDescription
ExConsole

The current instance of ExConsole.

@@ -170,13 +287,29 @@
Parameters
- + + +
ExConsole self

The current instance of ExConsole.

+

The current instance of ExConsole.

System.Int32 numberOfLines

The number of lines to clear (count up from last line)

+
+
Returns
+ + + + + + + + + + + @@ -210,7 +343,7 @@

Declaration
-
public static void ClearLine(this ExConsole self, int lineIndex)
+
public static ExConsole ClearLine(this ExConsole self, int lineIndex)
Parameters
TypeDescription
ExConsole

The current instance of ExConsole.

@@ -232,6 +365,22 @@
Parameters
+ + +
System.Int32 lineIndex

Line index to clear.

+
+
Returns
+ + + + + + + + + + + @@ -266,7 +415,8 @@
Exceptions
diff --git a/docs/api/ExtendedConsole.ExConsoleMenu.html b/docs/api/ExtendedConsole.ExConsoleMenu.html index 97b3ff7..8e955d3 100644 --- a/docs/api/ExtendedConsole.ExConsoleMenu.html +++ b/docs/api/ExtendedConsole.ExConsoleMenu.html @@ -10,7 +10,7 @@ - + @@ -115,242 +115,14 @@

Methods

- -

ChooseFromEnum<T>(ExConsole, String, Boolean)

-

Displays enum members as a menu for the user to choose from.

-
-
-
Declaration
-
-
public static T ChooseFromEnum<T>(this ExConsole self, string title, bool clearWhenSelected)
-    where T : Enum
-
-
Parameters
-
TypeDescription
ExConsole

The current instance of ExConsole.

- - - - - - - - - - - - - - - - - - - - - - - - -
TypeNameDescription
ExConsoleself

The current instance of ExConsole.

-
System.Stringtitle

The title of the menu.

-
System.BooleanclearWhenSelected

A boolean value to determine -whether the menu should still be displayed after the user have chosen an option.

-
-
Returns
- - - - - - - - - - - - - -
TypeDescription
T

The member of the enum the user selected.

-
-
Type Parameters
- - - - - - - - - - - - - -
NameDescription
T

The type of the enum.

-
-
Examples
-

Display the names of the members of the ConsoleColor enum, -asking the user to choose a color from the list. -the color variable is of type ConsoleColor.

-
var color = exConsole.ChooseFromEnum<ConsoleColor>(
-   "Choose a foreground color",
-   true
-);
- -
Exceptions
- - - - - - - - - - - - - - - - - - - - - -
TypeCondition
System.ArgumentNullException

Thrown when self or title are null.

-
System.ArgumentException

Thrown when title is empty.

-
System.Xml.XmlException

Thrown when title isn't properly formatted xml.

-
- - - -

ChooseFromEnum<T>(ExConsole, String, String, Boolean)

-

Displays enum members as a menu for the user to choose from.

-
-
-
Declaration
-
-
public static T? ChooseFromEnum<T>(this ExConsole self, string title, string quitText, bool clearWhenSelected)
-    where T : struct, Enum
-
-
Parameters
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TypeNameDescription
ExConsoleself

The current instance of ExConsole.

-
System.Stringtitle

The title of the menu.

-
System.StringquitText

The title of a menu item that isn't a member of the enum, to enable the user to return without choosing.

-
System.BooleanclearWhenSelected

A boolean value to determine -whether the menu should still be displayed after the user have chosen an option.

-
-
Returns
- - - - - - - - - - - - - -
TypeDescription
System.Nullable<T>

The member of the enum the user selected.

-
-
Type Parameters
- - - - - - - - - - - - - -
NameDescription
T

The type of the enum.

-
-
Examples
-

Display the names of the members of the ConsoleColor enum, -asking the user to choose a color from the list, or "none". -the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none".

-
var color = exConsole.ChooseFromEnum<ConsoleColor>(
-   "Choose a foreground color, or <c f='red>none</c> to keep current color.",
-   "<c f='red'>none</c>",
-   true
-);
- -
Exceptions
- - - - - - - - - - - - - - - - - - - - - -
TypeCondition
System.ArgumentNullException

Thrown when self or title are null.

-
System.ArgumentException

Thrown when title is empty.

-
System.Xml.XmlException

Thrown when title isn't properly formatted xml.

-
- - - -

ChooseFromEnum<T>(ExConsole, String, String, String, Boolean)

-

Displays enum members as a menu for the user to choose from.

+ +

Menu(ExConsole, MenuDisplayArgs, String[])

+

Displays a menu to the user and invokes the action the user chooses.

Declaration
-
public static T ChooseFromEnum<T>(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected)
-    where T : Enum
+
public static int Menu(this ExConsole self, MenuDisplayArgs displayArgs, params string[] items)
Parameters
@@ -369,28 +141,15 @@
Parameters
- - - - - - - - - - - - - + + - - - + + @@ -405,38 +164,23 @@
Returns
- - - - -
System.Stringtitle

The title of the menu.

-
System.StringpleaseSelectText

The text to show below the menu.

-
System.StringinvalidSelectionText

The text to show when the user enters an invalid value.

+
MenuDisplayArgsdisplayArgs

An instance of the MenuDisplayArgs class holding the display configuration of the menu.

System.BooleanclearWhenSelected

A boolean value to determine -whether the menu should still be displayed after the user have chosen an option.

+
System.String[]items

The items of the menu.

T

The member of the enum the user selected.

-
-
Type Parameters
- - - - - - - - - - - +
NameDescription
T

The type of the enum.

+
System.Int32

An integer representing the user's choice.

-
Examples
-

Display the names of the members of the ConsoleColor enum, -asking the user to choose a color from the list. -the color variable is of type ConsoleColor.

-
var color = exConsole.ChooseFromEnum<ConsoleColor>(
-   "Choose a foreground color",
-   "Please choose a color.",
-   "Please choose from the above list.",
-   true
-);
+
Examples
+

Create and run a menu with the specified items, "What to do next?" as a title,
+"Please enter the number of your selection." displayed below the items, +and "Invalid number entered. Please try again.", if the user enters an invalid value. +This menu does not execute anything, it only returns the zero-based index of the item selected by the user

+
 var selection = exConsole.Menu(
+    new MenuDisplayArgs("What to do next?", "Please enter the number of your selection.", invalidSelectionErrorMessage:"Invalid number entered. Please try again." )
+    "<c f='Yellow'>quit<c>",
+    "Do this",
+    "Do that"
+ );
Exceptions
@@ -449,32 +193,31 @@
Exceptions
- - -
System.ArgumentNullException

Thrown when self, title, pleaseSelectText or invalidSelectionText are null.

+

Thrown when self or displayArgs or any of it's properties are null.

System.ArgumentException

Thrown when any of title, pleaseSelectText or invalidSelectionText is empty.

+

Thrown when displayArgs is empty or when items are not supplied.

System.Xml.XmlException

Thrown when title, pleaseSelectText or invalidSelectionText are not properly formatted xml.

+

Thrown when any of the text properties of displayArgs isn't properly formatted xml.

- -

ChooseFromEnum<T>(ExConsole, String, String, String, String, Boolean)

-

Displays enum members as a menu for the user to choose from.

+ +

Menu(ExConsole, MenuDisplayArgs, (String Title, Action Action)[])

+

Displays a menu to the user and invokes the action the user chooses.

Declaration
-
public static T? ChooseFromEnum<T>(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, string quitText, bool clearWhenSelected)
-    where T : struct, Enum
+
public static int Menu(this ExConsole self, MenuDisplayArgs displayArgs, params (string Title, Action Action)[] items)
Parameters
@@ -493,34 +236,17 @@
Parameters
- - - - - - - - - - - - - - - - - - + + - - - + + @@ -535,39 +261,20 @@
Returns
- - - - -
System.Stringtitle

The title of the menu.

-
System.StringpleaseSelectText

The text to show below the menu.

-
System.StringinvalidSelectionText

The text to show when the user enters an invalid value.

-
System.StringquitText

The title of a menu item that isn't a member of the enum, to enable the user to return without choosing.

+
MenuDisplayArgsdisplayArgs

An instance of the MenuDisplayArgs class holding the display configuration of the menu.

System.BooleanclearWhenSelected

A boolean value to determine -whether the menu should still be displayed after the user have chosen an option.

+
System.ValueTuple<System.String, System.Action>[]items

The items of the menu. +Each item contains a title and an action to perform, should the user choses this item. +null can be passed in as the action if the item selection should perform no action.

System.Nullable<T>

The member of the enum the user selected.

-
-
Type Parameters
- - - - - - - - - - - +
NameDescription
T

The type of the enum.

+
System.Int32

An integer representing the user's choice.

-
Examples
-

Display the names of the members of the ConsoleColor enum, -asking the user to choose a color from the list, or "none". -the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none".

-
var color = exConsole.ChooseFromEnum<ConsoleColor>(
-   "Choose a foreground color",
-   "Please choose a color or <c f='red>none</c> to keep current color.",
-   "Please choose from the above list.",
-   "<c f='red'>none</c>",
-   true
-);
+
Examples
+

Create and run a menu with the specified title and items, that will disapear after the user selected an item.

+
 var selection = exConsole.Menu(
+     new MenuDisplayArgs("What to do next?"),
+     ("<c f='Yellow'>quit<c>", null),
+     ("Do this", () => DoThis(3)),
+     ("Do that", DoThat)
+ );
Exceptions
@@ -580,17 +287,17 @@
Exceptions
- - - @@ -599,12 +306,20 @@
Exceptions

Menu(ExConsole, String, Boolean, String[])

-

Displays a menu to the user and returns the index of the item the user chooses.

+

Note:

+

+This method is deprecated and will be removed in future versions. +Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. +

+

+Displays a menu to the user and returns the index of the item the user chooses. +

Declaration
-
public static int Menu(this ExConsole self, string title, bool clearWhenSelected, params string[] items)
+
[Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the Menu overload that takes an instance of MenuDisplayArgs as an argument instead.")]
+public static int Menu(this ExConsole self, string title, bool clearWhenSelected, params string[] items)
Parameters
System.ArgumentNullException

Thrown when self, title, pleaseSelectText, invalidSelectionText or quitText are null.

+

Thrown when self or displayArgs or any of it's properties are null.

System.ArgumentException

Thrown when any of title, pleaseSelectText, invalidSelectionText or quitText is empty.

+

Thrown when displayArgs is empty or when items are not supplied.

System.Xml.XmlException

Thrown when title, pleaseSelectText, invalidSelectionText or quitText are not properly formatted xml.

+

Thrown when any of the text properties of displayArgs isn't properly formatted xml.

@@ -701,12 +416,20 @@
Exceptions

Menu(ExConsole, String, Boolean, (String Title, Action Action)[])

-

Displays a menu to the user and invokes the action the user chooses.

+

Note:

+

+This method is deprecated and will be removed in future versions. +Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. +

+

+Displays a menu to the user and invokes the action the user chooses. +

Declaration
-
public static int Menu(this ExConsole self, string title, bool clearWhenSelected, params (string Title, Action Action)[] items)
+
[Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the Menu overload that takes an instance of MenuDisplayArgs as an argument instead.")]
+public static int Menu(this ExConsole self, string title, bool clearWhenSelected, params (string Title, Action Action)[] items)
Parameters
@@ -803,12 +526,20 @@
Exceptions

Menu(ExConsole, String, String, String, Boolean, String[])

-

Displays a menu to the user and returns the index of the item the user chooses.

+

Note:

+

+This method is deprecated and will be removed in future versions. +Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. +

+

+Displays a menu to the user and returns the index of the item the user chooses. +

Declaration
-
public static int Menu(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected, params string[] items)
+
[Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the Menu overload that takes an instance of MenuDisplayArgs as an argument instead.")]
+public static int Menu(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected, params string[] items)
Parameters
@@ -921,12 +652,20 @@
Exceptions

Menu(ExConsole, String, String, String, Boolean, (String Title, Action Action)[])

-

Displays a menu to the user and invokes the action the user chooses.

+

Note:

+

+This method is deprecated and will be removed in future versions. +Use the Menu overload that takes an instance of MenuDisplayArgs as an argument instead. +

+

+Displays a menu to the user and invokes the action the user chooses. +

Declaration
-
public static int Menu(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected, params (string Title, Action Action)[] items)
+
[Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the Menu overload that takes an instance of MenuDisplayArgs as an argument instead.")]
+public static int Menu(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected, params (string Title, Action Action)[] items)
Parameters
@@ -1046,7 +785,8 @@
Exceptions
diff --git a/docs/api/ExtendedConsole.ExConsoleMultipleSelectMenu.html b/docs/api/ExtendedConsole.ExConsoleMultipleSelectMenu.html new file mode 100644 index 0000000..7f01ee0 --- /dev/null +++ b/docs/api/ExtendedConsole.ExConsoleMultipleSelectMenu.html @@ -0,0 +1,379 @@ + + + + + + + + Class ExConsoleMultipleSelectMenu + + + + + + + + + + + + + + + + +
+
+ + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
TypeNameDescription
ExConsoleself

The current instance of ExConsole.

+
MultipleSelectDisplayArgsdisplayArgs

An instance of the MultipleSelectDisplayArgs class holding the display configuration of the menu.

+
T[]items

The items of the menu.

+
+
Returns
+ + + + + + + + + + + + + +
TypeDescription
System.Collections.Generic.IEnumerable<T>

An System.Collections.Generic.IEnumerable<T> containing the values selected by the user.

+
+
Type Parameters
+ + + + + + + + + + + + + +
NameDescription
T

The type of items for the user to select from.

+
+
Examples
+

Show the user a list of dates to choose from, return an System.Collections.Generic.IEnumerable<T> where T is System.DateTime.

+
var dates = exConsole.MultipleSelectMenu(
+    new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), 
+    DateTime.Now, 
+    DateTime.Now.AddHours(1), 
+    DateTime.Now.AddHours(2), 
+    DateTime.Now.AddHours(3)
+);
+

After the user selects the desired values, the dates variable will contain the user's selection.

+ +
Exceptions
+ + + + + + + + + + + + + + + + + + + + + +
TypeCondition
System.ArgumentNullException

Thrown when any of the parameters is null.

+
System.ArgumentException

Thrown when any of the text properties of displayArgs are empty, or when items contain less than two items.

+
System.Xml.XmlException

Thrown when any of the text properties of displayArgs aren't properly formatted xml.

+
+ + + +

MultipleSelectMenu<T>(ExConsole, MultipleSelectDisplayArgs, Func<T, String>, T[])

+

Displays a multiple select menu to the user and returns the item(s) the user selected.

+
+
+
Declaration
+
+
public static IEnumerable<T> MultipleSelectMenu<T>(this ExConsole self, MultipleSelectDisplayArgs displayArgs, Func<T, string> toString, params T[] items)
+
+
Parameters
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeNameDescription
ExConsoleself

The current instance of ExConsole.

+
MultipleSelectDisplayArgsdisplayArgs

An instance of the MultipleSelectDisplayArgs class holding the display configuration of the menu.

+
System.Func<T, System.String>toString

A System.Func<T, TResult> to be used to display the items on the console, TResult is a System.String.

+
T[]items

The items of the menu.

+
+
Returns
+ + + + + + + + + + + + + +
TypeDescription
System.Collections.Generic.IEnumerable<T>

An System.Collections.Generic.IEnumerable<T> containing the values selected by the user.

+
+
Type Parameters
+ + + + + + + + + + + + + +
NameDescription
T

The type of items for the user to select from.

+
+
Examples
+

Show the user a list of dates to choose from, as yyyy-mm-dd, return an System.Collections.Generic.IEnumerable<T> where T is System.DateTime.

+
var dates = exConsole.MultipleSelectMenu(
+    new MultipleSelectDisplayArgs("Select at least one date.", focusedItemColor:ConsoleColor.Cyan), 
+    d => d.ToString("yyyy-mm-dd"),
+    DateTime.Now, 
+    DateTime.Now.AddHours(1), 
+    DateTime.Now.AddHours(2), 
+    DateTime.Now.AddHours(3)
+);
+

After the user selects the desired values, the dates variable will contain the user's selection.

+ +
Exceptions
+ + + + + + + + + + + + + + + + + + + + + +
TypeCondition
System.ArgumentNullException

Thrown when any of the parameters is null.

+
System.ArgumentException

Thrown when any of the text properties of displayArgs are empty, or when items contain less than two items.

+
System.Xml.XmlException

Thrown when any of the text properties of displayArgs aren't properly formatted xml.

+
+ +
+ + +
+ + + + + + + + + + diff --git a/docs/api/ExtendedConsole.ExConsoleRead.html b/docs/api/ExtendedConsole.ExConsoleRead.html index d2866b4..7c12352 100644 --- a/docs/api/ExtendedConsole.ExConsoleRead.html +++ b/docs/api/ExtendedConsole.ExConsoleRead.html @@ -10,7 +10,7 @@ - + @@ -122,7 +122,7 @@

Declaration
-
public static void Pause(this ExConsole self)
+
public static ExConsole Pause(this ExConsole self)
Parameters
@@ -138,6 +138,22 @@
Parameters
+ + +
ExConsole self

The current instance of ExConsole.

+
+
Returns
+ + + + + + + + + + + @@ -172,7 +188,7 @@

Declaration
-
public static void Pause(this ExConsole self, string title)
+
public static ExConsole Pause(this ExConsole self, string title)
Parameters
TypeDescription
ExConsole

The current instance of ExConsole.

@@ -194,6 +210,22 @@
Parameters
+ + +
System.String title

The title to show the user before asking for input.

+
+
Returns
+ + + + + + + + + + + @@ -419,7 +451,7 @@
Exceptions

ReadClass<T>(ExConsole, String, String, Func<String, (Boolean Success, T Value)>)

-

Reads an input line from the user and converts it to T.

+

Reads an input line from the user and converts it to T.

Declaration
@@ -458,7 +490,7 @@
Parameters
- @@ -474,7 +506,7 @@
Returns
- @@ -1313,7 +1345,7 @@
Exceptions

ReadStruct<T>(ExConsole, String, String, Func<String, (Boolean Success, T Value)>)

-

Reads an input line from the user and converts it to a nullable T.

+

Reads an input line from the user and converts it to a nullable T.

Declaration
@@ -1352,7 +1384,7 @@
Parameters
- @@ -1368,7 +1400,7 @@
Returns
- @@ -1391,7 +1423,7 @@
Type Parameters
TypeDescription
ExConsole

The current instance of ExConsole.

System.Func<System.String, System.ValueTuple<System.Boolean, T>> converter

A function that takes in a string and returns a value tuple of bool success and T value.

+

A function that takes in a string and returns a System.ValueTuple of System.Boolean success and T value.

T

The T value converted from the input string, or null if the user entered ^Z.

+

The T value converted from the input string, or null if the user entered ^Z.

System.Func<System.String, System.ValueTuple<System.Boolean, T>> converter

A function that takes in a string and returns a value tuple of bool success and T value.

+

A function that takes in a string and returns a System.ValueTuple of System.Boolean success and T value.

System.Nullable<T>

An instance of T? that has a value unless the user entered ^Z.

+

An instance of T? that has a value unless the user entered ^Z.

Examples

Parse and get an instance of the TimeSpan struct from user input. -The duration variable is of type Nullable<TimeSpan>, and will be null if the user entered ctrl+Z.

+The duration variable is of type Nullable&lt;TimeSpan>, and will be null if the user entered ctrl+Z.

var duration = exConsole.ReadStruct(
     "Please enter estimated time (HH:mm:ss)",
     "Invalid value entered",
@@ -1546,7 +1578,7 @@ 
Exceptions

ReadValues<T>(ExConsole, String, String, String, Func<String, (Boolean Success, T Value)>)

-

Reads multiple values from the user, converts and returns them as an IEnumerable<T>. +

Reads multiple values from the user, converts and returns them as an System.Collections.Generic.IEnumerable<T>. Repeats until the user enters the quit text.

@@ -1607,7 +1639,7 @@
Returns
System.Collections.Generic.IEnumerable<T> -

An IEnumerable<T> containing values conveted from the user input.

+

An System.Collections.Generic.IEnumerable<T> containing values conveted from the user input.

@@ -1630,8 +1662,8 @@
Type Parameters
Examples

Read a collection of int values from the user. -The integers vairable is of type IEnumerable<T>, and will never be null. -If the user enters "done" before entering any valid integers, the retun value is an empty IEnumerable<T>.

+The integers vairable is of type System.Collections.Generic.IEnumerable<T>, and will never be null. +If the user enters "done" before entering any valid integers, the retun value is an empty System.Collections.Generic.IEnumerable<T>.

var integers = _exConsole.ReadValues(
     "Please enter integer values, or <c f='red'>done</c> to quit.",
     "failed to parse input as int.",
@@ -1675,7 +1707,8 @@ 
Exceptions
diff --git a/docs/api/ExtendedConsole.MenuDisplayArgs.html b/docs/api/ExtendedConsole.MenuDisplayArgs.html new file mode 100644 index 0000000..bd9985c --- /dev/null +++ b/docs/api/ExtendedConsole.MenuDisplayArgs.html @@ -0,0 +1,307 @@ + + + + + + + + Class MenuDisplayArgs + + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api/ExtendedConsole.MultipleSelectDisplayArgs.html b/docs/api/ExtendedConsole.MultipleSelectDisplayArgs.html new file mode 100644 index 0000000..6751963 --- /dev/null +++ b/docs/api/ExtendedConsole.MultipleSelectDisplayArgs.html @@ -0,0 +1,339 @@ + + + + + + + + Class MultipleSelectDisplayArgs + + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api/ExtendedConsole.html b/docs/api/ExtendedConsole.html index a8aa5e8..b49c0b4 100644 --- a/docs/api/ExtendedConsole.html +++ b/docs/api/ExtendedConsole.html @@ -10,7 +10,7 @@ - + @@ -87,15 +87,27 @@

ExConsole

Markup example:
<c f='Yellow'>yellow text<c b='blue'> on blue background.</c></c>

+ +

ExConsoleChooseFromEnum

+

Provides extension methods for ExConsole to support simple menus based on enum values.

ExConsoleClearLines

Provides extension methods for ExConsole for clearing specific console lines.

ExConsoleMenu

Provides extension methods for ExConsole to support simple menus.

+
+

ExConsoleMultipleSelectMenu

+

Provides extension methods for ExConsole to support multiple select menus.

ExConsoleRead

Provides extension methods for ExConsole for easy reading and parsing inputs from the user.

+
+

MenuDisplayArgs

+

Stores display arguments for menu.

+
+

MultipleSelectDisplayArgs

+

Stores display arguments for multiple select menu.

@@ -107,7 +119,8 @@

ExConsoleRead< diff --git a/docs/api/index.html b/docs/api/index.html index 9a3adc6..09085a4 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -5,10 +5,10 @@ - ExtendedConsole documentation + PLACEHOLDER - - + + @@ -66,23 +66,11 @@
-
-

ExtendedConsole

-

The ExtendedConsole project is devided into a few classes, each responsible for certain features.

-

- The main public class is ExConsole.
- This class supports writing markup text to the Console. -

-

- Other public classes are extention classes built to extend the `ExConsole` features:

+

+

PLACEHOLDER

- The ExConsoleRead class provides extension methods to read and parse user input.
- - The ExConsoleClearLines class provides extension methods to clear specific lines on the Console.
- - The ExConsoleMenu class provides extension methods to create and execute menues.
-

-
+

TODO: Add .NET projects to the src folder and run docfx to generate REAL API Documentation!

+
diff --git a/docs/api/toc.html b/docs/api/toc.html index e52f7df..d00292b 100644 --- a/docs/api/toc.html +++ b/docs/api/toc.html @@ -20,15 +20,27 @@
  • ExConsole
  • +
  • + ExConsoleChooseFromEnum +
  • ExConsoleClearLines
  • ExConsoleMenu
  • +
  • + ExConsoleMultipleSelectMenu +
  • ExConsoleRead
  • +
  • + MenuDisplayArgs +
  • +
  • + MultipleSelectDisplayArgs +