Skip to content

Commit

Permalink
Fixed improvements: #72 and #74
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cerqueira committed Oct 9, 2023
1 parent 3de47f6 commit ffaa648
Show file tree
Hide file tree
Showing 21 changed files with 555 additions and 242 deletions.
22 changes: 13 additions & 9 deletions Samples/ConsoleFeaturesSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@ static void Main()

//global
PromptPlus.Config.EnabledAbortKey = false;
PromptPlus.Config.PageSize = 5;
PromptPlus.StyleSchema.ApplyStyle(StyleControls.Prompt, new Style(Color.Red));
//by instance
PromptPlus.Input("").Config(cfg =>
{
cfg
.ApplyStyle(StyleControls.Answer, new Style(Color.Yellow))
.ApplyStyle(StyleControls.Prompt, new Style(Color.Yellow))
.EnabledAbortKey(true);
});

PromptPlus.WriteLine("[RED ON WHITE]Hello[/] [YELLOW]Word[/]");

PromptPlus.WriteLine("[RGB(255,0,0) ON WHITE]Test[YELLOW] COLOR [/] BACK COLOR [/] other text");

PromptPlus.AppendText("[RGB(255,0,0) ON WHITE]Test[/]")
.And(" COLOR ",Color.Yellow)
.And(" BACK COLOR ",new Style(Color.Red,Color.White))
.And("other text")
.WriteLine();
PromptPlus.Join()
.DoubleDash($"PromptPlus Join")
.Write("[RGB(255,0,0) ON WHITE]Test[/]")
.Write(" COLOR ",Style.Default.Foreground(Color.Yellow))
.Write(" BACK COLOR ",new Style(Color.Red,Color.White))
.Write("other text")
.WriteLine()
.CountLines();

//standard
PromptPlus.DoubleDash($"PromptPlus IgnoreColorTokens = false - Default value and usage" );
Expand Down Expand Up @@ -104,7 +106,7 @@ static void Main()
cfg.PadRight = 2;
});

PromptPlus.BackgroundColor = ConsoleColor.Blue;
//PromptPlus.BackgroundColor = ConsoleColor.Blue;
PromptPlus.Clear();

PromptPlus.SingleDash($"[yellow]Console Information[/]", DashOptions.DoubleBorder, 1 /*extra lines*/);
Expand All @@ -131,6 +133,8 @@ static void Main()
.Spinner(SpinnersType.Balloon)
.Run();

PromptPlus.BackgroundColor = ConsoleColor.Black;

PromptPlus.Clear();


Expand Down
2 changes: 1 addition & 1 deletion Samples/MaskEditDateTimeTypeSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void Main(string[] args)
PromptPlus.MaskEdit("input", "MaskEdit DateTime input")
.Mask(MaskedType.DateTime)
.DescriptionWithInputType(FormatWeek.Long)
.Culture(new CultureInfo("pt-br"))
.Culture("pt-br")
.AcceptEmptyValue()
.Run();

Expand Down
1 change: 1 addition & 0 deletions Samples/MaskEditNumberTypeSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static void Main(string[] args)

PromptPlus.MaskEdit("input", "MaskEdit Number input")
.Mask(MaskedType.Number)
.Culture("pt-br")
.AmmoutPositions(10, 2, true)
.PositiveStyle(Style.Default.Foreground(Color.Green))
.NegativeStyle(Style.Default.Foreground(Color.IndianRed))
Expand Down
4 changes: 2 additions & 2 deletions Samples/SelectUserScopeSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ static void Main()
PromptPlus.DoubleDash("Control:Select - Using class with AdderScope and OrderBy");
var sel = PromptPlus.Select<MyClass>("Select")
.AddItems(_datasample)
.AddItemsTo(AdderScope.Disable, _datasample.Where(x => x.IsDisabled).ToArray())
.AddItemsTo(AdderScope.Remove, _datasample.Where(x => x.IsHide).ToArray())
.AddItemsTo(AdderScope.Disable, _datasample.Where(x => x.IsDisabled))
.AddItemsTo(AdderScope.Remove, _datasample.Where(x => x.IsHide))
.TextSelector(x => x.MyText)
.EqualItems((item1, item2) => item1.Id == item2.Id)
.ChangeDescription(x => x.MyDesc)
Expand Down
2 changes: 1 addition & 1 deletion Src/Controls/IPromptConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace PPlus.Controls
{
/// <summary>
/// Interface for config controls and overwrite default values
/// Interface for config controls to overwrite default values
/// </summary>
public interface IPromptConfig
{
Expand Down
11 changes: 11 additions & 0 deletions Src/Controls/SelectColletion/IControlMultiSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ***************************************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;

Expand Down Expand Up @@ -173,6 +174,16 @@ public interface IControlMultiSelect<T> : IPromptControls<IEnumerable<T>>
/// <returns><see cref="IControlMultiSelect{T}"/></returns>
IControlMultiSelect<T> AddItemsTo(AdderScope scope, params T[] values);

/// <summary>
/// Add Items colletion to scope Disable/Remove <seealso cref="AdderScope"/>
/// <br>At startup the list items will be compared and will be removed or disabled <see cref="AdderScope"/></br>
/// <br>Tip: Use <seealso cref="EqualItems"/> for custom comparer</br>
/// </summary>
/// <param name="scope">scope Disable/Remove</param>
/// <param name="values">items colletion</param>
/// <returns><see cref="IControlMultiSelect{T}"/></returns>
IControlMultiSelect<T> AddItemsTo(AdderScope scope, IEnumerable<T> values);

/// <summary>
/// Custom item comparator
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Src/Controls/SelectColletion/IControlSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ***************************************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;

Expand Down Expand Up @@ -135,6 +136,16 @@ public interface IControlSelect<T> : IPromptControls<T>
/// <returns><see cref="IControlSelect{T}"/></returns>
IControlSelect<T> AddItemsTo(AdderScope scope, params T[] values);

/// <summary>
/// Add Items colletion to scope Disable/Remove <seealso cref="AdderScope"/>
/// <br>At startup the list items will be compared and will be removed or disabled <see cref="AdderScope"/></br>
/// <br>Tip: Use <seealso cref="EqualItems"/> for custom comparer</br>
/// </summary>
/// <param name="scope">scope Disable/Remove</param>
/// <param name="values">items colletion</param>
/// <returns><see cref="IControlSelect{T}"/></returns>
IControlSelect<T> AddItemsTo(AdderScope scope, IEnumerable<T> values);

/// <summary>
/// Add Item in a group to list
/// <br>AddItemGrouped cannot be used with OrderBy/OrderByDescending</br>
Expand Down
13 changes: 12 additions & 1 deletion Src/Controls/SelectColletion/MultiSelectControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,18 @@ public IControlMultiSelect<T> AddItemsGrouped(string group, IEnumerable<T> value
}

public IControlMultiSelect<T> AddItemsTo(AdderScope scope,params T[] values)
{
InternalAdd(scope, values);
return this;
}

public IControlMultiSelect<T> AddItemsTo(AdderScope scope, IEnumerable<T> values)
{
InternalAdd(scope, values);
return this;
}

private void InternalAdd(AdderScope scope, IEnumerable<T> values)
{
foreach (var item in values)
{
Expand All @@ -396,7 +408,6 @@ public IControlMultiSelect<T> AddItemsTo(AdderScope scope,params T[] values)
throw new PromptPlusException($"AdderScope : {scope} Not Implemented");
}
}
return this;
}

public IControlMultiSelect<T> OverflowAnswer(Overflow value)
Expand Down
14 changes: 13 additions & 1 deletion Src/Controls/SelectColletion/SelectControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,20 @@ public IControlSelect<T> AddItems(IEnumerable<T> value, bool disable = false)
return this;
}

public IControlSelect<T> AddItemsTo(AdderScope scope, IEnumerable<T> values)
{
InternalAdd(scope, values);
return this;
}


public IControlSelect<T> AddItemsTo(AdderScope scope,params T[] values)
{
InternalAdd(scope,values);
return this;
}

private void InternalAdd(AdderScope scope, IEnumerable<T> values)
{
foreach (var item in values)
{
Expand All @@ -207,7 +220,6 @@ public IControlSelect<T> AddItemsTo(AdderScope scope,params T[] values)
throw new PromptPlusException($"AddItemsTo : {scope} Not Implemented");
}
}
return this;
}

public IControlSelect<T> AutoSelect(bool value = true)
Expand Down
70 changes: 0 additions & 70 deletions Src/Drivers/AppendTextControl.cs

This file was deleted.

54 changes: 13 additions & 41 deletions Src/Drivers/DriveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ static PromptPlus()
}
else
{
OriginalCodePageEncode = System.Console.OutputEncoding;
OriginalCodePageEncode = Console.OutputEncoding;
var (codepagefrom, codepageto) = ConvertCodePage;

if (System.Console.OutputEncoding.CodePage.ToString() == codepageto)
if (Console.OutputEncoding.CodePage.ToString() == codepageto)
{
unicodesupported = true;
}

else if (System.Console.OutputEncoding.CodePage.ToString() == codepagefrom)
else if (Console.OutputEncoding.CodePage.ToString() == codepagefrom)
{
System.Console.OutputEncoding = Encoding.GetEncoding(int.Parse(codepageto));
Console.OutputEncoding = Encoding.GetEncoding(int.Parse(codepageto));
unicodesupported = true;
}
else if (System.Console.OutputEncoding.Equals(Encoding.Unicode))
else if (Console.OutputEncoding.Equals(Encoding.Unicode))
{
unicodesupported = true;
}
else if (System.Console.OutputEncoding.Equals(Encoding.BigEndianUnicode))
else if (Console.OutputEncoding.Equals(Encoding.BigEndianUnicode))
{
unicodesupported = true;
}
else if (System.Console.OutputEncoding.Equals(Encoding.UTF32))
else if (Console.OutputEncoding.Equals(Encoding.UTF32))
{
unicodesupported = true;
}
Expand All @@ -91,46 +91,18 @@ private static void CurrentDomain_ProcessExit(object? sender, EventArgs e)
Thread.CurrentThread.CurrentCulture = AppConsoleCulture;
if (!IsRunningInUnitTest)
{
System.Console.OutputEncoding = OriginalCodePageEncode;
Console.OutputEncoding = OriginalCodePageEncode;
}
ResetColor();
}

/// <summary>
/// Add text to the recording buffer
/// Start Join Commands
/// </summary>
/// <param name="text">Text to write</param>
/// <returns><see cref="IAppendText"/></returns>
public static IAppendText AppendText(string text)
/// <returns><see cref="IJointConsole"/></returns>
public static IJointConsole Join()
{
var ctrl = new AppendTextControl();
ctrl.And(text);
return ctrl;
}

/// <summary>
/// Add text to the recording buffer with <see cref="Style"/>
/// </summary>
/// <param name="text">Text to write</param>
/// <param name="style">The <see cref="Style"/></param>
/// <returns><see cref="IAppendText"/></returns>
public static IAppendText AppendText(string text, Style style)
{
var ctrl = new AppendTextControl();
ctrl.And(text, style);
return ctrl;
}

/// <summary>
/// Add text to the recording buffer with forecolor <see cref="Color"/>
/// </summary>
/// <param name="text">Text to write</param>
/// <param name="color">The forecolor. <see cref="Color"/></param>
/// <returns><see cref="IAppendText"/></returns>
public static IAppendText AppendText(string text, Color color)
{
var ctrl = new AppendTextControl();
ctrl.And(text, color);
var ctrl = new JoinConsoleControl();
return ctrl;
}

Expand Down Expand Up @@ -246,7 +218,7 @@ internal static bool IsControlText
/// </summary>
/// <param name="forecorlor">The <see cref="Color"/> ForegroundColor</param>
/// <param name="background">The <see cref="Color"/> BackgroundColor</param>
public static void ConsoleDefaultColor(Color forecorlor, Color background)
public static void DefaultColor(Color forecorlor, Color background)
{
_consoledrive.ForegroundColor = forecorlor;
_consoledrive.BackgroundColor = background;
Expand Down
Loading

0 comments on commit ffaa648

Please sign in to comment.