Skip to content

Commit e94d9cd

Browse files
committed
[overlay] pretty-print extracted variable values
1 parent b65b9bb commit e94d9cd

2 files changed

Lines changed: 33 additions & 15 deletions

File tree

src/field_overlay_source.cc

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "log_vtab_impl.hh"
4545
#include "md2attr_line.hh"
4646
#include "msg.text.hh"
47+
#include "pretty_printer.hh"
4748
#include "ptimec.hh"
4849
#include "readline_highlighters.hh"
4950
#include "sql_util.hh"
@@ -607,16 +608,34 @@ field_overlay_source::build_field_lines(const listview_curses& lv,
607608
attr_line_t(" Variables from ")
608609
.append(lnav::roles::hyperlink(src_link_with_href)));
609610
for (const auto& [name, value] : this->fos_log_helper.ldh_src_vars) {
610-
auto al = attr_line_t(" ")
611-
.append(lnav::roles::variable(name))
612-
.append(" = ")
613-
.append(value);
614-
this->fos_row_to_field_meta.emplace(this->fos_lines.size(),
615-
row_info{
616-
std::nullopt,
617-
value,
618-
});
619-
this->fos_lines.emplace_back(al);
611+
attr_line_t pretty_value;
612+
data_scanner ds(value);
613+
pretty_printer pp(&ds, string_attrs_t{});
614+
pp.append_to(pretty_value);
615+
auto tf_opt = detect_text_format(value);
616+
if (tf_opt) {
617+
highlight_syntax(tf_opt.value(), pretty_value, std::nullopt);
618+
}
619+
auto pretty_lines = pretty_value.rtrim().split_lines();
620+
auto prefix = attr_line_t(" ")
621+
.append(lnav::roles::variable(name))
622+
.append(" = ");
623+
if (pretty_lines.size() == 1) {
624+
pretty_lines[0].insert(0, prefix);
625+
} else {
626+
pretty_lines.insert(pretty_lines.begin(), prefix);
627+
}
628+
for (size_t lpc = 0; lpc < pretty_lines.size(); lpc++) {
629+
if (lpc > 0) {
630+
pretty_lines[lpc].insert(0, " ");
631+
}
632+
this->fos_row_to_field_meta.emplace(this->fos_lines.size(),
633+
row_info{
634+
std::nullopt,
635+
value,
636+
});
637+
this->fos_lines.emplace_back(pretty_lines[lpc]);
638+
}
620639
}
621640
} else if (!this->fos_log_helper.ldh_parser
622641
|| this->fos_log_helper.ldh_parser->dp_pairs.empty())
@@ -938,10 +957,9 @@ field_overlay_source::list_static_overlay(const listview_curses& lv,
938957
{
939958
auto& exec_phase = injector::get<lnav::exec_phase&>();
940959
if (media != media_t::display) {
941-
auto& tc = dynamic_cast<textview_curses&>(
942-
const_cast<listview_curses&>(lv));
943-
const auto& sticky_bv
944-
= tc.get_bookmarks()[&textview_curses::BM_STICKY];
960+
auto& tc
961+
= dynamic_cast<textview_curses&>(const_cast<listview_curses&>(lv));
962+
const auto& sticky_bv = tc.get_bookmarks()[&textview_curses::BM_STICKY];
945963
if (!sticky_bv.empty()) {
946964
auto top = lv.get_top();
947965
int sticky_index = 0;

src/text_format.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ detect_text_format(string_fragment sf,
160160
static const auto SQL_MATCHERS = lnav::pcre2pp::code::from_const(
161161
"(?:"
162162
"create\\s+table\\s+|"
163-
"select\\s+.+\\s+from\\s+|"
163+
"select\\s+.+\\s+(?:from|where)\\s+|"
164164
"insert\\s+into\\s+.+\\s+"
165165
"values"
166166
")",

0 commit comments

Comments
 (0)