[file-marker] some more cleanup

This commit is contained in:
Timothy Stack 2015-05-14 22:07:28 -07:00
parent b8b16bd8e5
commit 04f8ceadab
5 changed files with 36 additions and 5 deletions

View File

@ -1799,7 +1799,10 @@ static void handle_paging_key(int ch)
for (; top <= bottom; ++top) {
attr_line_t al;
tc->listview_value_for_row(*tc, top, al);
write(STDOUT_FILENO, al.get_string().c_str(), al.length());
struct line_range lr = find_string_attr_range(
al.get_attrs(), &textview_curses::SA_ORIGINAL_LINE);
write(STDOUT_FILENO, lr.substr(al.get_string()),
lr.sublen(al.get_string()));
write(STDOUT_FILENO, "\n", 1);
}
}
@ -4726,7 +4729,8 @@ int main(int argc, char *argv[])
++vl, ++y) {
while (los != NULL &&
los->list_value_for_overlay(*tc, y, al)) {
printf("%s\n", line.c_str());
write(STDOUT_FILENO, line.c_str(), line.length());
write(STDOUT_FILENO, "\n", 1);
++y;
}
@ -4735,7 +4739,11 @@ int main(int argc, char *argv[])
continue;
}
printf("%s\n", line.c_str());
struct line_range lr = find_string_attr_range(
al.get_attrs(), &textview_curses::SA_ORIGINAL_LINE);
write(STDOUT_FILENO, lr.substr(al.get_string()),
lr.sublen(al.get_string()));
write(STDOUT_FILENO, "\n", 1);
}
}
}

View File

@ -246,6 +246,7 @@ void logfile_sub_source::text_attrs_for_line(textview_curses &lv,
int time_offset_end = 0;
int attrs = 0;
value_out.clear();
switch (this->lss_token_line->get_level() & ~logline::LEVEL__FLAGS) {
case logline::LEVEL_FATAL:
case logline::LEVEL_CRITICAL:
@ -283,6 +284,10 @@ void logfile_sub_source::text_attrs_for_line(textview_curses &lv,
format->annotate(sbr, value_out, line_values);
}
lr.lr_start = 0;
lr.lr_end = this->lss_token_value.length();
value_out.push_back(string_attr(lr, &textview_curses::SA_ORIGINAL_LINE));
lr.lr_start = time_offset_end + this->lss_token_date_end;
lr.lr_end = -1;
@ -292,7 +297,7 @@ void logfile_sub_source::text_attrs_for_line(textview_curses &lv,
for (string_attrs_t::iterator iter = value_out.begin();
iter != value_out.end();
++iter) {
struct line_range *existing_lr = (line_range *) &iter->sa_range;
struct line_range *existing_lr = &iter->sa_range;
existing_lr->lr_start += 1;
if (existing_lr->lr_end != -1) {

View File

@ -57,6 +57,7 @@ bookmark_type_t textview_curses::BM_USER("user");
bookmark_type_t textview_curses::BM_PARTITION("partition");
bookmark_type_t textview_curses::BM_SEARCH("search");
string_attr_type textview_curses::SA_ORIGINAL_LINE;
string_attr_type textview_curses::SA_BODY;
textview_curses::textview_curses()

View File

@ -382,6 +382,7 @@ public:
static bookmark_type_t BM_PARTITION;
static bookmark_type_t BM_SEARCH;
static string_attr_type SA_ORIGINAL_LINE;
static string_attr_type SA_BODY;
struct highlighter {

View File

@ -196,6 +196,23 @@ struct line_range {
bool operator==(const struct line_range &rhs) const {
return (this->lr_start == rhs.lr_start && this->lr_end == rhs.lr_end);
};
const char *substr(const std::string &str) const {
if (this->lr_start == -1) {
return str.c_str();
}
return &(str.c_str()[this->lr_start]);
}
size_t sublen(const std::string &str) const {
if (this->lr_start == -1) {
return str.length();
}
if (this->lr_end == -1) {
return str.length() - this->lr_start;
}
return this->length();
}
};
/**
@ -239,7 +256,6 @@ inline string_attrs_t::const_iterator
find_string_attr(const string_attrs_t &sa, string_attr_type_t type)
{
string_attrs_t::const_iterator iter;
struct line_range retval;
for (iter = sa.begin(); iter != sa.end(); ++iter) {
if (iter->sa_type == type) {