Skip to content

Commit 4cce3a2

Browse files
committed
Message handler: add quote_begin, quote_end commands
These will permit custom formatting of quoting for each message handler, See #4875 for discussion.
1 parent d932d6f commit 4cce3a2

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

src/util/cout_message.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ console_message_handlert::console_message_handlert(bool _always_flush)
7070
/// \param c: ECMA-48 command code
7171
std::string console_message_handlert::command(unsigned c) const
7272
{
73+
// quote_begin and quote_end
74+
if(c == '<' || c == '>')
75+
return "'";
76+
7377
if(!use_SGR)
7478
return std::string();
7579

src/util/message.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ const messaget::commandt messaget::bright_yellow(93);
9595
const messaget::commandt messaget::bright_blue(94);
9696
const messaget::commandt messaget::bright_magenta(95);
9797
const messaget::commandt messaget::bright_cyan(96);
98+
const messaget::commandt messaget::quote_begin('<');
99+
const messaget::commandt messaget::quote_end('>');
98100

99101
/// Parse a (user-)provided string as a verbosity level and set it as the
100102
/// verbosity of dest.

src/util/message.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ class messaget
390390
/// render underlined text
391391
static const commandt underline;
392392

393+
/// start quoted text
394+
static const commandt quote_begin;
395+
396+
/// start quoted text
397+
static const commandt quote_end;
398+
393399
mstreamt &get_mstream(unsigned message_level) const
394400
{
395401
mstream.message_level=message_level;

src/util/ui_message.h

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,75 @@ class ui_message_handlert : public message_handlert
9696

9797
std::string command(unsigned c) const override
9898
{
99-
if(message_handler)
100-
return message_handler->command(c);
101-
else
99+
if(!message_handler)
102100
return std::string();
101+
102+
switch(_ui)
103+
{
104+
case uit::PLAIN:
105+
switch(c)
106+
{
107+
case '<': // fall through
108+
case '>':
109+
return "'";
110+
}
111+
break;
112+
case uit::XML_UI:
113+
switch(c)
114+
{
115+
case 0: // reset
116+
case 1: // bold
117+
case 2: // faint
118+
case 3: // italic
119+
case 4: // underline
120+
case 31: // red
121+
case 32: // green
122+
case 33: // yellow
123+
case 34: // blue
124+
case 35: // magenta
125+
case 36: // cyan
126+
case 91: // bright_red
127+
case 92: // bright_green
128+
case 93: // bright_yellow
129+
case 94: // bright_blue
130+
case 95: // bright_magenta
131+
case 96: // bright_cyan
132+
return std::string();
133+
case '<': // quote_begin
134+
return "'"; // could use something like <quote> here
135+
case '>': // quote_end
136+
return "'"; // could use something like </quote> here
137+
}
138+
break;
139+
case uit::JSON_UI:
140+
switch(c)
141+
{
142+
case 0: // reset
143+
case 1: // bold
144+
case 2: // faint
145+
case 3: // italic
146+
case 4: // underline
147+
case 31: // red
148+
case 32: // green
149+
case 33: // yellow
150+
case 34: // blue
151+
case 35: // magenta
152+
case 36: // cyan
153+
case 91: // bright_red
154+
case 92: // bright_green
155+
case 93: // bright_yellow
156+
case 94: // bright_blue
157+
case 95: // bright_magenta
158+
case 96: // bright_cyan
159+
return std::string();
160+
case '<': // quote_begin
161+
case '>': // quote_end
162+
return "'";
163+
}
164+
break;
165+
}
166+
167+
return message_handler->command(c);
103168
}
104169
};
105170

0 commit comments

Comments
 (0)