ClickHouse/dbms/src/DataStreams/PrettyBlockOutputStream.h

53 lines
1.2 KiB
C++
Raw Normal View History

2011-11-07 01:15:37 +00:00
#pragma once
#include <Core/Block.h>
#include <DataStreams/IBlockOutputStream.h>
2011-11-07 01:15:37 +00:00
namespace DB
{
2016-08-13 01:57:35 +00:00
class WriteBuffer;
class Context;
2016-08-13 01:57:35 +00:00
2017-05-13 22:19:04 +00:00
/** Prints the result in the form of beautiful tables.
2011-11-07 01:15:37 +00:00
*/
class PrettyBlockOutputStream : public IBlockOutputStream
{
public:
2017-05-13 22:19:04 +00:00
/// no_escapes - do not use ANSI escape sequences - to display in the browser, not in the console.
PrettyBlockOutputStream(WriteBuffer & ostr_, bool no_escapes_, size_t max_rows_, const Context & context_);
2011-11-07 01:15:37 +00:00
void write(const Block & block) override;
void writeSuffix() override;
void flush() override;
void setTotals(const Block & totals_) override { totals = totals_; }
void setExtremes(const Block & extremes_) override { extremes = extremes_; }
2011-11-28 04:05:53 +00:00
protected:
void writeTotals();
void writeExtremes();
using Widths_t = std::vector<size_t>;
2011-11-28 04:05:53 +00:00
2017-05-13 22:19:04 +00:00
/// Evaluate the visible width (when outputting to the console with UTF-8 encoding) the width of the values and column names.
void calculateWidths(Block & block, Widths_t & max_widths, Widths_t & name_widths);
WriteBuffer & ostr;
size_t max_rows;
size_t total_rows = 0;
size_t terminal_width = 0;
2012-06-25 05:07:34 +00:00
bool no_escapes;
Block totals;
Block extremes;
const Context & context;
2011-11-07 01:15:37 +00:00
};
}