Skip to content

Commit

Permalink
Version 1.1.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Peled-Zohar committed May 17, 2021
1 parent 15accce commit 97b572b
Show file tree
Hide file tree
Showing 65 changed files with 5,500 additions and 1,192 deletions.
32 changes: 19 additions & 13 deletions ExtendedConsole/ExConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,44 @@ public class ExConsole
/// </summary>
/// <param name="markup">Markup text to write.</param>
/// <exception cref="System.Xml.XmlException">Thrown when markup text isn't properly formatted xml.</exception>
/// <returns>The current instance of <see cref="ExConsole"/>.</returns>
/// <example>
/// Write "Hello World!", cyan on a dark gray background.
/// <code>
/// exConsole.Write("&lt;c f='cyan' b='darkgray'&gt;Hello World!&lt;c&gt;");
/// </code>
/// </example>
public void Write(string markup)
public ExConsole Write(string markup)
{
Parser.ParseMarkeup(markup).Write();
return this;
}

/// <summary>
/// Writes the specified markup to the console, advances the cursor to the next line.
/// </summary>
/// <param name="markup">Markup text to write.</param>
/// <exception cref="System.Xml.XmlException">Thrown when markup text isn't properly formatted xml.</exception>
/// <returns>The current instance of <see cref="ExConsole"/>.</returns>
/// <example>
/// Write "Hello World!", black on a white background,
/// and advance the cursor to the next line.
/// <code>
/// exConsole.WriteLine("&lt;c b='white' f='black'&gt;Hello World!&lt;c&gt;");
/// </code>
/// </example>
public void WriteLine(string markup)
public ExConsole WriteLine(string markup)
{
Parser.ParseMarkeup(markup).WriteLine();
return this;
}

/// <summary>
/// Writes multiple markup lines to the console.
/// </summary>
/// <param name="lines">Lines of markup text to write.</param>
/// <exception cref="System.Xml.XmlException">Thrown when markup text isn't properly formatted xml.</exception>
/// <returns>The current instance of <see cref="ExConsole"/>.</returns>
/// <example>
/// Write "Hello World!" in yellow,
/// "This is exConsole writing multiple markup lines" in the next line, with exConsole in green, and
Expand All @@ -71,12 +76,13 @@ public void WriteLine(string markup)
/// );
/// </code>
/// </example>
public void WriteLines(params string[] lines)
public ExConsole WriteLines(params string[] lines)
{
foreach(var line in lines)
{
WriteLine(line);
}
return this;
}

/// <summary>
Expand All @@ -87,16 +93,15 @@ public void WriteLines(params string[] lines)
/// <param name="foregroundColor">Foreground color.</param>
/// <param name="backgroundColor">Background color.</param>
/// <exception cref="System.Xml.XmlException">Thrown when markup text isn't properly formatted xml.</exception>
/// <returns>The current instance of <see cref="ExConsole"/>.</returns>
/// <example>
/// Write "Hello World!" in magenta, followed by "How are you?" in black on a white background. Advance the cursor to the next line.
/// <code>
/// exConsole.WriteLine("Hello world! &lt;c b='white' f='black'&gt;How are you?&lt;c&gt;", ConsoleColor.Magenta, null);
/// </code>
/// </example>
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);

/// <summary>
/// Changes console colors to the specified colors, and writes the specified markup to the console.
Expand All @@ -105,17 +110,15 @@ public void WriteLine(string markup, ConsoleColor? foregroundColor, ConsoleColor
/// <param name="foregroundColor">Foreground color.</param>
/// <param name="backgroundColor">Background color.</param>
/// <exception cref="System.Xml.XmlException">Thrown when markup text isn't properly formatted xml.</exception>
/// <returns>The current instance of <see cref="ExConsole"/>.</returns>
/// <example>
/// Write "Hello World!" in black on a magenta background, followed by "How are you?" in black on a white background.
/// <code>
/// exConsole.Write("Hello world! &lt;c b='white' f='black'&gt;How are you?&lt;c&gt;", ConsoleColor.Black, ConsoleColor.Magenta);
/// </code>
/// </example>
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);

// <summary>
// Writes the specified text with the specified colors,
Expand All @@ -125,7 +128,8 @@ public void Write(string markup, ConsoleColor? foregroundColor, ConsoleColor? ba
// <param name="foregroundColor">Foreground color.</param>
// <param name="backgroundColor">Background color.</param>
// <exception cref="System.Xml.XmlException">Thrown when markup text isn't properly formatted xml.</exception>
private void WriteInColor(Action action, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor)
// <returns>The current instance of<see cref= "ExConsole" />.</ returns >
private ExConsole WriteInColor(Action action, ConsoleColor? foregroundColor, ConsoleColor? backgroundColor)
{
var (Foreground, Background) = (Console.ForegroundColor, Console.BackgroundColor);
Console.ForegroundColor = foregroundColor ?? Foreground;
Expand All @@ -135,6 +139,8 @@ private void WriteInColor(Action action, ConsoleColor? foregroundColor, ConsoleC

Console.ForegroundColor = Foreground;
Console.BackgroundColor = Background;

return this;
}
}
}
Loading

0 comments on commit 97b572b

Please sign in to comment.