public void Write(ObjectWriteContext context) { foreach (var item in Items) { context.Write("- "); context.Write(item); context.NewLine(); } }
public void WriteVerticalBorder(ObjectWriteContext context, int paddingLeft, int paddingRight) { if (paddingLeft > 0) { context.Write(new string(' ', paddingLeft)); } if (Bordered) { context.Write("|"); } if (paddingRight > 0) { context.Write(new string(' ', paddingRight)); } }
private void WriteHorizontalBorder(ObjectWriteContext context, int contentLength) { if (Bordered) { if (Margin.Left > 0) { context.Write(new string(' ', Margin.Left)); } context.Write("+"); context.Write(new string('-', contentLength + Padding.Left + Padding.Right)); context.Write("+"); if (Margin.Right > 0) { context.Write(new string(' ', Margin.Right)); } } }
public void Write(ObjectWriteContext context) { var properties = ModelType.GetProperties(); var longestPropertyName = properties.Max(p => p.Name.Length); foreach (var property in properties) { context.Write($"{property.Name.PadRight(longestPropertyName)} : "); context.WriteObject(property.GetValue(Model)); context.NewLine(); } }
private void WriteTopCap(ObjectWriteContext context, int longestLineLength) { for (var i = 0; i < Margin.Top; i++) { context.NewLine(); } WriteHorizontalBorder(context, longestLineLength); for (var i = 0; i < Padding.Top; i++) { context.NewLine(); WriteVerticalBorder(context, Margin.Left, Padding.Left); context.Write(new string(' ', longestLineLength)); WriteVerticalBorder(context, Padding.Right, Margin.Right); } }
private void WriteBottomCap(ObjectWriteContext context, int contentLength) { for (var i = 0; i < Padding.Bottom; i++) { WriteVerticalBorder(context, Margin.Left, Padding.Left); context.Write(new string(' ', contentLength)); WriteVerticalBorder(context, Padding.Right, Margin.Right); context.NewLine(); } WriteHorizontalBorder(context, contentLength); for (var i = 0; i < Margin.Bottom; i++) { context.NewLine(); } }
public void Write(ObjectWriteContext context) { var buildScrawler = new ProxyScrawler(); var proxiedContext = context.CreateSubContext(buildScrawler); var isTerminated = false; var isLineTerminator = false; var terminatorChars = proxiedContext.LineTerminator.ToCharArray(); var lineList = new LineList(32); string currentLine = string.Empty; // Setup on write method for the proxy. buildScrawler.OnWrite(s => { var len = s.Length; if (len == 0) { return; } isLineTerminator = s.Equals(proxiedContext.LineTerminator, StringComparison.Ordinal); if (isLineTerminator) { lineList.AddLine(currentLine); currentLine = string.Empty; return; } isTerminated = isLineTerminator || s.EndsWith(proxiedContext.LineTerminator); if (isTerminated) { lineList.AddLine(currentLine.TrimEnd(terminatorChars)); currentLine = string.Empty; return; } currentLine += s; }); // Write to the proxied context. InnerComponent.Write(proxiedContext); // Make all lines into a "block". // | abc abc abc | // | abc abc | // | abc ab abc | lineList.RightPad(lineList.LongestLineLength); // Write top border WriteTopCap(context, lineList.LongestLineLength); context.NewLine(); foreach (var line in lineList) { WriteVerticalBorder(context, Margin.Left, Padding.Left); context.Write(line); WriteVerticalBorder(context, Padding.Right, Margin.Right); context.NewLine(); } WriteBottomCap(context, lineList.LongestLineLength); context.NewLine(); }