Skip to content

Commit

Permalink
Initial Render table
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cerqueira committed Sep 21, 2023
1 parent 82856e5 commit 3a34066
Show file tree
Hide file tree
Showing 9 changed files with 623 additions and 116 deletions.
9 changes: 6 additions & 3 deletions Samples/TableBasicSamples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Globalization;
using System.IO.Pipes;
using PPlus;
using PPlus.Controls;
using static System.Net.Mime.MediaTypeNames;

namespace TableBasicSamples
Expand Down Expand Up @@ -32,10 +33,12 @@ static MyTable[] CreateItem()
PromptPlus.Config.DefaultCulture = new CultureInfo("en-us");

PromptPlus.Table<MyTable>()
.Title("Test",titleMode:TableTitleMode.InRow)
.WithSeparatorRows()
.AddItems(CreateItem())
.AddColumn((item) => item.Id, 10, null)
.AddColumn((item) => item.MyDate, 15, null)
.AddColumn((item) => item.MyText, 20, null,format:(arg) => $"Text: {arg}")
.AddColumn((item) => item.Id, 10)
.AddColumn((item) => item.MyDate, 15)
.AddColumn((item) => item.MyText, 20, format:(arg) => $"Text: {arg}")
.AddFormatType<DateTime>(FmtDate)
.AddFormatType<int>(FmtInt)
.EnabledInteractionUser(
Expand Down
34 changes: 17 additions & 17 deletions Src/Controls/Table/IControlTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
IControlTable<T> FilterByColumns(params byte[] indexColumn);

/// <summary>
/// The Table layout. Default value is 'TableLayout.SingleBorde'
/// The Table layout. Default value is 'TableLayout.SingleGridFull'
/// </summary>
/// <param name="value">The <see cref="TableLayout"/></param>
/// <returns><see cref="IControlTable{T}"/></returns>
Expand All @@ -151,29 +151,23 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
/// </summary>
/// <param name="value">Title</param>
/// <param name="alignment">alignment title</param>
/// <param name="tableTitleMode">InLine: Write the title above the grid. InRow : Write the title inside the grid as a row</param>
/// <param name="titleMode">InLine: Write the title above the grid. InRow : Write the title inside the grid as a row</param>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> Title(string value, Alignment alignment = Alignment.Center, TableTitleMode tableTitleMode = TableTitleMode.InLine);
IControlTable<T> Title(string value, Alignment alignment = Alignment.Center, TableTitleMode titleMode = TableTitleMode.InLine);

/// <summary>
/// Add Column
/// </summary>
/// <param name="field">Expression that defines the field associated with the column</param>
/// <param name="minwidth">Minimum column width</param>
/// <param name="maxwidth">Maximum column width</param>
/// <param name="width">column width</param>
/// <param name="format">Function to format the field.If not informed, it will be ToString()</param>
/// <param name="alignment">alignment content</param>
/// <param name="title">The Column title</param>
/// <param name="titlealignment">alignment title</param>
/// <param name="titlereplaceswidth">title width overrides column width when greater</param>
/// <param name="textcrop">If true the value will be truncated by the maximum size, otherwise an extra new line will be created</param>
/// <param name="format">Function to format the field.If not informed, it will be ToString()</param>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> AddColumn(Expression<Func<T, object>> field, byte minwidth, byte? maxwidth, Alignment alignment = Alignment.Left, bool textcrop = false, Func<object, string> format = null);

/// <summary>
/// Add Column Title
/// </summary>
/// <param name="value">The Column title</param>
/// <param name="alignment">alignment title</param>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> AddColumnTitle(string value, Alignment alignment = Alignment.Center);
IControlTable<T> AddColumn(Expression < Func<T, object>> field, byte width, Func<object, string> format = null,Alignment alignment = Alignment.Left, string? title = null, Alignment titlealignment = Alignment.Center,bool titlereplaceswidth = true, bool textcrop = false);

/// <summary>
/// Add extra row with merger columns
Expand All @@ -183,13 +177,19 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
/// <param name="startColumn">start column</param>
/// <param name="endcolumn">Final column</param>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> MergeColumnTitle(string value, byte startColumn, byte endcolumn, Alignment alignment = Alignment.Center);
IControlTable<T> MergeColumns(string value, byte startColumn, byte endcolumn, Alignment alignment = Alignment.Center);

/// <summary>
/// Set separator between rows. Default none.
/// </summary>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> SeparatorRows();
IControlTable<T> WithSeparatorRows();

/// <summary>
/// Hide columns headers. Default false.
/// </summary>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> HideHeaders();

/// <summary>
/// Set the grid to have the current console width
Expand Down
7 changes: 4 additions & 3 deletions Src/Controls/Table/ItemTableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ namespace PPlus.Controls
internal struct ItemItemColumn<T>
{
public Func<T, object> Field { get; set; }
public Alignment Align { get; set; }
public byte MinWidth { get; set; }
public byte MaxWidth { get; set; }
public Alignment AlignCol { get; set; }
public byte Width { get; set; }
public bool TextCrop { get; set; }
public Func<object, string>? Format { get; set; }
public string Title { get; set; }
public Alignment AlignTitle { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@

namespace PPlus.Controls
{
internal readonly struct ItemTableHeader
internal readonly struct ItemTableMergeHeader
{
public ItemTableHeader()
public ItemTableMergeHeader()
{
throw new PromptPlusException("ItemHeader CTOR NotImplemented");
throw new PromptPlusException("ItemTableMergeHeader CTOR NotImplemented");
}

public ItemTableHeader(string header, Alignment align)
{
Header = header;
Align = align;
StartColumn = 0;
EndColumn = 0;
}

public ItemTableHeader(string header, Alignment align, byte start,byte end)
public ItemTableMergeHeader(string header, Alignment align, byte start,byte end)
{
Header = header;
Align = align;
Expand Down
Loading

0 comments on commit 3a34066

Please sign in to comment.