Skip to content

Commit 6e16197

Browse files
committed
cswriter: improve colorization of source code ctx
1 parent 7f4d27d commit 6e16197

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

abstract-writer.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ AbstractWriter* createWriter(
109109

110110
struct CtxEventDetector::Private {
111111
boost::regex reAnyCtxLine;
112+
boost::regex reKeyCtxLine;
112113

113114
Private():
114-
reAnyCtxLine("^ *[0-9]+\\|(?:->)? .*$")
115+
reAnyCtxLine("^ *[0-9]+\\|(?:->)? .*$"),
116+
reKeyCtxLine("^ *[0-9]+\\|-> .*$")
115117
{
116118
}
117119
};
@@ -129,3 +131,8 @@ bool CtxEventDetector::isAnyCtxLine(const DefEvent &evt) const {
129131
return (evt.event == "#")
130132
&& boost::regex_match(evt.msg, d->reAnyCtxLine);
131133
}
134+
135+
bool CtxEventDetector::isKeyCtxLine(const DefEvent &evt) const {
136+
return (evt.event == "#")
137+
&& boost::regex_match(evt.msg, d->reKeyCtxLine);
138+
}

abstract-writer.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CtxEventDetector {
7878
~CtxEventDetector();
7979

8080
bool isAnyCtxLine(const DefEvent &evt) const;
81+
bool isKeyCtxLine(const DefEvent &evt) const;
8182

8283
private:
8384
struct Private;

cswriter.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,17 @@ void CovWriter::handleDef(const Defect &def) {
7474
if (0 < evt.column)
7575
str << evt.column << ":";
7676

77-
if (evt.event == "#")
77+
if (evt.event == "#") {
7878
str << d->cw.setColor(C_LIGHT_CYAN) << "#";
7979

80+
static CtxEventDetector detector;
81+
if (detector.isAnyCtxLine(evt)) {
82+
const EColor color = detector.isKeyCtxLine(evt)
83+
? C_WHITE
84+
: C_DARK_GRAY;
85+
str << d->cw.setColor(color);
86+
}
87+
}
8088
else {
8189
str << " ";
8290
if (!evt.event.empty())

0 commit comments

Comments
 (0)