• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 19674547642-2710

25 Nov 2025 03:17PM UTC coverage: 68.841% (+0.001%) from 68.84%
19674547642-2710

push

github

tstack
[spectro] per-row thresholds

32 of 37 new or added lines in 3 files covered. (86.49%)

378 existing lines in 10 files now uncovered.

51184 of 74351 relevant lines covered (68.84%)

431944.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.21
/src/db_sub_source.cc
1
/**
2
 * Copyright (c) 2014, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#include <iterator>
31
#include <map>
32

33
#include "db_sub_source.hh"
34

35
#include "base/ansi_scrubber.hh"
36
#include "base/date_time_scanner.hh"
37
#include "base/humanize.hh"
38
#include "base/itertools.enumerate.hh"
39
#include "base/itertools.hh"
40
#include "base/map_util.hh"
41
#include "base/math_util.hh"
42
#include "base/time_util.hh"
43
#include "base/types.hh"
44
#include "config.h"
45
#include "hist_source_T.hh"
46
#include "scn/scan.h"
47
#include "yajlpp/json_ptr.hh"
48
#include "yajlpp/yajlpp_def.hh"
49

50
using namespace lnav::roles::literals;
51

52
const unsigned char db_label_source::NULL_STR[] = "<NULL>";
53

54
constexpr ssize_t MAX_JSON_WIDTH = 16 * 1024;
55

56
struct user_row_style {
57
    lnav::map::small<std::string, style_config> urs_column_config;
58
};
59

60
static const typed_json_path_container<user_row_style>&
61
get_row_style_handlers()
9✔
62
{
63
    static const json_path_container col_style_handlers = {
64
        yajlpp::pattern_property_handler("(?<column_name>[^/]+)")
3✔
65
            .for_field(&user_row_style::urs_column_config)
3✔
66
            .with_children(style_config_handlers),
3✔
67
    };
18✔
68

69
    static const typed_json_path_container<user_row_style> retval
70
        = typed_json_path_container<user_row_style>{
9✔
71
            yajlpp::property_handler("columns")
9✔
72
                .with_children(col_style_handlers),
3✔
73
    }.with_schema_id2("row-style"_frag);
18✔
74

75
    return retval;
9✔
76
}
12✔
77

78
line_info
79
db_label_source::text_value_for_line(textview_curses& tc,
998✔
80
                                     int row,
81
                                     std::string& label_out,
82
                                     line_flags_t flags)
83
{
84
    /*
85
     * start_value is the result rowid, each bucket type is a column value
86
     * label_out should be the raw text output.
87
     */
88

89
    label_out.clear();
998✔
90
    this->dls_ansi_attrs.clear();
998✔
91
    label_out.reserve(this->dls_max_column_width * this->dls_headers.size());
998✔
92
    if (row < 0_vl || row >= (int) this->dls_row_cursors.size()) {
998✔
93
        return {};
×
94
    }
95
    std::optional<log_level_t> row_level;
998✔
96
    auto cell_cursor = this->dls_row_cursors[row].sync();
998✔
97
    for (size_t lpc = 0; lpc < this->dls_headers.size();
5,445✔
98
         lpc++, cell_cursor = cell_cursor->next())
4,447✔
99
    {
100
        if (lpc == this->dls_row_style_column
4,447✔
101
            && !this->dls_row_styles_have_errors)
9✔
102
        {
103
            continue;
9✔
104
        }
105
        const auto& hm = this->dls_headers[lpc];
4,441✔
106
        if (hm.hm_hidden) {
4,441✔
107
            continue;
3✔
108
        }
109
        ssize_t actual_col_size
110
            = std::min(this->dls_max_column_width, hm.hm_column_size);
4,438✔
111
        auto align = hm.hm_align;
4,438✔
112

113
        if (row < (int) this->dls_row_styles.size()) {
4,438✔
114
            auto style_opt
115
                = this->dls_row_styles[row].rs_column_config.value_for(lpc);
18✔
116
            if (style_opt && style_opt.value()->ta_align.has_value()) {
18✔
117
                align = style_opt.value()->ta_align.value();
3✔
118
            }
119
        }
120

121
        auto sf = cell_cursor->to_string_fragment(this->dls_cell_allocator);
4,438✔
122
        auto al = attr_line_t::from_table_cell_content(
123
            sf, this->dls_max_column_width);
4,438✔
124

125
        if (this->tss_view != nullptr
8,876✔
126
            && cell_cursor->get_type() == lnav::cell_type::CT_TEXT)
4,438✔
127
        {
128
            this->tss_view->apply_highlights(
1,086✔
129
                al, line_range::empty_at(0), line_range::empty_at(0));
2,172✔
130
        }
131
        if (this->dls_level_column && lpc == this->dls_level_column.value()) {
4,438✔
132
            row_level = string2level(sf.data(), sf.length());
119✔
133
        }
134

135
        auto cell_length = al.utf8_length_or_length();
4,438✔
136
        if (actual_col_size < cell_length) {
4,438✔
137
            log_warning(
×
138
                "invalid column size: actual_col_size=%zd < cell_length=%zd",
139
                actual_col_size,
140
                cell_length);
141
            cell_length = actual_col_size;
×
142
        }
143
        const auto padding = actual_col_size - cell_length;
4,438✔
144
        auto lpadding = 0;
4,438✔
145
        auto rpadding = padding;
4,438✔
146
        switch (align) {
4,438✔
147
            case text_align_t::start:
2,007✔
148
                break;
2,007✔
149
            case text_align_t::center: {
1✔
150
                lpadding = padding / 2;
1✔
151
                rpadding = padding - lpadding;
1✔
152
                break;
1✔
153
            }
154
            case text_align_t::end:
2,430✔
155
                lpadding = padding;
2,430✔
156
                rpadding = 0;
2,430✔
157
                break;
2,430✔
158
        }
159
        this->dls_cell_width[lpc] = al.al_string.length() + padding;
4,438✔
160
        label_out.append(lpadding, ' ');
4,438✔
161
        shift_string_attrs(al.al_attrs, 0, label_out.size());
4,438✔
162
        label_out.append(std::move(al.al_string));
4,438✔
163
        label_out.append(rpadding, ' ');
4,438✔
164
        label_out.push_back(' ');
4,438✔
165

166
        this->dls_ansi_attrs.insert(
8,876✔
167
            this->dls_ansi_attrs.end(),
4,438✔
168
            std::make_move_iterator(al.al_attrs.begin()),
169
            std::make_move_iterator(al.al_attrs.end()));
170
    }
4,438✔
171
    if (row_level.has_value()) {
998✔
172
        this->dls_ansi_attrs.emplace_back(line_range{0, -1},
119✔
173
                                          SA_LEVEL.value(row_level.value()));
238✔
174
    }
175
    this->dls_ansi_attrs.reserve(this->dls_ansi_attrs.size()
998✔
176
                                 + 3 * this->dls_headers.size());
998✔
177
    this->dls_cell_allocator.reset();
998✔
178

179
    return {};
998✔
180
}
181

182
void
183
db_label_source::text_attrs_for_line(textview_curses& tc,
998✔
184
                                     int row,
185
                                     string_attrs_t& sa)
186
{
187
    static const auto NUM_ATTR = VC_ROLE.value(role_t::VCR_NUMBER);
998✔
188
    static const auto VLINE_ATTR = VC_GRAPHIC.value(NCACS_VLINE);
998✔
189

190
    line_range lr(0, 0);
998✔
191
    const line_range lr2(0, -1);
998✔
192

193
    if (row < 0_vl || row >= (int) this->dls_row_cursors.size()) {
998✔
194
        return;
×
195
    }
196
    sa = std::move(this->dls_ansi_attrs);
998✔
197
    auto alt_row_index = row % 4;
998✔
198
    if (alt_row_index == 2 || alt_row_index == 3) {
998✔
199
        sa.emplace_back(lr2, VC_ROLE.value(role_t::VCR_ALT_ROW));
377✔
200
    }
201
    sa.emplace_back(line_range{0, 0}, SA_ORIGINAL_LINE.value());
998✔
202
    sa.emplace_back(line_range{0, 0}, SA_BODY.value());
998✔
203
    for (size_t lpc = 0; lpc < this->dls_headers.size() - 1; lpc++) {
4,447✔
204
        if (lpc == this->dls_row_style_column
3,449✔
205
            && !this->dls_row_styles_have_errors)
×
206
        {
207
            continue;
×
208
        }
209

210
        const auto& hm = this->dls_headers[lpc];
3,449✔
211
        if (hm.hm_hidden) {
3,449✔
212
            continue;
3✔
213
        }
214

215
        if (hm.is_graphable()) {
3,446✔
216
            lr.lr_end += this->dls_cell_width[lpc];
717✔
217
            sa.emplace_back(lr, NUM_ATTR);
717✔
218
        }
219
        lr.lr_start += this->dls_cell_width[lpc];
3,446✔
220
        lr.lr_end = lr.lr_start + 1;
3,446✔
221
        sa.emplace_back(lr, VLINE_ATTR);
3,446✔
222
        lr.lr_start += 1;
3,446✔
223
    }
224

225
    for (const auto& attr : sa) {
7,804✔
226
        require_ge(attr.sa_range.lr_start, 0);
6,806✔
227
    }
228
    int cell_start = 0;
998✔
229
    auto cursor = this->dls_row_cursors[row].sync();
998✔
230
    for (size_t lpc = 0; lpc < this->dls_headers.size();
5,445✔
231
         lpc++, cursor = cursor->next())
4,447✔
232
    {
233
        std::optional<text_attrs> user_attrs;
4,447✔
234

235
        if (lpc == this->dls_row_style_column) {
4,447✔
236
            if (!this->dls_row_styles_have_errors) {
9✔
237
                continue;
9✔
238
            }
239
        }
240

241
        const auto& hm = this->dls_headers[lpc];
4,441✔
242
        if (hm.hm_hidden) {
4,441✔
243
            continue;
3✔
244
        }
245
        if (row < (ssize_t) this->dls_row_styles.size()) {
4,438✔
246
            auto style_opt
247
                = this->dls_row_styles[row].rs_column_config.value_for(lpc);
18✔
248
            if (style_opt) {
18✔
249
                user_attrs = *style_opt.value();
6✔
250
            }
251
        }
252

253
        int left = cell_start;
4,438✔
254
        auto stlr = line_range{
255
            cell_start,
256
            (int) (cell_start + this->dls_cell_width[lpc]),
8,876✔
257
        };
4,438✔
258
        if (hm.is_graphable()) {
4,438✔
259
            std::optional<double> get_res;
1,075✔
260
            if (cursor->get_type() == lnav::cell_type::CT_INTEGER) {
1,075✔
261
                get_res = cursor->get_int();
768✔
262
            } else if (cursor->get_type() == lnav::cell_type::CT_FLOAT) {
307✔
263
                get_res = cursor->get_float();
307✔
264
            }
265
            if (get_res.has_value()) {
1,075✔
266
                hm.hm_chart.chart_attrs_for_value(tc,
1,075✔
267
                                                  left,
268
                                                  this->dls_cell_width[lpc],
1,075✔
269
                                                  hm.hm_name,
1,075✔
270
                                                  get_res.value(),
1,075✔
271
                                                  sa,
272
                                                  user_attrs);
273

274
                for (const auto& attr : sa) {
19,163✔
275
                    require_ge(attr.sa_range.lr_start, 0);
18,088✔
276
                }
277
            }
278
        } else if (user_attrs.has_value()) {
3,363✔
279
            sa.emplace_back(stlr, VC_STYLE.value(user_attrs.value()));
3✔
280
        }
281
        auto cell_sf = string_fragment::invalid();
4,438✔
282
        if (cursor->get_type() == lnav::cell_type::CT_TEXT) {
4,438✔
283
            cell_sf = cursor->get_text();
1,642✔
284
        } else if (cursor->get_type() == lnav::cell_type::CT_NULL) {
2,796✔
285
            sa.emplace_back(stlr, VC_ROLE.value(role_t::VCR_NULL));
1,006✔
286
        }
287
        if (lpc == this->dls_row_style_column) {
4,438✔
288
            sa.emplace_back(stlr, VC_ROLE.value(role_t::VCR_ERROR));
3✔
289
        } else if (cell_sf.is_valid() && cell_sf.length() > 2
6,074✔
290
                   && cell_sf.length() < MAX_JSON_WIDTH
1,398✔
291
                   && ((cell_sf.front() == '{' && cell_sf.back() == '}')
7,415✔
292
                       || (cell_sf.front() == '[' && cell_sf.back() == ']')))
1,341✔
293
        {
294
            auto cb = [&](const std::string& ptr, const scoped_value_t& sv) {
181✔
295
                auto val_opt = to_double(sv);
181✔
296
                if (val_opt) {
181✔
297
                    hm.hm_chart.chart_attrs_for_value(tc,
126✔
298
                                                      left,
299
                                                      this->dls_cell_width[lpc],
63✔
300
                                                      ptr,
301
                                                      val_opt.value(),
63✔
302
                                                      sa);
303
                    for (const auto& attr : sa) {
573✔
304
                        require_ge(attr.sa_range.lr_start, 0);
510✔
305
                    }
306
                }
307
            };
181✔
308
            json_ptr_walk jpw(cb);
112✔
309

310
            jpw.parse_fully(cell_sf);
112✔
311
        }
112✔
312
        cell_start += this->dls_cell_width[lpc] + 1;
4,438✔
313
    }
314

315
    for (const auto& attr : sa) {
9,639✔
316
        require_ge(attr.sa_range.lr_start, 0);
8,641✔
317
    }
318
}
319

320
void
321
db_label_source::set_col_as_graphable(int lpc)
711✔
322
{
323
    static auto& vc = view_colors::singleton();
711✔
324

325
    auto& hm = this->dls_headers[lpc];
711✔
326
    auto name_for_ident_attrs = hm.hm_name;
711✔
327
    auto attrs = vc.attrs_for_ident(name_for_ident_attrs);
711✔
328
    for (size_t attempt = 0; hm.hm_chart.attrs_in_use(attrs) && attempt < 3;
711✔
329
         attempt++)
330
    {
331
        name_for_ident_attrs += " ";
×
332
        attrs = vc.attrs_for_ident(name_for_ident_attrs);
×
333
    }
334
    hm.hm_graphable = true;
711✔
335
    hm.hm_chart.with_attrs_for_ident(hm.hm_name, attrs);
711✔
336
    hm.hm_title_attrs = attrs | text_attrs::with_reverse();
711✔
337
    hm.hm_column_size = std::max(hm.hm_column_size, size_t{10});
711✔
338
}
711✔
339

340
void
341
db_label_source::push_header(const std::string& colstr, int type)
3,049✔
342
{
343
    this->dls_headers.emplace_back(colstr);
3,049✔
344
    this->dls_cell_width.push_back(0);
3,049✔
345

346
    auto& hm = this->dls_headers.back();
3,049✔
347

348
    hm.hm_column_size = utf8_string_length(colstr).unwrapOr(colstr.length());
3,049✔
349
    hm.hm_column_type = type;
3,049✔
350
    if (colstr == "log_time" || colstr == "min(log_time)"
6,030✔
351
        || colstr == "log_time_msecs")
6,030✔
352
    {
353
        this->dls_time_column_index = this->dls_headers.size() - 1;
74✔
354
    }
355
    if (colstr == "__lnav_style__") {
3,049✔
356
        this->dls_row_style_column = this->dls_headers.size() - 1;
3✔
357
    }
358
    if (colstr == "log_level") {
3,049✔
359
        this->dls_level_column = this->dls_headers.size() - 1;
54✔
360
    }
361
    hm.hm_chart.with_show_state(stacked_bar_chart_base::show_all{});
3,049✔
362
}
3,049✔
363

364
void
365
db_label_source::update_time_column(const timeval& tv)
317✔
366
{
367
    if (!this->dls_time_column.empty() && tv < this->dls_time_column.back()) {
317✔
368
        this->dls_time_column_invalidated_at = this->dls_time_column.size();
1✔
369
        this->dls_time_column_index = SIZE_MAX;
1✔
370
        this->dls_time_column.clear();
1✔
371
    } else {
372
        this->dls_time_column.push_back(tv);
316✔
373
    }
374
}
317✔
375

376
void
377
db_label_source::update_time_column(const string_fragment& sf)
296✔
378
{
379
    date_time_scanner dts;
296✔
380
    timeval tv;
381

382
    if (!dts.convert_to_timeval(sf.data(), sf.length(), nullptr, tv)) {
296✔
383
        tv.tv_sec = -1;
×
384
        tv.tv_usec = -1;
×
385
    }
386
    this->update_time_column(tv);
296✔
387
}
296✔
388

389
void
390
db_label_source::push_column(const column_value_t& sv)
9,184✔
391
{
392
    auto row_index = this->dls_row_cursors.size() - 1;
9,184✔
393
    auto& vc = view_colors::singleton();
9,184✔
394
    auto col = this->dls_push_column++;
9,184✔
395
    auto& hm = this->dls_headers[col];
9,184✔
396
    size_t width = 1;
9,184✔
397
    auto cv_sf = string_fragment::invalid();
9,184✔
398

399
    sv.match(
9,184✔
400
        [this, &col, &width, &cv_sf, &hm, &row_index](
×
401
            const string_fragment& sf) {
402
            if (this->dls_row_style_column == col) {
4,090✔
403
                return;
9✔
404
            }
405
            if (col == this->dls_time_column_index) {
4,081✔
406
                this->update_time_column(sf);
296✔
407
            } else if (this->dls_level_column
7,570✔
408
                       && this->dls_level_column.value() == col
5,100✔
409
                       && this->tss_view != nullptr)
5,100✔
410
            {
411
                auto& bm = this->tss_view->get_bookmarks();
216✔
412
                auto lev = string2level(sf.data(), sf.length());
216✔
413
                switch (lev) {
216✔
414
                    case log_level_t::LEVEL_FATAL:
36✔
415
                    case log_level_t::LEVEL_CRITICAL:
416
                    case log_level_t::LEVEL_ERROR:
417
                        bm[&textview_curses::BM_ERRORS].insert_once(
72✔
418
                            vis_line_t(row_index));
36✔
419
                        break;
36✔
420
                    case log_level_t::LEVEL_WARNING:
6✔
421
                        bm[&textview_curses::BM_WARNINGS].insert_once(
12✔
422
                            vis_line_t(row_index));
6✔
423
                        break;
6✔
424
                    default:
174✔
425
                        break;
174✔
426
                }
427
            }
428
            width = utf8_string_length(sf.data(), sf.length())
4,081✔
429
                        .unwrapOr(sf.length());
4,081✔
430
            if (hm.is_graphable()
4,081✔
431
                && sf.length() < lnav::cell_container::SHORT_TEXT_LENGTH)
4,081✔
432
            {
433
                auto from_res = humanize::try_from<double>(sf);
382✔
434
                if (from_res.has_value()) {
382✔
435
                    this->dls_cell_container.push_float_with_units_cell(
764✔
436
                        from_res.value(), sf);
382✔
437
                } else {
438
                    this->dls_cell_container.push_text_cell(sf);
×
439
                }
440
            } else {
441
                this->dls_cell_container.push_text_cell(sf);
3,699✔
442
            }
443
            cv_sf = sf;
4,081✔
444
        },
445
        [this, col, &width](int64_t i) {
×
446
            width = count_digits(i);
2,690✔
447
            this->dls_cell_container.push_int_cell(i);
2,690✔
448
            if (col == this->dls_time_column_index) {
2,690✔
449
                auto ms = std::chrono::milliseconds{i};
21✔
450
                auto us
451
                    = std::chrono::duration_cast<std::chrono::microseconds>(ms);
21✔
452

453
                this->update_time_column(to_timeval(us));
21✔
454
            }
455
        },
2,690✔
456
        [this, &width](double d) {
×
457
            char buffer[1];
458
            auto fmt_res = fmt::format_to_n(buffer, 0, FMT_STRING("{}"), d);
693✔
459
            width = fmt_res.size;
231✔
460
            this->dls_cell_container.push_float_cell(d);
231✔
461
        },
231✔
462
        [this, &width](null_value_t) {
9,184✔
463
            width = 6;
2,173✔
464
            this->dls_cell_container.push_null_cell();
2,173✔
465
        });
2,173✔
466

467
    if (col == this->dls_row_style_column) {
9,184✔
468
        auto col_sf = string_fragment::invalid();
9✔
469
        if (sv.is<null_value_t>()) {
9✔
470
            this->dls_row_styles.emplace_back(row_style{});
×
471
        } else if (sv.is<string_fragment>()) {
9✔
472
            static const intern_string_t SRC
473
                = intern_string::lookup("__lnav_style__");
15✔
474
            auto frag = sv.get<string_fragment>();
9✔
475
            if (frag.empty()) {
9✔
476
                this->dls_row_styles.emplace_back(row_style{});
×
477
            } else {
478
                auto parse_res
479
                    = get_row_style_handlers().parser_for(SRC).of(frag);
9✔
480
                if (parse_res.isErr()) {
9✔
481
                    log_error("DB row %zu JSON is invalid:", row_index);
×
482
                    auto errors = parse_res.unwrapErr();
×
483
                    for (const auto& err : errors) {
×
484
                        log_error("  %s", err.to_attr_line().al_string.c_str());
×
485
                    }
486
                    col_sf = string_fragment::from_str(
×
487
                                 errors[0].to_attr_line().al_string)
×
488
                                 .to_owned(this->dls_cell_allocator);
×
489
                    this->dls_row_styles_have_errors = true;
×
490
                } else {
×
491
                    auto urs = parse_res.unwrap();
9✔
492
                    auto rs = row_style{};
9✔
493
                    for (const auto& [col_name, col_style] :
18✔
494
                         urs.urs_column_config)
27✔
495
                    {
496
                        auto col_index_opt
497
                            = this->column_name_to_index(col_name);
9✔
498
                        if (!col_index_opt) {
9✔
499
                            log_error("DB row %zu column name '%s' not found",
3✔
500
                                      row_index,
501
                                      col_name.c_str());
502
                            col_sf = string_fragment::from_str(
×
503
                                         fmt::format(
3✔
504
                                             FMT_STRING(
9✔
505
                                                 "column name '{}' not found"),
506
                                             col_name))
507
                                         .to_owned(this->dls_cell_allocator);
3✔
508
                            this->dls_row_styles_have_errors = true;
3✔
509
                        } else {
510
                            text_attrs ta;
6✔
511

512
                            auto fg_res = styling::color_unit::from_str(
513
                                col_style.sc_color);
6✔
514
                            if (fg_res.isErr()) {
6✔
515
                                log_error("DB row %zu color is invalid: %s",
×
516
                                          row_index,
517
                                          fg_res.unwrapErr().c_str());
518
                                col_sf
519
                                    = string_fragment::from_str(
×
520
                                          fmt::format(
×
521
                                              FMT_STRING("invalid color: {}"),
×
522
                                              fg_res.unwrapErr()))
×
523
                                          .to_owned(this->dls_cell_allocator);
×
524
                                this->dls_row_styles_have_errors = true;
×
525
                            } else {
526
                                ta.ta_fg_color
527
                                    = vc.match_color(fg_res.unwrap());
6✔
528
                            }
529
                            auto bg_res = styling::color_unit::from_str(
530
                                col_style.sc_background_color);
6✔
531
                            if (bg_res.isErr()) {
6✔
532
                                log_error(
×
533
                                    "DB row %zu background-color is invalid: "
534
                                    "%s",
535
                                    row_index,
536
                                    bg_res.unwrapErr().c_str());
537
                                col_sf
538
                                    = string_fragment::from_str(
×
539
                                          fmt::format(
×
540
                                              FMT_STRING(
×
541
                                                  "invalid "
542
                                                  "background-color: {}"),
543
                                              fg_res.unwrapErr()))
×
544
                                          .to_owned(this->dls_cell_allocator);
×
545
                                this->dls_row_styles_have_errors = true;
×
546
                            } else {
547
                                ta.ta_bg_color
548
                                    = vc.match_color(bg_res.unwrap());
6✔
549
                            }
550
                            ta.ta_align = col_style.sc_text_align;
6✔
551
                            if (col_style.sc_underline) {
6✔
552
                                ta |= text_attrs::style::underline;
×
553
                            }
554
                            if (col_style.sc_bold) {
6✔
555
                                ta |= text_attrs::style::bold;
×
556
                            }
557
                            if (col_style.sc_italic) {
6✔
558
                                ta |= text_attrs::style::italic;
×
559
                            }
560
                            if (col_style.sc_strike) {
6✔
561
                                ta |= text_attrs::style::struck;
×
562
                            }
563
                            if (this->dls_headers[col_index_opt.value()]
6✔
564
                                    .is_graphable())
6✔
565
                            {
566
                                this->dls_headers[col_index_opt.value()]
3✔
567
                                    .hm_title_attrs
568
                                    = text_attrs::with_underline();
6✔
569
                            }
570
                            rs.rs_column_config[col_index_opt.value()] = ta;
6✔
571
                        }
6✔
572
                    }
573
                    this->dls_row_styles.emplace_back(std::move(rs));
9✔
574
                }
9✔
575
            }
9✔
576
        } else {
577
            log_error("DB row %zu is not a string -- %s",
×
578
                      row_index,
579
                      mapbox::util::apply_visitor(type_visitor(), sv));
580

581
            col_sf
582
                = string_fragment::from_str("expecting a JSON object for style")
×
583
                      .to_owned(this->dls_cell_allocator);
×
584
            this->dls_row_styles_have_errors = true;
×
585
        }
586

587
        if (col_sf.empty()) {
9✔
588
            this->dls_cell_container.push_null_cell();
6✔
589
        } else {
590
            this->dls_cell_container.push_text_cell(col_sf);
3✔
591
            width = utf8_string_length(col_sf.data(), col_sf.length())
3✔
592
                        .unwrapOr(col_sf.length());
3✔
593
            this->dls_cell_allocator.reset();
3✔
594
        }
595
    }
596

597
    hm.hm_column_size = std::max(this->dls_headers[col].hm_column_size, width);
9,184✔
598
    if (hm.is_graphable()) {
9,184✔
599
        if (sv.is<int64_t>()) {
2,018✔
600
            hm.hm_chart.add_value(hm.hm_name, sv.get<int64_t>());
1,409✔
601
            hm.hm_tdigest.insert(sv.get<int64_t>());
1,409✔
602
        } else if (sv.is<double>()) {
609✔
603
            hm.hm_chart.add_value(hm.hm_name, sv.get<double>());
221✔
604
            hm.hm_tdigest.insert(sv.get<double>());
221✔
605
        } else if (sv.is<string_fragment>()) {
388✔
606
            auto sf = sv.get<string_fragment>();
382✔
607
            auto num_from_res = humanize::try_from<double>(sf);
382✔
608
            if (num_from_res) {
382✔
609
                hm.hm_chart.add_value(hm.hm_name, num_from_res.value());
382✔
610
                hm.hm_tdigest.insert(num_from_res.value());
382✔
611
            }
612
        }
613
    } else if (cv_sf.is_valid() && cv_sf.length() > 2
10,865✔
614
               && ((cv_sf.startswith("{") && cv_sf.endswith("}"))
13,907✔
615
                   || (cv_sf.startswith("[") && cv_sf.endswith("]"))))
3,042✔
616
    {
617
        auto cb = [this, &hm, &vc](const std::string& ptr,
1,070✔
618
                                   const scoped_value_t& sv) {
619
            auto ptr_sf = string_fragment::from_str(ptr);
1,070✔
620
            auto iter = hm.hm_json_columns.find(ptr_sf);
1,070✔
621
            if (iter == hm.hm_json_columns.end()) {
1,070✔
622
                auto owned_ptr_sf = ptr_sf.to_owned(this->dls_header_allocator);
888✔
623
                iter = hm.hm_json_columns
1,776✔
624
                           .emplace(owned_ptr_sf, hm.hm_json_columns.size())
888✔
625
                           .first;
626
            }
627
            if (sv.is<int64_t>()) {
1,070✔
628
                auto val = sv.get<int64_t>();
334✔
629
                auto& ci = hm.hm_chart.add_value(ptr, val);
334✔
630
                if (ci.ci_attrs.empty()) {
334✔
631
                    ci.ci_attrs = vc.attrs_for_ident(ptr);
312✔
632
                }
633
            } else if (sv.is<double>()) {
736✔
634
                auto val = sv.get<double>();
35✔
635
                auto& ci = hm.hm_chart.add_value(ptr, val);
35✔
636
                if (ci.ci_attrs.empty()) {
35✔
637
                    ci.ci_attrs = vc.attrs_for_ident(ptr);
35✔
638
                }
639
            }
640
        };
1,070✔
641
        json_ptr_walk jpw(cb);
388✔
642

643
        jpw.parse_fully(cv_sf);
388✔
644
    }
388✔
645
    hm.hm_chart.next_row();
9,184✔
646
}
9,184✔
647

648
void
649
db_label_source::clear()
2,655✔
650
{
651
    this->dls_generation += 1;
2,655✔
652
    this->dls_query_start = std::nullopt;
2,655✔
653
    this->dls_query_end = std::nullopt;
2,655✔
654
    this->dls_headers.clear();
2,655✔
655
    this->dls_row_cursors.clear();
2,655✔
656
    this->dls_cell_container.reset();
2,655✔
657
    this->dls_time_column.clear();
2,655✔
658
    this->dls_time_column_index = SIZE_MAX;
2,655✔
659
    this->dls_cell_width.clear();
2,655✔
660
    this->dls_row_styles.clear();
2,655✔
661
    this->dls_row_styles_have_errors = false;
2,655✔
662
    this->dls_row_style_column = SIZE_MAX;
2,655✔
663
    this->dls_level_column = std::nullopt;
2,655✔
664
    this->dls_cell_allocator.reset();
2,655✔
665
    this->dls_header_allocator.reset();
2,655✔
666
    this->dls_step_rc = SQLITE_OK;
2,655✔
667
    if (this->tss_view != nullptr) {
2,655✔
668
        this->tss_view->get_bookmarks().clear();
333✔
669
    }
670
}
2,655✔
671

672
std::optional<size_t>
673
db_label_source::column_name_to_index(const std::string& name) const
15✔
674
{
675
    return this->dls_headers | lnav::itertools::find(name);
15✔
676
}
677

678
std::optional<vis_line_t>
679
db_label_source::row_for_time(timeval time_bucket)
5✔
680
{
681
    const auto iter = std::lower_bound(this->dls_time_column.begin(),
5✔
682
                                       this->dls_time_column.end(),
683
                                       time_bucket);
684
    if (iter != this->dls_time_column.end()) {
5✔
685
        return vis_line_t(std::distance(this->dls_time_column.begin(), iter));
8✔
686
    }
687
    return std::nullopt;
1✔
688
}
689

690
std::optional<text_time_translator::row_info>
691
db_label_source::time_for_row(vis_line_t row)
306✔
692
{
693
    if ((row < 0_vl) || (((size_t) row) >= this->dls_time_column.size())) {
306✔
694
        return std::nullopt;
250✔
695
    }
696

697
    return row_info{this->dls_time_column[row], row};
56✔
698
}
699

700
bool
UNCOV
701
db_label_source::text_handle_mouse(
×
702
    textview_curses& tc,
703
    const listview_curses::display_line_content_t&,
704
    mouse_event& me)
705
{
706
    if (tc.get_overlay_selection()) {
×
707
        auto nci = ncinput{};
×
708
        if (me.is_click_in(mouse_button_t::BUTTON_LEFT, 0, 3)) {
×
UNCOV
709
            nci.id = ' ';
×
UNCOV
710
            nci.eff_text[0] = ' ';
×
711
            this->list_input_handle_key(tc, nci);
×
712
        }
713
    }
UNCOV
714
    return true;
×
715
}
716

717
static constexpr string_attr_type<std::string> DBA_DETAILS("details");
718
static constexpr string_attr_type<std::string> DBA_COLUMN_NAME("column-name");
719

720
bool
721
db_label_source::list_input_handle_key(listview_curses& lv, const ncinput& ch)
×
722
{
723
    switch (ch.eff_text[0]) {
×
724
        case ' ': {
×
725
            auto ov_sel = lv.get_overlay_selection();
×
726
            if (ov_sel) {
×
727
                std::vector<attr_line_t> rows;
×
728
                auto* ov_source = lv.get_overlay_source();
×
729
                ov_source->list_value_for_overlay(
×
UNCOV
730
                    lv, lv.get_selection().value(), rows);
×
731
                if (ov_sel.value() < (ssize_t) rows.size()) {
×
732
                    auto& row_al = rows[ov_sel.value()];
×
733
                    auto col_attr
734
                        = get_string_attr(row_al.al_attrs, DBA_COLUMN_NAME);
×
735
                    if (col_attr) {
×
736
                        auto col_name = col_attr.value().get();
×
737
                        auto col_opt = this->column_name_to_index(col_name);
×
UNCOV
738
                        if (col_opt) {
×
UNCOV
739
                            this->dls_headers[col_opt.value()].hm_hidden
×
UNCOV
740
                                = !this->dls_headers[col_opt.value()].hm_hidden;
×
741
                        }
742
                    }
743
                }
UNCOV
744
                lv.set_needs_update();
×
745

UNCOV
746
                return true;
×
747
            }
UNCOV
748
            break;
×
749
        }
750
    }
751

UNCOV
752
    return false;
×
753
}
754

755
std::optional<json_string>
756
db_label_source::text_row_details(const textview_curses& tc)
3✔
757
{
758
    if (this->dls_row_cursors.empty()) {
3✔
UNCOV
759
        log_trace("db_label_source::text_row_details: empty");
×
UNCOV
760
        return std::nullopt;
×
761
    }
762
    if (!this->dls_query_end.has_value()) {
3✔
763
        log_trace("db_label_source::text_row_details: query in progress");
2✔
764
        return std::nullopt;
2✔
765
    }
766

767
    auto ov_sel = tc.get_overlay_selection();
1✔
768

769
    if (ov_sel.has_value()) {
1✔
770
        std::vector<attr_line_t> rows;
×
771
        auto* ov_source = tc.get_overlay_source();
×
772
        ov_source->list_value_for_overlay(tc, tc.get_selection().value(), rows);
×
773
        if (ov_sel.value() < (ssize_t) rows.size()) {
×
774
            auto& row_al = rows[ov_sel.value()];
×
775
            auto deets_attr = get_string_attr(row_al.al_attrs, DBA_DETAILS);
×
776
            if (deets_attr) {
×
777
                auto deets = deets_attr->get();
×
UNCOV
778
                if (!deets.empty()) {
×
UNCOV
779
                    return json_string(
×
UNCOV
780
                        auto_buffer::from(deets.c_str(), deets.length()));
×
781
                }
782
            }
783
        }
UNCOV
784
    } else {
×
785
        yajlpp_gen gen;
1✔
786

787
        {
788
            yajlpp_map root(gen);
1✔
789

790
            auto sel = tc.get_selection();
1✔
791
            if (sel) {
1✔
792
                root.gen("value");
1✔
793

794
                {
795
                    yajlpp_map value_map(gen);
1✔
796

797
                    auto cursor
798
                        = this->dls_row_cursors[tc.get_selection().value()]
1✔
799
                              .sync();
1✔
800
                    for (const auto& [col, hm] :
22✔
801
                         lnav::itertools::enumerate(this->dls_headers))
23✔
802
                    {
803
                        value_map.gen(hm.hm_name);
21✔
804

805
                        switch (cursor->get_type()) {
21✔
806
                            case lnav::cell_type::CT_NULL:
9✔
807
                                value_map.gen();
9✔
808
                                break;
9✔
809
                            case lnav::cell_type::CT_INTEGER:
5✔
810
                                value_map.gen(cursor->get_int());
5✔
811
                                break;
5✔
UNCOV
812
                            case lnav::cell_type::CT_FLOAT:
×
813
                                if (cursor->get_sub_value() == 0) {
×
UNCOV
814
                                    value_map.gen(cursor->get_float());
×
815
                                } else {
UNCOV
816
                                    value_map.gen(cursor->get_float_as_text());
×
817
                                }
UNCOV
818
                                break;
×
819
                            case lnav::cell_type::CT_TEXT:
7✔
820
                                value_map.gen(cursor->get_text());
7✔
821
                                break;
7✔
822
                        }
823
                        cursor = cursor->next();
21✔
824
                    }
825
                }
1✔
826
            }
827
        }
1✔
828

829
        return json_string{gen};
1✔
830
    }
1✔
831

UNCOV
832
    return std::nullopt;
×
833
}
834

835
std::string
836
db_label_source::get_row_as_string(vis_line_t row)
1,480✔
837
{
838
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())) {
1,480✔
UNCOV
839
        return "";
×
840
    }
841

842
    if (this->dls_headers.size() == 1) {
1,480✔
843
        return this->dls_row_cursors[row]
1,472✔
844
            .sync()
1,472✔
845
            .value()
1,472✔
846
            .to_string_fragment(this->dls_cell_allocator)
2,944✔
847
            .to_string();
1,472✔
848
    }
849

850
    std::string retval;
8✔
851
    size_t lpc = 0;
8✔
852
    auto cursor = this->dls_row_cursors[row].sync();
8✔
853
    while (lpc < this->dls_headers.size() && cursor.has_value()) {
32✔
854
        const auto& hm = this->dls_headers[lpc];
24✔
855

856
        if (!retval.empty()) {
24✔
857
            retval.append("; ");
16✔
858
        }
859
        retval.append(hm.hm_name);
24✔
860
        retval.push_back('=');
24✔
861
        auto sf = cursor->to_string_fragment(this->dls_cell_allocator);
24✔
862
        retval += sf;
24✔
863

864
        cursor = cursor->next();
24✔
865
        lpc += 1;
24✔
866
    }
867
    this->dls_cell_allocator.reset();
8✔
868

869
    return retval;
8✔
870
}
8✔
871

872
std::string
873
db_label_source::get_cell_as_string(vis_line_t row, size_t col)
×
874
{
875
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())
×
UNCOV
876
        || col >= this->dls_headers.size())
×
877
    {
878
        return "";
×
879
    }
880

881
    this->dls_cell_allocator.reset();
×
882
    size_t lpc = 0;
×
883
    auto cursor = this->dls_row_cursors[row].sync();
×
884
    while (cursor.has_value()) {
×
UNCOV
885
        if (lpc == col) {
×
UNCOV
886
            return cursor->to_string_fragment(this->dls_cell_allocator)
×
887
                .to_string();
×
888
        }
889

UNCOV
890
        cursor = cursor->next();
×
891
        lpc += 1;
×
892
    }
893

UNCOV
894
    return "";
×
895
}
896

897
std::optional<int64_t>
898
db_label_source::get_cell_as_int64(vis_line_t row, size_t col) const
×
899
{
900
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())
×
UNCOV
901
        || col >= this->dls_headers.size())
×
902
    {
903
        return std::nullopt;
×
904
    }
905

906
    size_t lpc = 0;
×
907
    auto cursor = this->dls_row_cursors[row].sync();
×
908
    while (cursor.has_value()) {
×
UNCOV
909
        if (lpc == col) {
×
910
            if (cursor->get_type() == lnav::cell_type::CT_INTEGER) {
×
UNCOV
911
                return cursor->get_int();
×
912
            }
913
            return std::nullopt;
×
914
        }
915

UNCOV
916
        cursor = cursor->next();
×
917
        lpc += 1;
×
918
    }
919

UNCOV
920
    return std::nullopt;
×
921
}
922

923
std::optional<double>
924
db_label_source::get_cell_as_double(vis_line_t row, size_t col) const
×
925
{
926
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())
×
UNCOV
927
        || col >= this->dls_headers.size())
×
928
    {
929
        return std::nullopt;
×
930
    }
931

932
    size_t lpc = 0;
×
933
    auto cursor = this->dls_row_cursors[row].sync();
×
934
    while (cursor.has_value()) {
×
935
        if (lpc == col) {
×
936
            switch (cursor->get_type()) {
×
937
                case lnav::cell_type::CT_INTEGER:
×
938
                    return cursor->get_int();
×
939
                case lnav::cell_type::CT_FLOAT:
×
UNCOV
940
                    return cursor->get_float();
×
UNCOV
941
                default:
×
UNCOV
942
                    return std::nullopt;
×
943
            }
944
        }
945

UNCOV
946
        cursor = cursor->next();
×
947
        lpc += 1;
×
948
    }
949

UNCOV
950
    return std::nullopt;
×
951
}
952

953
mapbox::util::variant<int64_t, double>
954
db_label_source::get_cell_as_numeric(vis_line_t row, size_t col) const
×
955
{
956
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())
×
UNCOV
957
        || col >= this->dls_headers.size())
×
958
    {
959
        return numeric_cell_t{mapbox::util::no_init{}};
×
960
    }
961

962
    size_t lpc = 0;
×
963
    auto cursor = this->dls_row_cursors[row].sync();
×
964
    while (cursor.has_value()) {
×
965
        if (lpc == col) {
×
966
            switch (cursor->get_type()) {
×
967
                case lnav::cell_type::CT_INTEGER:
×
968
                    return cursor->get_int();
×
969
                case lnav::cell_type::CT_FLOAT:
×
UNCOV
970
                    return cursor->get_float();
×
UNCOV
971
                default:
×
UNCOV
972
                    return numeric_cell_t{mapbox::util::no_init{}};
×
973
            }
974
        }
975

UNCOV
976
        cursor = cursor->next();
×
977
        lpc += 1;
×
978
    }
979

UNCOV
980
    return numeric_cell_t{mapbox::util::no_init{}};
×
981
}
982

983
void
984
db_label_source::reset_user_state()
6✔
985
{
986
    for (auto& hm : this->dls_headers) {
6✔
UNCOV
987
        hm.hm_hidden = false;
×
988
    }
989
}
6✔
990

991
std::optional<attr_line_t>
992
db_overlay_source::list_header_for_overlay(const listview_curses& lv,
×
993
                                           vis_line_t line)
994
{
995
    attr_line_t retval;
×
996

997
    retval.append("  Details for row ")
×
998
        .append(
×
999
            lnav::roles::number(fmt::format(FMT_STRING("{:L}"), (int) line)))
×
1000
        .append(". Press ")
×
1001
        .append("p"_hotkey)
×
1002
        .append(" to hide this panel.");
×
1003
    if (lv.get_overlay_selection()) {
×
1004
        retval.append(" Controls: ")
×
1005
            .append("c"_hotkey)
×
UNCOV
1006
            .append(" to copy a column value; ")
×
1007
            .append("SPC"_hotkey)
×
1008
            .append(" to hide/show a column");
×
1009
    } else {
UNCOV
1010
        retval.append("  Press ")
×
1011
            .append("CTRL-]"_hotkey)
×
UNCOV
1012
            .append(" to focus on this panel");
×
1013
    }
UNCOV
1014
    return retval;
×
1015
}
1016

1017
void
1018
db_overlay_source::list_value_for_overlay(const listview_curses& lv,
700✔
1019
                                          vis_line_t row,
1020
                                          std::vector<attr_line_t>& value_out)
1021
{
1022
    if (!this->dos_active || lv.get_inner_height() == 0) {
700✔
1023
        return;
700✔
1024
    }
1025

UNCOV
1026
    auto sel = lv.get_selection();
×
UNCOV
1027
    if (!sel || row != sel.value()) {
×
1028
        return;
×
1029
    }
1030

UNCOV
1031
    auto& vc = view_colors::singleton();
×
1032
    unsigned long width;
UNCOV
1033
    vis_line_t height;
×
1034

1035
    lv.get_dimensions(height, width);
×
1036

UNCOV
1037
    auto max_name_width = this->dos_labels->dls_headers
×
1038
        | lnav::itertools::map([](const auto& hm) { return hm.hm_name.size(); })
×
1039
        | lnav::itertools::max();
×
1040

UNCOV
1041
    auto cursor = this->dos_labels->dls_row_cursors[row].sync();
×
1042
    for (const auto& [col, hm] :
×
1043
         lnav::itertools::enumerate(this->dos_labels->dls_headers))
×
1044
    {
UNCOV
1045
        auto al = attr_line_t()
×
1046
                      .append(lnav::roles::h3(hm.hm_name))
×
1047
                      .right_justify(max_name_width.value_or(0) + 2);
×
1048

1049
        if (hm.hm_hidden) {
×
UNCOV
1050
            al.insert(1, "\u25c7"_comment);
×
1051
        } else {
UNCOV
1052
            al.insert(1, "\u25c6"_ok);
×
1053
        }
1054

1055
        auto sf
1056
            = cursor->to_string_fragment(this->dos_labels->dls_cell_allocator);
×
1057

1058
        al.al_attrs.emplace_back(line_range{0, -1},
×
UNCOV
1059
                                 DBA_COLUMN_NAME.value(hm.hm_name));
×
1060
        if (cursor->get_type() == lnav::cell_type::CT_TEXT
×
UNCOV
1061
            && (sf.startswith("[") || sf.startswith("{")))
×
1062
        {
1063
            auto parse_res = json_walk_collector::parse_fully(sf);
×
1064

1065
            if (parse_res.isOk()) {
×
UNCOV
1066
                auto jwc = parse_res.unwrap();
×
1067
                {
1068
                    yajlpp_gen gen;
×
1069

1070
                    {
1071
                        yajlpp_map root(gen);
×
1072

1073
                        root.gen("key");
×
UNCOV
1074
                        root.gen(hm.hm_name);
×
1075
                        root.gen("value");
×
1076
                        root.gen(sf);
×
1077
                    }
1078
                    al.al_attrs.emplace_back(
×
UNCOV
1079
                        line_range{0, -1},
×
1080
                        DBA_DETAILS.value(
×
1081
                            gen.to_string_fragment().to_string()));
×
1082
                }
1083
                value_out.emplace_back(al);
×
1084
                al.clear();
×
1085

1086
                stacked_bar_chart<std::string> chart;
×
1087
                int start_line = value_out.size();
×
1088

1089
                auto indent = 3 + max_name_width.value() - hm.hm_name.size();
×
UNCOV
1090
                chart.with_stacking_enabled(false)
×
1091
                    .with_margins(indent + 2, 0)
×
1092
                    .with_show_state(stacked_bar_chart_base::show_all{});
×
1093

UNCOV
1094
                for (const auto& [walk_index, jpw_value] :
×
1095
                     lnav::itertools::enumerate(jwc.jwc_values))
×
1096
                {
1097
                    {
1098
                        yajlpp_gen gen;
×
1099

1100
                        {
1101
                            yajlpp_map root(gen);
×
1102

1103
                            root.gen("key");
×
UNCOV
1104
                            root.gen(jpw_value.first);
×
1105
                            root.gen("value");
×
1106
                            root.gen(fmt::to_string(jpw_value.second));
×
1107
                        }
1108
                        al.al_attrs.emplace_back(
×
UNCOV
1109
                            line_range{0, -1},
×
UNCOV
1110
                            DBA_DETAILS.value(
×
1111
                                gen.to_string_fragment().to_string()));
×
1112
                    }
1113

1114
                    al.append(indent + 2, ' ')
×
UNCOV
1115
                        .append(lnav::roles::h5(jpw_value.first))
×
1116
                        .append(" = ")
×
1117
                        .append(fmt::to_string(jpw_value.second));
×
1118

1119
                    auto& sa = al.al_attrs;
×
UNCOV
1120
                    line_range lr(indent, indent + 1);
×
1121

UNCOV
1122
                    sa.emplace_back(
×
1123
                        lr,
1124
                        VC_GRAPHIC.value(walk_index < jwc.jwc_values.size() - 1
×
1125
                                             ? NCACS_LTEE
1126
                                             : NCACS_LLCORNER));
1127
                    lr.lr_start = indent + 2 + jpw_value.first.size() + 3;
×
1128
                    lr.lr_end = -1;
×
1129

UNCOV
1130
                    auto val_opt = to_double(jpw_value.second);
×
1131
                    if (val_opt) {
×
1132
                        auto attrs = vc.attrs_for_ident(jpw_value.first);
×
1133

UNCOV
1134
                        chart.add_value(jpw_value.first, val_opt.value());
×
1135
                        chart.with_attrs_for_ident(jpw_value.first, attrs);
×
1136
                        sa.emplace_back(lr, VC_ROLE.value(role_t::VCR_NUMBER));
×
1137
                    }
UNCOV
1138
                    value_out.emplace_back(al);
×
1139
                    al.clear();
×
1140
                }
1141

1142
                int curr_line = start_line;
×
UNCOV
1143
                for (auto iter = jwc.jwc_values.begin();
×
1144
                     iter != jwc.jwc_values.end();
×
1145
                     ++iter, curr_line++)
×
1146
                {
UNCOV
1147
                    auto val_opt = to_double(iter->second);
×
UNCOV
1148
                    if (!val_opt) {
×
1149
                        continue;
×
1150
                    }
1151

1152
                    auto& sa = value_out[curr_line].get_attrs();
×
UNCOV
1153
                    int left = indent + 2;
×
1154
                    chart.chart_attrs_for_value(
×
1155
                        lv, left, width, iter->first, val_opt.value(), sa);
×
1156
                }
UNCOV
1157
            } else {
×
1158
                yajlpp_gen gen;
×
1159

1160
                {
1161
                    yajlpp_map root(gen);
×
1162

1163
                    root.gen("key");
×
UNCOV
1164
                    root.gen(hm.hm_name);
×
1165
                    root.gen("value");
×
1166
                    root.gen(sf);
×
1167
                }
1168
                al.append(": ").append(sf);
×
UNCOV
1169
                al.al_attrs.emplace_back(
×
1170
                    line_range{0, -1},
×
1171
                    DBA_DETAILS.value(gen.to_string_fragment().to_string()));
×
1172
            }
UNCOV
1173
        } else {
×
1174
            yajlpp_gen gen;
×
1175

1176
            {
1177
                yajlpp_map root(gen);
×
1178

1179
                root.gen("key");
×
1180
                root.gen(hm.hm_name);
×
1181
                root.gen("value");
×
1182
                switch (cursor->get_type()) {
×
1183
                    case lnav::cell_type::CT_NULL:
×
1184
                        root.gen();
×
1185
                        break;
×
1186
                    case lnav::cell_type::CT_INTEGER:
×
1187
                        root.gen(cursor->get_int());
×
1188
                        break;
×
UNCOV
1189
                    case lnav::cell_type::CT_FLOAT:
×
1190
                        if (cursor->get_sub_value() == 0) {
×
UNCOV
1191
                            root.gen(cursor->get_float());
×
1192
                        } else {
1193
                            root.gen(cursor->get_float_as_text());
×
1194
                        }
1195
                        break;
×
UNCOV
1196
                    case lnav::cell_type::CT_TEXT:
×
UNCOV
1197
                        root.gen(cursor->get_text());
×
UNCOV
1198
                        break;
×
1199
                }
1200
            }
1201

1202
            auto value_al = attr_line_t::from_table_cell_content(sf, 1000);
×
1203
            al.append(": ").append(value_al);
×
UNCOV
1204
            al.al_attrs.emplace_back(
×
UNCOV
1205
                line_range{0, -1},
×
1206
                DBA_DETAILS.value(gen.to_string_fragment().to_string()));
×
1207
        }
1208

1209
        if (!al.empty()) {
×
UNCOV
1210
            value_out.emplace_back(al);
×
1211
        }
1212
        cursor = cursor->next();
×
1213
    }
1214

UNCOV
1215
    this->dos_labels->dls_cell_allocator.reset();
×
1216
}
1217

1218
bool
1219
db_overlay_source::list_static_overlay(const listview_curses& lv,
319✔
1220
                                       media_t media,
1221
                                       int y,
1222
                                       int bottom,
1223
                                       attr_line_t& value_out)
1224
{
1225
    if (y != 0) {
319✔
1226
        return false;
99✔
1227
    }
1228

1229
    auto& line = value_out.get_string();
220✔
1230
    const auto* dls = this->dos_labels;
220✔
1231
    auto& sa = value_out.get_attrs();
220✔
1232

1233
    for (size_t lpc = 0; lpc < this->dos_labels->dls_headers.size(); lpc++) {
1,241✔
1234
        if (lpc == this->dos_labels->dls_row_style_column
1,021✔
1235
            && !this->dos_labels->dls_row_styles_have_errors)
3✔
1236
        {
1237
            continue;
3✔
1238
        }
1239

1240
        const auto& hm = dls->dls_headers[lpc];
1,019✔
1241
        if (hm.hm_hidden) {
1,019✔
1242
            continue;
1✔
1243
        }
1244
        auto actual_col_size
1245
            = std::min(dls->dls_max_column_width, hm.hm_column_size);
1,018✔
1246
        auto cell_title = hm.hm_name;
1,018✔
1247
        string_attrs_t cell_attrs;
1,018✔
1248
        scrub_ansi_string(cell_title, &cell_attrs);
1,018✔
1249
        truncate_to(cell_title, dls->dls_max_column_width);
1,018✔
1250

1251
        auto cell_length
1252
            = utf8_string_length(cell_title).unwrapOr(actual_col_size);
1,018✔
1253
        int total_fill = actual_col_size - cell_length;
1,018✔
1254
        auto line_len_before = line.length();
1,018✔
1255

1256
        int before = total_fill / 2;
1,018✔
1257
        total_fill -= before;
1,018✔
1258
        line.append(before, ' ');
1,018✔
1259
        shift_string_attrs(cell_attrs, 0, line.size());
1,018✔
1260
        line.append(cell_title);
1,018✔
1261
        line.append(total_fill, ' ');
1,018✔
1262
        auto header_range = line_range(line_len_before, line.length());
1,018✔
1263

1264
        line.append(1, ' ');
1,018✔
1265

1266
        require_ge(header_range.lr_start, 0);
1,018✔
1267

1268
        sa.emplace_back(header_range, VC_STYLE.value(hm.hm_title_attrs));
1,018✔
1269
        sa.insert(sa.end(), cell_attrs.begin(), cell_attrs.end());
1,018✔
1270
    }
1,018✔
1271

1272
    line_range lr(0);
220✔
1273

1274
    sa.emplace_back(
220✔
1275
        lr,
1276
        VC_STYLE.value(text_attrs::with_styles(text_attrs::style::bold,
440✔
1277
                                               text_attrs::style::underline)));
1278
    return true;
220✔
1279
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc