Do not include cell separators in grid

Closes #40
This commit is contained in:
Patrik Svensson
2020-08-11 11:45:05 +02:00
committed by Patrik Svensson
parent 22d4af4482
commit 9aa36c4cf0
5 changed files with 45 additions and 13 deletions

View File

@ -21,6 +21,7 @@ namespace Spectre.Console
Border = BorderKind.None,
ShowHeaders = false,
IsGrid = true,
PadRightCell = false,
};
}
@ -55,11 +56,14 @@ namespace Spectre.Console
throw new ArgumentNullException(nameof(column));
}
// Only pad the most right cell if we've explicitly set a padding.
_table.PadRightCell = column.Padding != null;
_table.AddColumn(new TableColumn(string.Empty)
{
Width = column.Width,
NoWrap = column.NoWrap,
Padding = column.Padding,
Padding = column.Padding ?? new Padding(0, 2),
Alignment = column.Alignment,
});
}

View File

@ -20,7 +20,7 @@ namespace Spectre.Console
/// <summary>
/// Gets or sets the padding of the column.
/// </summary>
public Padding Padding { get; set; } = new Padding(0, 1);
public Padding? Padding { get; set; } = null;
/// <summary>
/// Gets or sets the alignment of the column.

View File

@ -53,8 +53,14 @@ namespace Spectre.Console
/// </summary>
public bool SafeBorder { get; set; } = true;
// Whether this is a grid or not.
internal bool IsGrid { get; set; } = false;
// Whether or not the most right cell should be padded.
// This is almost always the case, unless we're rendering
// a grid without explicit padding in the last cell.
internal bool PadRightCell { get; set; } = true;
/// <summary>
/// Initializes a new instance of the <see cref="Table"/> class.
/// </summary>
@ -279,7 +285,7 @@ namespace Spectre.Console
}
// Pad column on the right side
if (showBorder || (hideBorder && !lastCell) || (IsGrid && !lastCell))
if (showBorder || (hideBorder && !lastCell) || (hideBorder && lastCell && IsGrid && PadRightCell))
{
var rightPadding = _columns[cellIndex].Padding.Right;
if (rightPadding > 0)
@ -293,7 +299,7 @@ namespace Spectre.Console
// Add right column edge
result.Add(new Segment(border.GetPart(BorderPart.CellRight)));
}
else if (showBorder || (hideBorder && !lastCell))
else if (showBorder)
{
// Add column separator
result.Add(new Segment(border.GetPart(BorderPart.CellSeparator)));