From 046346645f5d7039100ec15db11b887d5be7d7f3 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 23 Mar 2018 19:55:35 +0300 Subject: [PATCH] Minor modifications #1959 --- dbms/src/IO/ReadHelpers.h | 2 ++ dbms/src/Server/Client.cpp | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dbms/src/IO/ReadHelpers.h b/dbms/src/IO/ReadHelpers.h index 875515149b6..2d3b405675f 100644 --- a/dbms/src/IO/ReadHelpers.h +++ b/dbms/src/IO/ReadHelpers.h @@ -52,6 +52,8 @@ inline char parseEscapeSequence(char c) return '\a'; case 'b': return '\b'; + case 'e': + return '\x1B'; /// \e escape sequence is non standard for C and C++ but supported by gcc and clang. case 'f': return '\f'; case 'n': diff --git a/dbms/src/Server/Client.cpp b/dbms/src/Server/Client.cpp index 721df841820..d16a5de3b03 100644 --- a/dbms/src/Server/Client.cpp +++ b/dbms/src/Server/Client.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -340,38 +341,37 @@ private: Strings keys; - prompt_by_server_display_name = config().getString("prompt_by_server_display_name.default", "{display_name} :) "); + prompt_by_server_display_name = config().getRawString("prompt_by_server_display_name.default", "{display_name} :) "); config().keys("prompt_by_server_display_name", keys); for (const String & key : keys) { - if (key != "default" && server_display_name.find(key) != std::string::npos) + if (key != "default" && server_display_name.find(key) != std::string::npos) { - prompt_by_server_display_name = config().getString("prompt_by_server_display_name." + key); + prompt_by_server_display_name = config().getRawString("prompt_by_server_display_name." + key); break; } } - std::map terminalCharacters = { - { "\\e[", "\e[" }, - { "\\33[", "\33[" }, - { "\\033[", "\033["}, - { "\\x1B[", "\x1B["}, - }; - - for (const auto & [key, value]: terminalCharacters) + /// Prompt may contain escape sequences including \e[ or \x1b[ sequences to set terminal color. { - boost::replace_all(prompt_by_server_display_name, key, value); + String unescaped_prompt_by_server_display_name; + ReadBufferFromString in(prompt_by_server_display_name); + readEscapedString(unescaped_prompt_by_server_display_name, in); + prompt_by_server_display_name = std::move(unescaped_prompt_by_server_display_name); } - std::map environment = { + /// Prompt may contain the following substitutions in a form of {name}. + std::map environment = + { {"host", config().getString("host", "localhost")}, {"port", config().getString("port", "9000")}, {"user", config().getString("user", "default")}, {"display_name", server_display_name}, }; + /// Quite suboptimal. for (const auto & [key, value]: environment) { boost::replace_all(prompt_by_server_display_name, "{" + key + "}", value);