Skip to content

Commit 605babb

Browse files
committed
Message handler: add quote_begin, quote_end commands
These will permit custom formatting of quoting for each message handler, and for a start introduce <quote> tags for XML. See #4875 for discussion.
1 parent c43385b commit 605babb

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
@@ -67,6 +67,10 @@ console_message_handlert::console_message_handlert(bool _always_flush)
6767
/// \param c: ECMA-48 command code
6868
std::string console_message_handlert::command(unsigned c) const
6969
{
70+
// quote_begin and quote_end
71+
if(c == '<' || c == '>')
72+
return "'";
73+
7074
if(!use_SGR)
7175
return std::string();
7276

src/util/message.cpp

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

98100
/// Parse a (user-)provided string as a verbosity level and set it as the
99101
/// 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
@@ -94,10 +94,75 @@ class ui_message_handlert : public message_handlert
9494

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

0 commit comments

Comments
 (0)