1#pragma once
2
3#include <Core/Block.h>
4#include <Processors/Formats/IOutputFormat.h>
5#include <Formats/FormatSettings.h>
6
7
8namespace DB
9{
10
11class WriteBuffer;
12class Context;
13
14
15/** Prints the result in the form of beautiful tables.
16 */
17class PrettyBlockOutputFormat : public IOutputFormat
18{
19public:
20 /// no_escapes - do not use ANSI escape sequences - to display in the browser, not in the console.
21 PrettyBlockOutputFormat(WriteBuffer & out_, const Block & header_, const FormatSettings & format_settings_);
22
23 String getName() const override { return "PrettyBlockOutputFormat"; }
24
25 void consume(Chunk) override;
26 void consumeTotals(Chunk) override;
27 void consumeExtremes(Chunk) override;
28
29 void finalize() override;
30
31protected:
32 size_t total_rows = 0;
33 size_t terminal_width = 0;
34 bool suffix_written = false;
35
36 const FormatSettings format_settings;
37
38 using Widths = PODArray<size_t>;
39 using WidthsPerColumn = std::vector<Widths>;
40
41 virtual void write(const Chunk & chunk, PortKind port_kind);
42 virtual void writeSuffix();
43
44
45 void writeSuffixIfNot()
46 {
47 if (!suffix_written)
48 writeSuffix();
49
50 suffix_written = true;
51 }
52
53 void calculateWidths(
54 const Block & header, const Chunk & chunk,
55 WidthsPerColumn & widths, Widths & max_widths, Widths & name_widths);
56
57 void writeValueWithPadding(
58 const IColumn & column, const IDataType & type, size_t row_num, size_t value_width, size_t pad_to_width);
59};
60
61}
62