private void AutoFormatAllColumns(List <Row> prefetchRows, bool prefetchedAll) { int columnCount = columnDescriptors.Count; for (int i = 0; i < columnCount; ++i) { List <object> columnValues = new List <object>(prefetchRows.Count); foreach (Row row in prefetchRows) { object columnValue = row[i]; columnValues.Add(columnValue); } ColumnDescriptor columnDescriptor = this.columnDescriptors[i]; ColumnFormat columnFormat = columnDescriptor.Format; if (prefetchedAll && AreAllColumnValuesNull(columnValues)) { columnFormat.MaxWidth = ColumnFormat.NullText.Length; } else { columnFormat.AutoFormat(columnValues, prefetchedAll); } if (columnFormat.LimitWidthByUserOptions && columnFormat.MaxWidth > this.options.MaxResultColumnWidth) { columnFormat.MaxWidth = this.options.MaxResultColumnWidth; } if (columnFormat.MaxWidth < columnDescriptor.Name.Length) { columnFormat.MaxWidth = columnDescriptor.Name.Length; } } }
public ColumnDescriptor(int index, string name, Type type, int maxWidth) { this.index = index; this.name = name; this.type = type; if (maxWidth <= name.Length) { maxWidth = name.Length; } columnFormat = GetColumnFormat(type, maxWidth); }
public void TraceRow(TextWriter output, Row row) { int columnCount = row.Count; int maxLineCount = 0; int totalWidth = 0; // Split each column into several lines. List <string>[] allColumnLines = new List <string> [columnDescriptors.Count]; for (int i = 0; i < columnCount; ++i) { ColumnDescriptor columnDescriptor = this.columnDescriptors[i]; ColumnFormat columnFormat = columnDescriptor.Format; object columnValue = row[i]; string columnText = columnFormat.Format(columnValue); List <string> columnLines = BreakColumnText(columnDescriptor, columnText); int columnLineCount = columnLines.Count; if (columnLineCount > maxLineCount) { maxLineCount = columnLineCount; } allColumnLines[i] = columnLines; totalWidth += columnFormat.MaxWidth + 1; } for (int lineIndex = 0; lineIndex < maxLineCount; ++lineIndex) { StringBuilder rowBuffer = new StringBuilder(totalWidth); for (int i = 0; i < ColumnCount; ++i) { var columnInfo = columnDescriptors[i]; var columnFormat = columnInfo.Format; var columnLines = allColumnLines[i]; bool isLastColumn = IsLastNonEmptyColumn(allColumnLines, lineIndex, i); if (lineIndex < columnLines.Count) { string lineText = columnLines[lineIndex]; rowBuffer.Append(lineText); // Fill with blanks upon the beginning of the next column if (isLastColumn) { rowBuffer.Append(' '); } else { rowBuffer.Append(new string( ' ', columnFormat.MaxWidth - lineText.Length + 1 )); } } else { // Fill with blanks upon the beginning of the next column if (isLastColumn) { rowBuffer.Append(' '); } else { rowBuffer.Append(new string( ' ', columnFormat.MaxWidth + 1 )); } } } output.WriteLine(rowBuffer.ToString()); } }