예제 #1
0
        public void JSON(object obj)
        {
            try
            {
                _buffer.Out.Standard.WriteLine();

                Queue <string> lines = new Queue <string>(JsonConvert.SerializeObject(obj, Formatting.Indented)
                                                          .Split(new string[] { Environment.NewLine }, StringSplitOptions.None));

                int maxWidth = lines.Select(l => l.Length).Max() + 2;

                foreach (var line in lines)
                {
                    _buffer.Out.Standard.Write(Constants.TAB);
                    _buffer.Out.Accent1.WriteLine(string.Format(" {0} ", line.PadRight(maxWidth)));
                }

                _buffer.Out.Standard.WriteLine();
                _buffer.Flush();
            }
            finally
            {
                _buffer.Clear();
            }
        }
예제 #2
0
        public void WriteTable(IBufferedWriter buffer)
        {
            int padding = 5;

            // write header text row

            if (Columns.Count > 0)
            {
                buffer.Out.Standard.WriteLineAsync();

                buffer.Out.Standard.WriteAsync(string.Empty.PadLeft(_leftPadding));

                foreach (var column in Columns)
                {
                    buffer.Out.Standard.WriteAsync(column.HeaderText.PadRight(column.ColumnWidth + padding));
                }

                buffer.Out.Standard.WriteLineAsync();

                // write header underline row

                buffer.Out.Standard.WriteAsync(string.Empty.PadLeft(_leftPadding));

                foreach (var column in Columns)
                {
                    buffer.Out.Standard.WriteAsync(string.Empty.PadRight(column.ColumnWidth, '=').PadRight(column.ColumnWidth + padding));
                }

                buffer.Out.Standard.WriteLineAsync();

                // write rows

                var writer = buffer.Out.Accent1;

                foreach (var row in Rows)
                {
                    if (writer == buffer.Out.Accent1)
                    {
                        writer = buffer.Out.Standard;
                    }
                    else
                    {
                        writer = buffer.Out.Accent1;
                    }

                    for (int i = 0; i < row.RowHeight; i++)
                    {
                        buffer.Out.Standard.WriteAsync(string.Empty.PadLeft(_leftPadding));

                        foreach (var column in Columns)
                        {
                            if (row.Values[column.Index].Lines.Count < i + 1)
                            {
                                writer.WriteAsync(string.Empty.PadRight(column.ColumnWidth + padding));
                            }
                            else
                            {
                                writer.WriteAsync(row.Values[column.Index].Lines[i].PadRight(column.ColumnWidth + padding));
                            }
                        }

                        buffer.Out.Standard.WriteLineAsync();
                    }
                }

                buffer.Flush();
            }
        }