summaryrefslogtreecommitdiffstats
path: root/src/db_sub_source.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/db_sub_source.cc244
1 files changed, 152 insertions, 92 deletions
diff --git a/src/db_sub_source.cc b/src/db_sub_source.cc
index 795bda8..9453876 100644
--- a/src/db_sub_source.cc
+++ b/src/db_sub_source.cc
@@ -27,10 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <regex>
-
#include "db_sub_source.hh"
+#include "base/ansi_scrubber.hh"
#include "base/date_time_scanner.hh"
#include "base/itertools.hh"
#include "base/time_util.hh"
@@ -40,7 +39,6 @@
const char db_label_source::NULL_STR[] = "<NULL>";
-constexpr size_t MAX_COLUMN_WIDTH = 120;
constexpr size_t MAX_JSON_WIDTH = 16 * 1024;
void
@@ -55,15 +53,17 @@ db_label_source::text_value_for_line(textview_curses& tc,
*/
label_out.clear();
- if (row >= (int) this->dls_rows.size()) {
+ this->dls_ansi_attrs.clear();
+ if (row < 0_vl || row >= (int) this->dls_rows.size()) {
return;
}
for (int lpc = 0; lpc < (int) this->dls_rows[row].size(); lpc++) {
- auto actual_col_size
- = std::min(MAX_COLUMN_WIDTH, this->dls_headers[lpc].hm_column_size);
+ auto actual_col_size = std::min(this->dls_max_column_width,
+ this->dls_headers[lpc].hm_column_size);
auto cell_str = scrub_ws(this->dls_rows[row][lpc]);
-
- truncate_to(cell_str, MAX_COLUMN_WIDTH);
+ string_attrs_t cell_attrs;
+ scrub_ansi_string(cell_str, &cell_attrs);
+ truncate_to(cell_str, this->dls_max_column_width);
auto cell_length
= utf8_string_length(cell_str).unwrapOr(actual_col_size);
@@ -72,11 +72,15 @@ db_label_source::text_value_for_line(textview_curses& tc,
if (this->dls_headers[lpc].hm_column_type != SQLITE3_TEXT) {
label_out.append(padding, ' ');
}
+ shift_string_attrs(cell_attrs, 0, label_out.size());
label_out.append(cell_str);
if (this->dls_headers[lpc].hm_column_type == SQLITE3_TEXT) {
label_out.append(padding, ' ');
}
label_out.append(1, ' ');
+
+ this->dls_ansi_attrs.insert(
+ this->dls_ansi_attrs.end(), cell_attrs.begin(), cell_attrs.end());
}
}
@@ -88,12 +92,20 @@ db_label_source::text_attrs_for_line(textview_curses& tc,
struct line_range lr(0, 0);
const struct line_range lr2(0, -1);
- if (row >= (int) this->dls_rows.size()) {
+ if (row < 0_vl || row >= (int) this->dls_rows.size()) {
return;
}
+ sa = this->dls_ansi_attrs;
+ auto alt_row_index = row % 4;
+ if (alt_row_index == 2 || alt_row_index == 3) {
+ sa.emplace_back(lr2, VC_ROLE.value(role_t::VCR_ALT_ROW));
+ }
for (size_t lpc = 0; lpc < this->dls_headers.size() - 1; lpc++) {
- if (row % 2 == 0) {
- sa.emplace_back(lr2, VC_STYLE.value(text_attrs{A_BOLD}));
+ const auto& hm = this->dls_headers[lpc];
+
+ if (hm.hm_graphable) {
+ lr.lr_end += this->dls_cell_width[lpc];
+ sa.emplace_back(lr, VC_ROLE.value(role_t::VCR_NUMBER));
}
lr.lr_start += this->dls_cell_width[lpc];
lr.lr_end = lr.lr_start + 1;
@@ -101,17 +113,29 @@ db_label_source::text_attrs_for_line(textview_curses& tc,
lr.lr_start += 1;
}
- int left = 0;
+ for (const auto& attr : sa) {
+ require_ge(attr.sa_range.lr_start, 0);
+ }
+ int cell_start = 0;
for (size_t lpc = 0; lpc < this->dls_headers.size(); lpc++) {
auto row_view = scn::string_view{this->dls_rows[row][lpc]};
const auto& hm = this->dls_headers[lpc];
+ int left = cell_start;
if (hm.hm_graphable) {
auto num_scan_res = scn::scan_value<double>(row_view);
if (num_scan_res) {
- this->dls_chart.chart_attrs_for_value(
- tc, left, hm.hm_name, num_scan_res.value(), sa);
+ hm.hm_chart.chart_attrs_for_value(tc,
+ left,
+ this->dls_cell_width[lpc],
+ hm.hm_name,
+ num_scan_res.value(),
+ sa);
+
+ for (const auto& attr : sa) {
+ require_ge(attr.sa_range.lr_start, 0);
+ }
}
}
if (row_view.length() > 2 && row_view.length() < MAX_JSON_WIDTH
@@ -132,16 +156,25 @@ db_label_source::text_attrs_for_line(textview_curses& tc,
= scn::scan_value<double>(jpw_value.wt_value);
if (num_scan_res) {
- this->dls_chart.chart_attrs_for_value(
+ hm.hm_chart.chart_attrs_for_value(
tc,
left,
+ this->dls_cell_width[lpc],
jpw_value.wt_ptr,
num_scan_res.value(),
sa);
+ for (const auto& attr : sa) {
+ require_ge(attr.sa_range.lr_start, 0);
+ }
}
}
}
}
+ cell_start += this->dls_cell_width[lpc] + 1;
+ }
+
+ for (const auto& attr : sa) {
+ require_ge(attr.sa_range.lr_start, 0);
}
}
@@ -158,9 +191,13 @@ db_label_source::push_header(const std::string& colstr,
hm.hm_column_size = utf8_string_length(colstr).unwrapOr(colstr.length());
hm.hm_column_type = type;
hm.hm_graphable = graphable;
- if (colstr == "log_time") {
+ if (graphable) {
+ hm.hm_column_size = std::max(hm.hm_column_size, size_t{10});
+ }
+ if (colstr == "log_time" || colstr == "min(log_time)") {
this->dls_time_column_index = this->dls_headers.size() - 1;
}
+ hm.hm_chart.with_show_state(stacked_bar_chart_base::show_all{});
}
void
@@ -221,9 +258,9 @@ db_label_source::push_column(const scoped_value_t& sv)
&& this->dls_headers[index].hm_graphable)
{
if (sv.is<int64_t>()) {
- this->dls_chart.add_value(hm.hm_name, sv.get<int64_t>());
+ hm.hm_chart.add_value(hm.hm_name, sv.get<int64_t>());
} else {
- this->dls_chart.add_value(hm.hm_name, sv.get<double>());
+ hm.hm_chart.add_value(hm.hm_name, sv.get<double>());
}
} else if (col_sf.length() > 2
&& ((col_sf.startswith("{") && col_sf.endswith("}"))
@@ -241,20 +278,20 @@ db_label_source::push_column(const scoped_value_t& sv)
auto num_scan_res = scn::scan_value<double>(jpw_value.wt_value);
if (num_scan_res) {
- this->dls_chart.add_value(jpw_value.wt_ptr,
- num_scan_res.value());
- this->dls_chart.with_attrs_for_ident(
+ hm.hm_chart.add_value(jpw_value.wt_ptr,
+ num_scan_res.value());
+ hm.hm_chart.with_attrs_for_ident(
jpw_value.wt_ptr, vc.attrs_for_ident(jpw_value.wt_ptr));
}
}
}
}
+ hm.hm_chart.next_row();
}
void
db_label_source::clear()
{
- this->dls_chart.clear();
this->dls_headers.clear();
this->dls_rows.clear();
this->dls_time_column.clear();
@@ -282,26 +319,48 @@ db_label_source::row_for_time(struct timeval time_bucket)
return nonstd::nullopt;
}
-size_t
-db_overlay_source::list_overlay_count(const listview_curses& lv)
+nonstd::optional<text_time_translator::row_info>
+db_label_source::time_for_row(vis_line_t row)
+{
+ if ((row < 0_vl) || (((size_t) row) >= this->dls_time_column.size())) {
+ return nonstd::nullopt;
+ }
+
+ return row_info{this->dls_time_column[row], row};
+}
+
+nonstd::optional<attr_line_t>
+db_overlay_source::list_header_for_overlay(const listview_curses& lv,
+ vis_line_t line)
+{
+ attr_line_t retval;
+
+ retval.append(" JSON column details");
+ return retval;
+}
+
+void
+db_overlay_source::list_value_for_overlay(const listview_curses& lv,
+ vis_line_t row,
+ std::vector<attr_line_t>& value_out)
{
size_t retval = 1;
if (!this->dos_active || lv.get_inner_height() == 0) {
- this->dos_lines.clear();
+ return;
+ }
- return retval;
+ if (row != lv.get_selection()) {
+ return;
}
auto& vc = view_colors::singleton();
- auto top = lv.get_top();
- const auto& cols = this->dos_labels->dls_rows[top];
+ const auto& cols = this->dos_labels->dls_rows[row];
unsigned long width;
vis_line_t height;
lv.get_dimensions(height, width);
- this->dos_lines.clear();
for (size_t col = 0; col < cols.size(); col++) {
const char* col_value = cols[col];
size_t col_len = strlen(col_value);
@@ -321,21 +380,23 @@ db_overlay_source::list_overlay_count(const listview_curses& lv)
{
const std::string& header
= this->dos_labels->dls_headers[col].hm_name;
- this->dos_lines.emplace_back(" JSON Column: " + header);
+ value_out.emplace_back(" Column: " + header);
retval += 1;
}
stacked_bar_chart<std::string> chart;
- int start_line = this->dos_lines.size();
+ int start_line = value_out.size();
- chart.with_stacking_enabled(false).with_margins(3, 0);
+ chart.with_stacking_enabled(false)
+ .with_margins(3, 0)
+ .with_show_state(stacked_bar_chart_base::show_all{});
for (auto& jpw_value : jpw.jpw_values) {
- this->dos_lines.emplace_back(" " + jpw_value.wt_ptr + " = "
- + jpw_value.wt_value);
+ value_out.emplace_back(" " + jpw_value.wt_ptr + " = "
+ + jpw_value.wt_value);
- string_attrs_t& sa = this->dos_lines.back().get_attrs();
+ auto& sa = value_out.back().get_attrs();
struct line_range lr(1, 2);
sa.emplace_back(lr, VC_GRAPHIC.value(ACS_LTEE));
@@ -370,20 +431,24 @@ db_overlay_source::list_overlay_count(const listview_curses& lv)
auto num_scan_res = scn::scan_value<double>(iter->wt_value);
if (num_scan_res) {
- auto& sa = this->dos_lines[curr_line].get_attrs();
+ auto& sa = value_out[curr_line].get_attrs();
int left = 3;
- chart.chart_attrs_for_value(
- lv, left, iter->wt_ptr, num_scan_res.value(), sa);
+ chart.chart_attrs_for_value(lv,
+ left,
+ width,
+ iter->wt_ptr,
+ num_scan_res.value(),
+ sa);
}
}
}
}
if (retval > 1) {
- this->dos_lines.emplace_back("");
+ value_out.emplace_back("");
- string_attrs_t& sa = this->dos_lines.back().get_attrs();
+ string_attrs_t& sa = value_out.back().get_attrs();
struct line_range lr(1, 2);
sa.emplace_back(lr, VC_GRAPHIC.value(ACS_LLCORNER));
@@ -393,65 +458,60 @@ db_overlay_source::list_overlay_count(const listview_curses& lv)
retval += 1;
}
-
- return retval;
}
bool
-db_overlay_source::list_value_for_overlay(const listview_curses& lv,
- int y,
- int bottom,
- vis_line_t row,
- attr_line_t& value_out)
+db_overlay_source::list_static_overlay(const listview_curses& lv,
+ int y,
+ int bottom,
+ attr_line_t& value_out)
{
- if (y == 0) {
- this->list_overlay_count(lv);
- std::string& line = value_out.get_string();
- db_label_source* dls = this->dos_labels;
- string_attrs_t& sa = value_out.get_attrs();
+ if (y != 0) {
+ return false;
+ }
- for (size_t lpc = 0; lpc < this->dos_labels->dls_headers.size(); lpc++)
- {
- auto actual_col_size = std::min(
- MAX_COLUMN_WIDTH, dls->dls_headers[lpc].hm_column_size);
- std::string cell_title = dls->dls_headers[lpc].hm_name;
-
- truncate_to(cell_title, MAX_COLUMN_WIDTH);
-
- auto cell_length
- = utf8_string_length(cell_title).unwrapOr(actual_col_size);
- int before, total_fill = actual_col_size - cell_length;
- auto line_len_before = line.length();
-
- before = total_fill / 2;
- total_fill -= before;
- line.append(before, ' ');
- line.append(cell_title);
- line.append(total_fill, ' ');
- line.append(1, ' ');
-
- struct line_range header_range(line_len_before, line.length());
-
- text_attrs attrs;
- if (this->dos_labels->dls_headers[lpc].hm_graphable) {
- attrs = dls->dls_headers[lpc].hm_title_attrs
- | text_attrs{A_REVERSE};
- } else {
- attrs.ta_attrs = A_UNDERLINE;
- }
- sa.emplace_back(header_range, VC_STYLE.value(text_attrs{attrs}));
- }
+ auto& line = value_out.get_string();
+ auto* dls = this->dos_labels;
+ auto& sa = value_out.get_attrs();
- struct line_range lr(0);
+ for (size_t lpc = 0; lpc < this->dos_labels->dls_headers.size(); lpc++) {
+ auto actual_col_size = std::min(dls->dls_max_column_width,
+ dls->dls_headers[lpc].hm_column_size);
+ std::string cell_title = dls->dls_headers[lpc].hm_name;
+ string_attrs_t cell_attrs;
+ scrub_ansi_string(cell_title, &cell_attrs);
+ truncate_to(cell_title, dls->dls_max_column_width);
- sa.emplace_back(lr, VC_STYLE.value(text_attrs{A_BOLD | A_UNDERLINE}));
- return true;
- } else if (this->dos_active && y >= 2
- && ((size_t) y) < (this->dos_lines.size() + 2))
- {
- value_out = this->dos_lines[y - 2];
- return true;
+ auto cell_length
+ = utf8_string_length(cell_title).unwrapOr(actual_col_size);
+ int before, total_fill = actual_col_size - cell_length;
+ auto line_len_before = line.length();
+
+ before = total_fill / 2;
+ total_fill -= before;
+ line.append(before, ' ');
+ shift_string_attrs(cell_attrs, 0, line.size());
+ line.append(cell_title);
+ line.append(total_fill, ' ');
+ struct line_range header_range(line_len_before, line.length());
+
+ line.append(1, ' ');
+
+ require_ge(header_range.lr_start, 0);
+
+ text_attrs attrs;
+ if (this->dos_labels->dls_headers[lpc].hm_graphable) {
+ attrs
+ = dls->dls_headers[lpc].hm_title_attrs | text_attrs{A_REVERSE};
+ } else {
+ attrs.ta_attrs = A_UNDERLINE;
+ }
+ sa.emplace_back(header_range, VC_STYLE.value(attrs));
+ sa.insert(sa.end(), cell_attrs.begin(), cell_attrs.end());
}
- return false;
+ struct line_range lr(0);
+
+ sa.emplace_back(lr, VC_STYLE.value(text_attrs{A_BOLD | A_UNDERLINE}));
+ return true;
}