Use standard markup '{}' like macros. Add coments.

This commit is contained in:
Kirill Shvakov 2018-03-08 09:36:58 +02:00
parent 27a9ce8dd7
commit 052079b73a
6 changed files with 26 additions and 15 deletions

View File

@ -381,7 +381,7 @@ private:
Strings keys;
config().keys("prompt_by_server_display_name", keys);
prompt_by_server_display_name = config().getString("prompt_by_server_display_name.default", "%display_name% :)");
prompt_by_server_display_name = config().getString("prompt_by_server_display_name.default", "{display_name} :) ");
for (const String & key : keys)
{
@ -514,11 +514,8 @@ private:
{
String pattern = prompt_by_server_display_name;
for (const auto & [key, value]: colors)
for (const auto & [name, code]: colors)
{
String name = static_cast<String>(key);
String code = static_cast<String>(value);
boost::replace_all(pattern, "[" + name + "]", "\33[1;" + code + "m");
boost::replace_all(pattern, "[/" + name + "]", "\033[0m");
}
@ -533,7 +530,7 @@ private:
for (const auto & [key, value]: environment)
{
boost::replace_all(pattern, "%" + static_cast<String>(key) + "%", static_cast<String>(value));
boost::replace_all(pattern, "{" + key + "}", value);
}
return pattern;

View File

@ -198,7 +198,7 @@ HTTPHandler::HTTPHandler(IServer & server_)
: server(server_)
, log(&Logger::get("HTTPHandler"))
{
display_name = server.config().getString("display_name", getFQDNOrHostName());
server_display_name = server.config().getString("display_name", getFQDNOrHostName());
}
@ -632,7 +632,7 @@ void HTTPHandler::handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Ne
try
{
response.setContentType("text/plain; charset=UTF-8");
response.set("X-ClickHouse-Display-Name", display_name);
response.set("X-ClickHouse-Server-Display-Name", server_display_name);
/// For keep-alive to work.
if (request.getVersion() == Poco::Net::HTTPServerRequest::HTTP_1_1)
response.setChunkedTransferEncoding(true);

View File

@ -54,7 +54,9 @@ private:
IServer & server;
Poco::Logger * log;
String display_name;
/// It is the name of the server that will be sent in an http-header X-ClickHouse-Server-Display-Name.
String server_display_name;
CurrentMetrics::Increment metric_increment{CurrentMetrics::HTTPConnection};

View File

@ -31,7 +31,6 @@
#include "TCPHandler.h"
#include <Common/NetException.h>
#include <Common/getFQDNOrHostName.h>
namespace DB
@ -511,7 +510,7 @@ void TCPHandler::sendHello()
}
if (client_revision >= DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME)
{
writeStringBinary(server.config().getString("display_name", getFQDNOrHostName()), *out);
writeStringBinary(server_display_name, *out);
}
out->next();
}

View File

@ -2,6 +2,7 @@
#include <Poco/Net/TCPServerConnection.h>
#include <Common/getFQDNOrHostName.h>
#include <Common/CurrentMetrics.h>
#include <Common/Stopwatch.h>
#include <IO/Progress.h>
@ -81,6 +82,7 @@ public:
, connection_context(server.context())
, query_context(server.context())
{
server_display_name = server.config().getString("display_name", getFQDNOrHostName());
}
void run();
@ -111,7 +113,9 @@ private:
QueryState state;
CurrentMetrics::Increment metric_increment{CurrentMetrics::TCPConnection};
/// It is the name of the server that will be sent to the client.
String server_display_name;
void runImpl();

View File

@ -13,9 +13,18 @@
</invalidCertificateHandler>
</client>
</openSSL>
<!--
It's a custom prompt settings for the clickhouse-client
Possible macros:
{host}
{port}
{user}
{database}
{display_name}
-->
<prompt_by_server_display_name>
<default>%display_name% :)</default>
<test>%display_name% [green]:)[/green]</test>
<production>%display_name% [red]:)[/red]</production>
<default>{display_name} :) </default>
<test>{display_name} [green]:)[/green </test> <!-- if it matched to the substring "test" in the server display name - -->
<production>{display_name} [red]:)[/red] </production> <!-- if it matched to the substring "production" in the server display name -->
</prompt_by_server_display_name>
</config>