Skip to content

Commit

Permalink
Colorize citations when displaying text parts.
Browse files Browse the repository at this point in the history
Count the number of > at the begining of the line to compute citation
level, then use citationLevel % 4 to choose the color of the line.
  • Loading branch information
mawww authored and michaelforney committed Jan 25, 2011
1 parent 4e098cb commit 5aa7c70
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ner.yaml.sample
Expand Up @@ -80,6 +80,12 @@ colors:
attachment_filename : { fg: yellow, bg: black }
attachment_mimetype : { fg: magenta, bg: black }
attachment_filesize : { fg: green, bg: black }

# Citation levels
citation_level_1 : { fg: green, bg: black }
citation_level_2 : { fg: yellow, bg: black }
citation_level_3 : { fg: cyan, bg: black }
citation_level_4 : { fg: magenta, bg: black }
...

# vim: ft=yaml
Expand Down
8 changes: 7 additions & 1 deletion src/colors.hh
Expand Up @@ -63,7 +63,13 @@ enum ColorID
/* Message Parts */
AttachmentFilename,
AttachmentMimeType,
AttachmentFilesize
AttachmentFilesize,

/* Citation levels */
CitationLevel1,
CitationLevel2,
CitationLevel3,
CitationLevel4
};

#endif
Expand Down
23 changes: 22 additions & 1 deletion src/message_part_display_visitor.cc
Expand Up @@ -38,6 +38,27 @@ void MessagePartDisplayVisitor::visit(const TextPart & part)
{
for (auto line = part.lines.begin(), e = part.lines.end(); line != e; ++line)
{
unsigned citationLevel = 0;
for (auto character = line->begin(); character != line->end(); ++character)
{
if (*character == '>')
++citationLevel;
else if (*character != ' ')
break;
}

short color = 0;
if (citationLevel)
{
switch (citationLevel % 4)
{
case 1: color = ColorID::CitationLevel1; break;
case 2: color = ColorID::CitationLevel2; break;
case 3: color = ColorID::CitationLevel3; break;
case 0: color = ColorID::CitationLevel4; break;
}
}

for (auto lineWrapper = LineWrapper(*line); !lineWrapper.done(); ++_messageRow)
{
bool selected = _messageRow == _selection;
Expand All @@ -61,7 +82,7 @@ void MessagePartDisplayVisitor::visit(const TextPart & part)
wchgat(_window, _area.width - 2, A_REVERSE, 0, NULL);
}

if (NCurses::addUtf8String(_window, wrappedLine.c_str(), attributes) >
if (NCurses::addUtf8String(_window, wrappedLine.c_str(), attributes, color) >
_area.width - _area.y - 2)
{
NCurses::addCutOffIndicator(_window, attributes);
Expand Down
16 changes: 14 additions & 2 deletions src/ner_config.cc
Expand Up @@ -191,7 +191,13 @@ void NerConfig::load()
/* Message Parts */
{ ColorID::AttachmentFilename, Color{ COLOR_YELLOW, COLOR_BLACK } },
{ ColorID::AttachmentMimeType, Color{ COLOR_MAGENTA, COLOR_BLACK } },
{ ColorID::AttachmentFilesize, Color{ COLOR_GREEN, COLOR_BLACK } }
{ ColorID::AttachmentFilesize, Color{ COLOR_GREEN, COLOR_BLACK } },

/* Citation levels */
{ ColorID::CitationLevel1, Color{ COLOR_GREEN, COLOR_BLACK } },
{ ColorID::CitationLevel2, Color{ COLOR_YELLOW, COLOR_BLACK } },
{ ColorID::CitationLevel3, Color{ COLOR_CYAN, COLOR_BLACK } },
{ ColorID::CitationLevel4, Color{ COLOR_MAGENTA, COLOR_BLACK } }
};

const YAML::Node * colors = document.FindValue("colors");
Expand Down Expand Up @@ -239,7 +245,13 @@ void NerConfig::load()
/* Message Parts */
{ "attachment_filename", ColorID::AttachmentFilename },
{ "attachment_mimetype", ColorID::AttachmentMimeType },
{ "attachment_filesize", ColorID::AttachmentFilesize }
{ "attachment_filesize", ColorID::AttachmentFilesize },

/* Citation levels */
{ "citation_level_1", ColorID::CitationLevel1 },
{ "citation_level_2", ColorID::CitationLevel2 },
{ "citation_level_3", ColorID::CitationLevel3 },
{ "citation_level_4", ColorID::CitationLevel4 }
};

for (auto name = colors->begin(), e = colors->end(); name != e; ++name)
Expand Down

0 comments on commit 5aa7c70

Please sign in to comment.