[pretty] reformat all displayed lines instead of just the top one

Fixes #150
This commit is contained in:
Timothy Stack 2015-03-26 06:13:25 -07:00
parent d7d9a16179
commit 282e70445e
4 changed files with 32 additions and 14 deletions

View File

@ -175,7 +175,7 @@ Display
* - |ks| q |ke|
- Return to the previous view/quit
* - |ks| Shift |ke| + |ks| p |ke|
- Switch to/from the pretty-printed view of the top log message
- Switch to/from the pretty-printed view of the displayed log messages
* - |ks| Shift |ke| + |ks| t |ke|
- Display elapsed time between lines
* - |ks| t |ke|

View File

@ -161,9 +161,9 @@ through the file.
>/< Move horizontally to the next/previous search hit.
P Switch to/from the pretty-printed view of the top log
message. In this view, structured data, such as XML,
will be reformatted to make it easier to read.
P Switch to/from the pretty-printed view of the log messages
currently displayed. In this view, structured data, such
as XML, will be reformatted to make it easier to read.
t Switch to/from the text file view. The text file view is
for any files that are not recognized as log files.

View File

@ -1142,20 +1142,36 @@ static void open_pretty_view(void)
textview_curses *pretty_tc = &lnav_data.ld_views[LNV_PRETTY];
logfile_sub_source &lss = lnav_data.ld_log_source;
if (lss.text_line_count() > 0) {
content_line_t cl = lss.at(log_tc->get_top());
logfile *lf = lss.find(cl);
logfile::iterator ll = lf->message_start(lf->begin() + cl);
shared_buffer_ref sbr;
lf->read_full_message(ll, sbr);
data_scanner ds(sbr);
pretty_printer pp(&ds);
ostringstream stream;
bool first_line = true;
if (pretty_tc->get_sub_source() != NULL) {
delete pretty_tc->get_sub_source();
}
string pretty_text = pp.print();
pretty_tc->set_sub_source(new plain_text_source(pretty_text));
for (vis_line_t vl = log_tc->get_top(); vl < log_tc->get_bottom(); ++vl) {
content_line_t cl = lss.at(vl);
logfile *lf = lss.find(cl);
logfile::iterator ll = lf->begin() + cl;
shared_buffer_ref sbr;
if (!first_line && ll->is_continued()) {
continue;
}
ll = lf->message_start(ll);
lf->read_full_message(ll, sbr);
data_scanner ds(sbr);
pretty_printer pp(&ds);
// TODO: dump more details of the line in the output.
stream << pp.print() << endl;
first_line = false;
}
pretty_tc->set_sub_source(new plain_text_source(stream.str()));
if (lnav_data.ld_last_pretty_print_top != log_tc->get_top()) {
pretty_tc->set_top(vis_line_t(0));
}
lnav_data.ld_last_pretty_print_top = log_tc->get_top();
}
}

View File

@ -201,6 +201,8 @@ struct _lnav_data {
std::string ld_previous_search;
std::string ld_last_search[LNV__MAX];
vis_line_t ld_last_pretty_print_top;
log_vtab_manager * ld_vtab_manager;
auto_mem<sqlite3, sqlite_close_wrapper> ld_db;