mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Use Wcwidth library
This commit is contained in:

committed by
Patrik Svensson

parent
df291ef84e
commit
090b30f731
@ -83,7 +83,7 @@ namespace Spectre.Console
|
||||
}
|
||||
|
||||
// Missing space on right side?
|
||||
var lineWidth = line.CellWidth(context.Encoding);
|
||||
var lineWidth = line.CellWidth(context);
|
||||
var diff = width - lineWidth - Padding.Left - Padding.Right;
|
||||
if (diff > 0)
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ namespace Spectre.Console
|
||||
content.AddRange(line);
|
||||
|
||||
// Do we need to pad the panel?
|
||||
var length = line.Sum(segment => segment.CellLength(context.Encoding));
|
||||
var length = line.Sum(segment => segment.CellLength(context));
|
||||
if (length < childWidth)
|
||||
{
|
||||
var diff = childWidth - length;
|
||||
@ -138,9 +138,9 @@ namespace Spectre.Console
|
||||
var rightSpacing = 0;
|
||||
|
||||
var headerWidth = panelWidth - (EdgeWidth * 2);
|
||||
var header = Segment.TruncateWithEllipsis(Header.Text, Header.Style ?? borderStyle, context.Encoding, headerWidth);
|
||||
var header = Segment.TruncateWithEllipsis(Header.Text, Header.Style ?? borderStyle, context, headerWidth);
|
||||
|
||||
var excessWidth = headerWidth - header.CellLength(context.Encoding);
|
||||
var excessWidth = headerWidth - header.CellLength(context);
|
||||
if (excessWidth > 0)
|
||||
{
|
||||
switch (Header.Alignment ?? Justify.Left)
|
||||
|
@ -119,8 +119,8 @@ namespace Spectre.Console
|
||||
return new Measurement(0, 0);
|
||||
}
|
||||
|
||||
var min = _lines.Max(line => line.Max(segment => segment.CellLength(context.Encoding)));
|
||||
var max = _lines.Max(x => x.CellWidth(context.Encoding));
|
||||
var min = _lines.Max(line => line.Max(segment => segment.CellLength(context)));
|
||||
var max = _lines.Max(x => x.CellWidth(context));
|
||||
|
||||
return new Measurement(min, Math.Min(max, maxWidth));
|
||||
}
|
||||
@ -144,7 +144,7 @@ namespace Spectre.Console
|
||||
var justification = context.Justification ?? Alignment ?? Justify.Left;
|
||||
foreach (var (_, _, last, line) in lines.Enumerate())
|
||||
{
|
||||
var length = line.Sum(l => l.StripLineEndings().CellLength(context.Encoding));
|
||||
var length = line.Sum(l => l.StripLineEndings().CellLength(context));
|
||||
if (length < maxWidth)
|
||||
{
|
||||
// Justify right side
|
||||
@ -193,7 +193,7 @@ namespace Spectre.Console
|
||||
|
||||
private List<SegmentLine> SplitLines(RenderContext context, int maxWidth)
|
||||
{
|
||||
if (_lines.Max(x => x.CellWidth(context.Encoding)) <= maxWidth)
|
||||
if (_lines.Max(x => x.CellWidth(context)) <= maxWidth)
|
||||
{
|
||||
return Clone();
|
||||
}
|
||||
@ -244,15 +244,15 @@ namespace Spectre.Console
|
||||
continue;
|
||||
}
|
||||
|
||||
var length = current.CellLength(context.Encoding);
|
||||
var length = current.CellLength(context);
|
||||
if (length > maxWidth)
|
||||
{
|
||||
// The current segment is longer than the width of the console,
|
||||
// so we will need to crop it up, into new segments.
|
||||
var segments = Segment.SplitOverflow(current, Overflow, context.Encoding, maxWidth);
|
||||
var segments = Segment.SplitOverflow(current, Overflow, context, maxWidth);
|
||||
if (segments.Count > 0)
|
||||
{
|
||||
if (line.CellWidth(context.Encoding) + segments[0].CellLength(context.Encoding) > maxWidth)
|
||||
if (line.CellWidth(context) + segments[0].CellLength(context) > maxWidth)
|
||||
{
|
||||
lines.Add(line);
|
||||
line = new SegmentLine();
|
||||
@ -272,7 +272,7 @@ namespace Spectre.Console
|
||||
}
|
||||
else
|
||||
{
|
||||
if (line.CellWidth(context.Encoding) + length > maxWidth)
|
||||
if (line.CellWidth(context) + length > maxWidth)
|
||||
{
|
||||
line.Add(Segment.Empty);
|
||||
lines.Add(line);
|
||||
|
@ -250,7 +250,7 @@ namespace Spectre.Console
|
||||
result.AddRange(cell[cellRowIndex]);
|
||||
|
||||
// Pad cell content right
|
||||
var length = cell[cellRowIndex].Sum(segment => segment.CellLength(context.Encoding));
|
||||
var length = cell[cellRowIndex].Sum(segment => segment.CellLength(context));
|
||||
if (length < columnWidths[cellIndex])
|
||||
{
|
||||
result.Add(new Segment(new string(' ', columnWidths[cellIndex] - length)));
|
||||
|
Reference in New Issue
Block a user