public static void ExportAndWriteLine(this ConsoleTableBuilder builder, TableAligntment alignment = TableAligntment.Left)
        {
            var strBuilder = builder.Export();

            if (alignment != TableAligntment.Left)
            {
                var lines = strBuilder.ToString().Split('\n');

                var linesCount = lines.Count();
                for (int i = 0; i < linesCount; i++)
                {
                    switch (alignment)
                    {
                    case TableAligntment.Center:
                        Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (lines[i].Length / 2)) + "}", lines[i]));
                        break;

                    case TableAligntment.Right:
                        Console.WriteLine(String.Format("{0," + Console.WindowWidth + "}", new string(' ', Console.WindowWidth - lines[i].Length) + lines[i]));
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine(strBuilder);
            }
        }
Exemplo n.º 2
0
 public static void ExportAndWriteLine(this ConsoleTableBuilder builder, TableAligntment alignment = TableAligntment.Left)
 {
     builder.ExportAndWrite(alignment);
     Console.Write('\n');
 }
Exemplo n.º 3
0
        public static void ExportAndWrite(this ConsoleTableBuilder builder, TableAligntment alignment = TableAligntment.Left)
        {
            var strBuilder = builder.Export();
            var lines      = strBuilder.ToString().Split('\n');

            var linesCount = lines.Count();

            for (int i = 0; i < linesCount; i++)
            {
                var row = string.Empty;

                switch (alignment)
                {
                case TableAligntment.Left:
                    row = lines[i];
                    break;

                case TableAligntment.Center:
                    row = String.Format("{0," + ((Console.WindowWidth / 2) + (lines[i].RealLength(true) / 2) - (lines[i].RealLength(true) - lines[i].Length)) + "}", lines[i]);
                    break;

                case TableAligntment.Right:
                    row = new string(' ', Console.WindowWidth - lines[i].RealLength(true)) + lines[i];
                    break;
                }

                if (i == 0 &&
                    !string.IsNullOrEmpty(builder.TableTitle) &&
                    builder.TableTitle.Trim().Length != 0 &&
                    !builder.TableTitleColor.IsForegroundColorNull &&
                    builder.TitlePositionStartAt > 0 &&
                    builder.TitlePositionLength > 0)
                {
                    var newTitlePositionStartAt = builder.TitlePositionStartAt + (row.Length - lines[i].Length);

                    Console.Write(row.Substring(0, newTitlePositionStartAt));
                    Console.ForegroundColor = builder.TableTitleColor.ForegroundColor;
                    if (!builder.TableTitleColor.IsBackgroundColorNull)
                    {
                        Console.BackgroundColor = builder.TableTitleColor.BackgroundColor;
                    }
                    Console.Write(row.Substring(newTitlePositionStartAt, builder.TitlePositionLength));
                    Console.ResetColor();
                    Console.Write(row.Substring(newTitlePositionStartAt + builder.TitlePositionLength, row.Length - (newTitlePositionStartAt + builder.TitlePositionLength)));
                    Console.Write('\n');
                }
                else
                {
                    if (i == linesCount - 2)
                    {
                        if (row.EndsWith('\r'.ToString()))
                        {
                            Console.Write(row.Substring(0, row.Length - 1));
                        }
                        else
                        {
                            Console.Write(row);
                        }
                    }
                    else
                    {
                        if (i == linesCount - 1) // is last line
                        {
                            Console.Write(row);
                        }
                        else
                        {
                            Console.WriteLine(row);
                        }
                    }
                }
            }
        }