29 using System.Collections.Generic;
33 namespace OpenSim.Framework.Console
46 public const int DefaultTableSpacing = 2;
51 public List<ConsoleDisplayTableColumn> Columns {
get;
private set; }
56 public List<ConsoleDisplayTableRow> Rows {
get;
private set; }
61 public int Indent {
get; set; }
66 public int TableSpacing {
get; set; }
70 TableSpacing = DefaultTableSpacing;
71 Columns =
new List<ConsoleDisplayTableColumn>();
72 Rows =
new List<ConsoleDisplayTableRow>();
77 StringBuilder sb =
new StringBuilder();
78 AddToStringBuilder(sb);
87 public void AddRow(params
object[] cells)
94 string formatString = GetFormatString();
98 sb.AppendFormat(formatString, Columns.ConvertAll(c => c.Header).ToArray());
102 sb.AppendFormat(formatString, row.Cells.ToArray());
108 private string GetFormatString()
110 StringBuilder formatSb =
new StringBuilder();
112 formatSb.Append(
' ', Indent);
114 for (
int i = 0; i < Columns.Count; i++)
117 formatSb.Append(
' ', TableSpacing);
120 formatSb.AppendFormat(
"{{{0},-{1}}}", i, Columns[i].Width);
123 formatSb.Append(
'\n');
125 return formatSb.ToString();
131 public string Header {
get; set; }
132 public int Width {
get; set; }
143 public List<object> Cells {
get;
private set; }
152 Cells =
new List<object>(cells);
ConsoleDisplayTableRow(List< object > cells)
Used to generated a formatted table for the console.
void AddRow(params object[] cells)
override string ToString()
void AddColumn(string name, int width)
void AddToStringBuilder(StringBuilder sb)
ConsoleDisplayTableColumn(string header, int width)
ConsoleDisplayTableRow(params object[] cells)