Пример #1
0
        private int UpdateColumnWidth(int col)
        {
            if (col < 0 || col >= Columns.Count)
            {
                return(0);
            }

            ConsoleTableColumn column = Columns[col];

            column.Width = column.HeaderText.Length + 1 + CellPadding;

            for (int rowIndex = 0; rowIndex < Rows.Count; rowIndex++)
            {
                List <object> row = Rows[rowIndex];
                if (col >= row.Count)
                {
                    continue;
                }
                string value = ConvertValue(row[col], rowIndex, col);

                column.Width = Math.Max(column.Width, value.Length + 1 + CellPadding);
            }

            return(column.Width);
        }
Пример #2
0
        public void WriteHeader(bool headerDividerCap = true)
        {
            AttemptUpdate();

            if (headerDividerCap)
            {
                WriteDivider(ConsoleTableSection.Header);
            }

            Printer.Write($"{ColumnSeperator}", ConsoleTableSection.Seperator | ConsoleTableSection.Header, -1, -1);

            for (int colIndex = 0; colIndex < Columns.Count; colIndex++)
            {
                ConsoleTableColumn column = Columns[colIndex];

                Printer.Write(" ", ConsoleTableSection.Padding | ConsoleTableSection.Header, colIndex, -1);
                Printer.Write(column.HeaderText, ConsoleTableSection.Column | ConsoleTableSection.Header, colIndex, -1);
                Printer.Write(Repeat(" ", column.Padding), ConsoleTableSection.Padding | ConsoleTableSection.Header, colIndex, -1);
                Printer.Write($"{ColumnSeperator}", ConsoleTableSection.Seperator | ConsoleTableSection.Header, -1, -1);
            }

            Printer.Write("\n", ConsoleTableSection.Header, -1, -1);


            WriteDivider(ConsoleTableSection.Header);
        }
Пример #3
0
        public void WriteRow(int rowIndex, bool writeDividers = true, params object[] columnValues)
        {
            AttemptUpdate();

            Printer.Write($"{ColumnSeperator}", ConsoleTableSection.Row | ConsoleTableSection.Seperator, -1, rowIndex);



            for (int columnIndex = 0; columnIndex < Columns.Count; columnIndex++)
            {
                ConsoleTableColumn columnDef = Columns[columnIndex];

                bool hasColumnValue = columnIndex < columnValues.Length;

                object columnObject = hasColumnValue ? columnValues[columnIndex] : null;
                string columnValue  = ConvertValue(columnObject, rowIndex, columnIndex);

                Printer.Write(" ", ConsoleTableSection.Row | ConsoleTableSection.Padding, columnIndex, rowIndex);
                Printer.Write(columnValue, ConsoleTableSection.Row | ConsoleTableSection.Column, columnIndex, rowIndex);
                Printer.Write(Repeat(" ", columnDef.Width - columnValue.Length), ConsoleTableSection.Row | ConsoleTableSection.Padding, columnIndex, rowIndex);
                Printer.Write($"{ColumnSeperator}", ConsoleTableSection.Row | ConsoleTableSection.Seperator, -1, rowIndex);
            }

            Printer.Write("\n", ConsoleTableSection.Row, -1, rowIndex);

            if (writeDividers)
            {
                WriteDivider(ConsoleTableSection.Row);
            }
        }
Пример #4
0
        public void WriteDivider(ConsoleTableSection root = ConsoleTableSection.None)
        {
            AttemptUpdate();

            Printer.Write($"{RowColumnJunction}", root | ConsoleTableSection.Divider | ConsoleTableSection.Seperator, -1, -1);

            for (int colIndex = 0; colIndex < Columns.Count; colIndex++)
            {
                ConsoleTableColumn column = Columns[colIndex];
                Printer.Write(Repeat(RowSeperator.ToString(), column.Width + 1), root | ConsoleTableSection.Divider | ConsoleTableSection.Column, colIndex, -1);
                Printer.Write($"{RowColumnJunction}", root | ConsoleTableSection.Divider | ConsoleTableSection.Seperator, -1, -1);
            }

            Printer.Write("\n", root | ConsoleTableSection.Divider, -1, -1);
        }