1 | #pragma once |
2 | |
3 | #include <Core/Block.h> |
4 | #include <Processors/Formats/IOutputFormat.h> |
5 | #include <Formats/FormatSettings.h> |
6 | |
7 | |
8 | namespace DB |
9 | { |
10 | |
11 | class WriteBuffer; |
12 | class Context; |
13 | |
14 | |
15 | /** Prints the result in the form of beautiful tables. |
16 | */ |
17 | class PrettyBlockOutputFormat : public IOutputFormat |
18 | { |
19 | public: |
20 | /// no_escapes - do not use ANSI escape sequences - to display in the browser, not in the console. |
21 | PrettyBlockOutputFormat(WriteBuffer & out_, const Block & , 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 | |
31 | protected: |
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 & , 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 | |