Skip to content

Commit

Permalink
Finalização do controle Table.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cerqueira committed Sep 27, 2023
1 parent c5c6a30 commit bbb53f9
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 115 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@
- [API Reference](https://fracerqueira.github.io/PromptPlus/apis/apis.html)

## What's new in the latest version
### V4.0.6
### V4.1.0
[**Top**](#table-of-contents)

- Bug fixed: grouped item ordering. The sort option will be ignored
- New Control : Table<T> , Display data in a grid-table
- Samples in project [Table Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/TableSamples)
- Improvement commands with default values ​​(all controls)
- - Bug fixed: grouped item ordering. The sort option will be ignored
- Bug fixed: 'AcceptInput' method causes failure by not allowing navigation keys to be selected.
- Affeted Controls : AddtoList/Input
- Improvement : Direct writes to standard error output stream
- New Commands : OutputError()
- Sample with commemts in project [ConsoleFeatures Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/ConsoleFeaturesSamples)
- Samples with commemts in project [ConsoleFeatures Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/ConsoleFeaturesSamples)
- New feature: Escaping format characters color
- Global property : IgnoreColorTokens
- New Commands : EscapeColorTokens()/AcceptColorTokens()
- Sample with commemts in project [ConsoleFeatures Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/ConsoleFeaturesSamples)
- Samples with commemts in project [ConsoleFeatures Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/ConsoleFeaturesSamples)
- New feature: Group items in the select control
- Sample with commemts in project [SelectBasic Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/SelectBasicSamples)
- Samples with commemts in project [SelectBasic Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/SelectBasicSamples)
- New feature: Add separator line in the select control
- Sample with commemts in project [SelectBasic Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/SelectBasicSamples)
- Samples with commemts in project [SelectBasic Samples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/SelectBasicSamples)

**Special thanks to [ividyon](https://github.com/ividyon) for suggesting improvements and actively participating in this release**

Expand Down
60 changes: 31 additions & 29 deletions Samples/TableBasicSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,39 @@ internal class MyTableManyCols
public string D31 { get; set; } = new string('x', 20);
}

static void Main()
internal static MyTable[] CreateItems(int max)
{
static MyTable[] CreateItems(int max)
var result = new List<MyTable>();
var flag = false;
result.Add(new MyTable { Id = 0, MyDate = DateTime.Now, MyText = $"Test0 linha1{Environment.NewLine}Test0 linha2", ComplexCol = new MyComplexCol("C0") });
for (int i = 1; i < max; i++)
{
var result = new List<MyTable>();
var flag = false;
result.Add(new MyTable { Id = 0, MyDate = DateTime.Now, MyText = $"Test0 linha1{Environment.NewLine}Test0 linha2", ComplexCol = new MyComplexCol("C0") });
for (int i = 1; i < max; i++)
flag = !flag;
if (flag)
{
flag = !flag;
if (flag)
{
result.Add(new MyTable { Id = i, MyText = $"Test{i}", ComplexCol = new MyComplexCol($"C{i}") });
}
else
{
result.Add(new MyTable { Id = i, MyDate = DateTime.Now.AddDays(i), MyText = $"Test{i} very very very very very very very very long" + new string('x',150), ComplexCol = new MyComplexCol($"C{i}") });
}
result.Add(new MyTable { Id = i, MyText = $"Test{i}", ComplexCol = new MyComplexCol($"C{i}") });
}
else
{
result.Add(new MyTable { Id = i, MyDate = DateTime.Now.AddDays(i), MyText = $"Test{i} very very very very very very very very very very very very very very very long", ComplexCol = new MyComplexCol($"C{i}") });
}
return result.ToArray();
}
return result.ToArray();
}

static void Main()
{

//Ensure ValueResult Culture for all controls
PromptPlus.Config.DefaultCulture = new CultureInfo("en-us");

var data = CreateItems(20);

PromptPlus.DoubleDash("Control:Table - Autofill UserInteraction basic usage");

var tbl = PromptPlus.Table<MyTable>("Your Prompt", "Descripion Table")
.AddItems(data)
.AutoFill()
.AutoFill(0,80)
.AddFormatType<DateTime>(FmtDate)
.UserInteraction(
selectedTemplate: (item, row, col) => $"Current ID : {item.Id}. [yellow]Current row {row}, Current col {col}[/]",
Expand All @@ -112,7 +114,7 @@ static MyTable[] CreateItems(int max)
{
ctrl.AddItem(new MyTableManyCols() { MyText = "x" });
})
.AutoFill(10)
.AutoFill()
.AddFormatType<DateTime>(FmtDate)
.UserInteraction(
selectedTemplate: (item, row, col) => $"Current ID : {item.Id}. [yellow]Current row {row}, Current col {col}[/]",
Expand All @@ -138,18 +140,17 @@ static MyTable[] CreateItems(int max)
.Title("Test", titleMode: TableTitleMode.InRow)
.AddItem(new MyTable { Id = data.Length, MyText = $"Test{data.Length} disabled", ComplexCol = new MyComplexCol($"C{data.Length}") }, true)
.AddItems(data)
.AutoFill(10)
.AddColumn(field: (item) => item.Id, width: 10)
.AddColumn(field: (item) => item.MyDate!, width: 15/*,alignment: Alignment.Center*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text: {arg}", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text1: {arg}", title: $"Mytext1", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text2: {arg}", title: $"Mytext2", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text3: {arg}", title: $"Mytext3", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text4: {arg}", title: $"Mytext4", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text5: {arg}", title: $"Mytext5", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text8: {arg}", title: $"Mytext8", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text9: {arg}", title: $"Mytext9", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text10: {arg}", title: $"Mytext10", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text: {arg}", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text1: {arg}", title: $"Mytext1", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text2: {arg}", title: $"Mytext2", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text3: {arg}", title: $"Mytext3", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text4: {arg}", title: $"Mytext4", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text5: {arg}", title: $"Mytext5", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text8: {arg}", title: $"Mytext8", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text9: {arg}", title: $"Mytext9", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text10: {arg}", title: $"Mytext10", maxslidinglines: 2/*, textcrop:true*/)
.AddColumn(field: (item) => item.ComplexCol, width: 20, format: (arg) => $"{((MyComplexCol)arg).Id}:{((MyComplexCol)arg).Name}")
.AddColumn(field: (item) => item.ComplexCol.Name, width: 10)
.AddFormatType<DateTime>(FmtDate)
Expand All @@ -170,6 +171,7 @@ static MyTable[] CreateItems(int max)
foreach (var iteml in typelayout)
{
var hideheaders = true;
//hideheaders (true/false)
for (int h = 0; h < 2; h++)
{
hideheaders = !hideheaders;
Expand All @@ -178,7 +180,7 @@ static MyTable[] CreateItems(int max)
for (int i = 0; i < 2; i++)
{
seprow = !seprow;
PromptPlus.DoubleDash($"Control:Table (Write only) - Autofill Write Table Layout({iteml}) , Title({itemt}) , sep.row({seprow}) hide headers({hideheaders})");
PromptPlus.DoubleDash($"Autofill Layout({iteml}), Title({itemt}), sep.row({seprow}), hide headers({hideheaders})",style: Style.Default.Foreground(Color.Yellow));
var lt = (TableLayout)Enum.Parse(typeof(TableLayout), iteml.ToString()!);
PromptPlus.Table<MyTable>("")
.Title("Test", Alignment.Center, tm)
Expand Down
3 changes: 3 additions & 0 deletions Src/Controls/Objects/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal static class Messages
{
public static void UpdateCulture()
{
TableMoveCols = PromptPlusResources.TableMoveCols;
MoveToday = PromptPlusResources.MoveToday;
MoveDays = PromptPlusResources.MoveDays;
MoveDayWeek = PromptPlusResources.MoveDayWeek;
Expand Down Expand Up @@ -104,6 +105,8 @@ public static void UpdateCulture()
Pressedkey = PromptPlusResources.PressedKey;
AnyKey = PromptPlusResources.AnyKey;
}

public static string TableMoveCols { get; private set; } = PromptPlusResources.TableMoveCols;
public static string MoveToday { get; private set; } = PromptPlusResources.MoveToday;
public static string MoveDays { get; private set; } = PromptPlusResources.MoveDays;
public static string MoveDayWeek { get; private set; } = PromptPlusResources.MoveDayWeek;
Expand Down
8 changes: 4 additions & 4 deletions Src/Controls/Table/IControlTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
/// <param name="textcrop">If true the value will be truncated by the column size, otherwise, the content will be written in several lines</param>
/// <param name="maxslidinglines">Maximum Sliding Lines when the content length is greater than the column size and textcrop = false.</param>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> AddColumn(Expression < Func<T, object>> field, ushort width, Func<object, string> format = null,Alignment alignment = Alignment.Left, string? title = null, Alignment titlealignment = Alignment.Center,bool titlereplaceswidth = true, bool textcrop = false, int? maxslidinglines = null);
IControlTable<T> AddColumn(Expression < Func<T, object>> field, ushort width, Func<object, string> format = null,Alignment alignment = Alignment.Left, string? title = null, Alignment titlealignment = Alignment.Center,bool titlereplaceswidth = true, bool textcrop = false, ushort? maxslidinglines = null);

/// <summary>
/// Auto generate Columns
Expand All @@ -165,11 +165,11 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
/// <br>The content alignment will always be 'Left' and will always be with sliding lines</br>
/// <br>Columns are generated by the public properties of the data class recognized by <see cref="TypeCode"/>.</br>
/// <br>TypeCode.DBNull and TypeCode.Object will be ignored.</br>
/// <br>The column size will be automatically adjusted by the title size (Name property) and the minwidth parameter or content width when minwidth is null</br>
/// <br>The column size will be automatically adjusted by the title size (Name property) and the minmaxwidth parameter or content width when min/max width is null</br>
/// </summary>
/// <param name="minwidth">Minimum column width</param>
/// <param name="minmaxwidth">minimum and maximum width</param>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> AutoFill(ushort? minwidth = null);
IControlTable<T> AutoFill(params ushort?[] minmaxwidth);

/// <summary>
/// Set separator between rows. Default false.
Expand Down
109 changes: 109 additions & 0 deletions Src/Controls/Table/ScreenBufferTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,114 @@ public static void WriteLineDescriptionTable<T>(this ScreenBuffer screenBuffer,T
screenBuffer.AddBuffer(result, options.OptStyleSchema.Description());
}
}

public static void WriteLineTooltipsTable<T>(this ScreenBuffer screenBuffer, TableOptions<T> options, bool isfiltering, bool ismovecol)
{
if (options.OptShowTooltip)
{
var tp = options.OptToolTip;
var swm = false;
if (string.IsNullOrEmpty(tp))
{
tp = DefaultToolTipSelect(options, isfiltering, ismovecol);
swm = true;
}
if (!string.IsNullOrEmpty(tp))
{
screenBuffer.NewLine();
screenBuffer.AddBuffer(tp, options.OptStyleSchema.Tooltips(), swm);
}
}
}

private static string DefaultToolTipSelect<T>(TableOptions<T> options, bool isfiltering, bool ismovecol)
{
if (options.OptEnabledAbortKey)
{
if (!isfiltering)
{
if (ismovecol)
{
return string.Format("{0}, {1}, {2}, {3}\n{4}, {5}",
string.Format(Messages.TooltipToggle, options.Config.TooltipKeyPress),
string.Format(Messages.TooltipCancelEsc, options.Config.AbortKeyPress),
Messages.SelectFinishEnter,
Messages.TooltipPages,
Messages.TooltipSelectFilter,
Messages.TableMoveCols);
}
else
{
return string.Format("{0}, {1}, {2}, {3}\n{4}",
string.Format(Messages.TooltipToggle, options.Config.TooltipKeyPress),
string.Format(Messages.TooltipCancelEsc, options.Config.AbortKeyPress),
Messages.SelectFinishEnter,
Messages.TooltipPages,
Messages.TooltipSelectFilter);
}
}
else
{
if (options.FilterType != FilterMode.Disabled)
{
return string.Format("{0}, {1}, {2}, {3}\n{4}",
string.Format(Messages.TooltipToggle, options.Config.TooltipKeyPress),
string.Format(Messages.TooltipCancelEsc, options.Config.AbortKeyPress),
Messages.SelectFinishEnter,
Messages.TooltipPages,
Messages.TooltipSelectFilter);
}
else
{
return string.Format("{0}, {1}, {2}, {3}",
string.Format(Messages.TooltipToggle, options.Config.TooltipKeyPress),
string.Format(Messages.TooltipCancelEsc, options.Config.AbortKeyPress),
Messages.SelectFinishEnter,
Messages.TooltipPages);
}
}
}
else
{
if (!isfiltering)
{
if (ismovecol)
{
return string.Format("{0}, {1}, {2}\n{3}, {4}",
string.Format(Messages.TooltipToggle, options.Config.TooltipKeyPress),
Messages.SelectFinishEnter,
Messages.TooltipPages,
Messages.TooltipSelectFilter,
Messages.TableMoveCols);
}
else
{
return string.Format("{0}, {1}\n{2}, {3}",
string.Format(Messages.TooltipToggle, options.Config.TooltipKeyPress),
Messages.SelectFinishEnter,
Messages.TooltipPages,
Messages.TooltipSelectFilter);
}
}
else
{
if (options.FilterType != FilterMode.Disabled)
{
return string.Format("{0}, {1}\n{2}, {3}",
string.Format(Messages.TooltipToggle, options.Config.TooltipKeyPress),
Messages.SelectFinishEnter,
Messages.TooltipPages,
Messages.TooltipSelectFilter);
}
else
{
return string.Format("{0}, {1}, {2}",
string.Format(Messages.TooltipToggle, options.Config.TooltipKeyPress),
Messages.SelectFinishEnter,
Messages.TooltipPages);
}
}
}
}
}
}
Loading

0 comments on commit bbb53f9

Please sign in to comment.