Ejemplo n.º 1
0
 /// <summary>
 /// Set the colors from a rowconf color delegate
 /// </summary>
 /// <param name="cfg">RowConf instance</param>
 /// <param name="column">column index</param>
 /// <param name="content">text that should be written</param>
 public static void SetColor(RowConf cfg, int column, string content)
 {
     if (cfg.IsColorize == null || cfg.IsColorize(cfg, column, content))
     {
         ColorScheme color = cfg.Color == null ? null : cfg.Color(cfg, column, content);
         SetColor(color);
     }
 }
Ejemplo n.º 2
0
        public static RowCollection Create(string[][] data)
        {
            var c = new RowCollection();

            foreach (var item in data)
            {
                c.Import(RowConf.Create(item));
            }
            return(c);
        }
Ejemplo n.º 3
0
        public static RowCollection Create(RowConf header, params RowConf[] data)
        {
            var c = new RowCollection();

            c.Import(header);
            foreach (var item in data)
            {
                c.Import(item);
            }
            return(c);
        }
Ejemplo n.º 4
0
        public RowConf Clone(bool standalone)
        {
            var c = new RowConf()
            {
                border             = (standalone ? this.Border.Clone() : this.border),
                Data               = this.Data.ToList().ToArray(),
                RealLength         = (standalone ? this.RealLength.Clone() : this.reallength),
                Color              = (standalone ? this.Color : this.color),
                IsColorize         = (standalone ? this.IsColorize : this.iscolorize),
                IsHighlightPadding = (standalone ? this.IsHighlightPadding : this.ishighlightpadding)
            };

            return(c);
        }
Ejemplo n.º 5
0
        protected void Import(RowConf item, int?index)
        {
            var temp = item.Clone();

            temp.Parent = this;
            if (index.HasValue && index.Value >= 0)
            {
                this.Items.Insert(index.Value, temp);
            }
            else
            {
                this.Items.Add(temp);
            }

            if (this.IsCustomLength == false)
            {
                this.length = this.CalcTableLength();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Write columns based on a RowConf instance
        /// </summary>
        /// <param name="cfg">the rowconf</param>
        public static void WriteColumns(RowConf cfg)
        {
            // Build column wrapping
            string[][] sublines = cfg.WordwrappedData;

            // Print columns
            int maxsublines = sublines.Max(v => v.Length);

            for (int j = 0; j < maxsublines; j++)
            {
                if (cfg.Border.Enabled)
                {
                    Write(cfg.Border.CellVerticalLine + ("".PadLeft(TableCellPadding, ' ')));
                }

                for (int i = 0; i < sublines.Length; i++)
                {
                    string item      = (sublines[i].Length > j ? sublines[i][j] : "");
                    int    padlen    = cfg.Length.Items[i].Length - item.Length;
                    string pad       = "".PadRight(padlen, ' ');
                    bool   hlpadding = cfg.IsHighlightPadding != null && cfg.IsHighlightPadding(cfg, i, item);
                    RowCollectionSettings.ALIGN align = (cfg.Align == null ? null : cfg.Align(cfg, i, item)) ?? RowCollectionSettings.ALIGN.LEFT;

                    ResetColor();

                    if (align == RowCollectionSettings.ALIGN.RIGHT)
                    {
                        if (hlpadding)
                        {
                            SetColor(cfg, i, item);
                        }
                        Write(pad);
                        SetColor(cfg, i, item);
                        Write(item);
                    }
                    else if (align == RowCollectionSettings.ALIGN.CENTER)
                    {
                        int before = (int)((0.0 + padlen) / 2.0);
                        int after  = (int)Math.Ceiling(((0.0 + padlen) / 2.0));

                        if (hlpadding)
                        {
                            SetColor(cfg, i, item);
                        }
                        Write("".PadLeft(before, ' '));
                        SetColor(cfg, i, item);
                        Write(item);
                        if (!hlpadding)
                        {
                            ResetColor();
                        }
                        Write("".PadLeft(after, ' '));
                    }
                    else
                    {
                        SetColor(cfg, i, item);
                        Write(item);
                        if (!hlpadding)
                        {
                            ResetColor();
                        }
                        Write(pad);
                    }

                    ResetColor();

                    if (cfg.Border.Enabled)
                    {
                        Write(("".PadLeft(TableCellPadding, ' ')) + cfg.Border.CellVerticalLine);
                        if (i < sublines.Length - 1)
                        {
                            Write(("".PadLeft(TableCellPadding, ' ')));
                        }
                    }
                    else if (i < sublines.Length - 1)
                    {
                        Write(("".PadLeft(ColumnPadding, ' ')));
                    }
                }
                WriteLine();
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Write columns with the title color scheme on full width
 /// </summary>
 /// <param name="length">The length for each columns</param>
 /// <param name="s">The column contents</param>
 public static void WriteTitleLarge(LengthCollection length, string[] s)
 {
     WriteColumns(RowConf.Create(length, s).PresetTitle().SetBordered(false).SetAlignment(RowConf.ALIGNCENTER).SetHlPadding(true));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Write columns with the title color scheme
 /// </summary>
 /// <param name="length">The length for each columns</param>
 /// <param name="s">The column contents</param>
 public static void WriteTitle(LengthCollection length, string[] s)
 {
     WriteColumns(RowConf.Create(length, s).PresetTitle().SetBordered(false));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Write columns with the title color scheme
 /// </summary>
 /// <param name="s">the column contents</param>
 public static void WriteTitle(params string[] s)
 {
     WriteColumns(RowConf.Create(s).PresetTitle().SetBordered(false));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Write columns with the highlight color scheme
 /// </summary>
 /// <param name="length">The length for each columns</param>
 /// <param name="s">The column contents</param>
 public static void WriteHl(LengthCollection length, params string[] s)
 {
     WriteColumns(RowConf.Create(length, s).PresetHL());
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Write columns with the highlight color scheme
 /// </summary>
 /// <param name="s">the column contents</param>
 public static void WriteHl(params string[] s)
 {
     WriteColumns(RowConf.Create(s).PresetHL());
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Write columns
 /// </summary>
 /// <param name="s">the column contents</param>
 public static void WriteColumns(params string[] s)
 {
     WriteColumns(RowConf.Create(s).SetHlPadding(false));
 }
Ejemplo n.º 13
0
 public static RowCollection Create(RowConf row)
 {
     return(Create(new RowConf[] { row }));
 }
Ejemplo n.º 14
0
 public RowCollection Import(int index, RowConf item)
 {
     this.Import(item, index);
     return(this);
 }
Ejemplo n.º 15
0
 public RowCollection Import(RowConf item)
 {
     this.Import(item, null);
     return(this);
 }