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

tstack / lnav / 25176890854-3015

30 Apr 2026 04:20PM UTC coverage: 69.248% (+0.005%) from 69.243%
25176890854-3015

push

github

tstack
[views] move zoom stuff to text_time_translator

This adds support for zooming in the DB view.

Related to #1675

116 of 168 new or added lines in 14 files covered. (69.05%)

6 existing lines in 4 files now uncovered.

54401 of 78560 relevant lines covered (69.25%)

565148.14 hits per line

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

58.6
/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/func_util.hh"
38
#include "base/humanize.hh"
39
#include "base/itertools.enumerate.hh"
40
#include "base/itertools.hh"
41
#include "base/map_util.hh"
42
#include "base/math_util.hh"
43
#include "base/time_util.hh"
44
#include "base/types.hh"
45
#include "command_executor.hh"
46
#include "config.h"
47
#include "hist_source_T.hh"
48
#include "lnav_util.hh"
49
#include "log_level.hh"
50
#include "scn/scan.h"
51
#include "yajlpp/json_ptr.hh"
52
#include "yajlpp/yajlpp_def.hh"
53

54
using namespace lnav::roles::literals;
55

56
const unsigned char db_label_source::NULL_STR[] = "<NULL>";
57

58
constexpr ssize_t MAX_JSON_WIDTH = 16 * 1024;
59

60
struct user_row_style {
61
    lnav::map::small<std::string, style_config> urs_column_config;
62
};
63

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

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

79
    return retval;
9✔
80
}
12✔
81

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

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

117
        if (row < (int) this->dls_row_styles.size()) {
4,529✔
118
            auto style_opt
119
                = this->dls_row_styles[row].rs_column_config.value_for(lpc);
18✔
120
            if (style_opt && style_opt.value()->ta_align.has_value()) {
18✔
121
                align = style_opt.value()->ta_align.value();
3✔
122
            }
123
        }
124

125
        auto sf = cell_cursor->to_string_fragment(this->dls_cell_allocator);
4,529✔
126
        auto al = attr_line_t::from_table_cell_content(
127
            sf, this->dls_max_column_width);
4,529✔
128

129
        if (this->tss_view != nullptr
9,058✔
130
            && cell_cursor->get_type() == lnav::cell_type::CT_TEXT)
4,529✔
131
        {
132
            this->tss_view->apply_highlights(
1,108✔
133
                al, line_range::empty_at(0), line_range::empty_at(0));
2,216✔
134
        }
135
        if (this->dls_level_column && lpc == this->dls_level_column.value()) {
4,529✔
136
            row_level = string2level(sf.data(), sf.length());
121✔
137
        }
138

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

170
        this->dls_ansi_attrs.insert(
9,058✔
171
            this->dls_ansi_attrs.end(),
4,529✔
172
            std::make_move_iterator(al.al_attrs.begin()),
173
            std::make_move_iterator(al.al_attrs.end()));
174
    }
4,529✔
175
    if (row_level.has_value()) {
1,023✔
176
        this->dls_ansi_attrs.emplace_back(line_range{0, -1},
121✔
177
                                          SA_LEVEL.value(row_level.value()));
242✔
178
    }
179
    this->dls_ansi_attrs.reserve(this->dls_ansi_attrs.size()
1,023✔
180
                                 + 3 * this->dls_headers.size());
1,023✔
181
    this->dls_cell_allocator.reset();
1,023✔
182

183
    return {};
1,023✔
184
}
185

186
void
187
db_label_source::text_attrs_for_line(textview_curses& tc,
1,023✔
188
                                     int row,
189
                                     string_attrs_t& sa)
190
{
191
    static const auto NUM_ATTR = VC_ROLE.value(role_t::VCR_NUMBER);
1,023✔
192
    static const auto VLINE_ATTR = VC_GRAPHIC.value(NCACS_VLINE);
1,023✔
193

194
    line_range lr(0, 0);
1,023✔
195
    const line_range lr2(0, -1);
1,023✔
196

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

214
        const auto& hm = this->dls_headers[lpc];
3,515✔
215
        if (hm.hm_hidden) {
3,515✔
216
            continue;
3✔
217
        }
218

219
        if (hm.is_graphable()) {
3,512✔
220
            lr.lr_end += this->dls_cell_width[lpc];
724✔
221
            sa.emplace_back(lr, NUM_ATTR);
724✔
222
        }
223
        lr.lr_start += this->dls_cell_width[lpc];
3,512✔
224
        lr.lr_end = lr.lr_start + 1;
3,512✔
225
        sa.emplace_back(lr, VLINE_ATTR);
3,512✔
226
        lr.lr_start += 1;
3,512✔
227
    }
228

229
    for (const auto& attr : sa) {
7,979✔
230
        require_ge(attr.sa_range.lr_start, 0);
6,956✔
231
    }
232
    int cell_start = 0;
1,023✔
233
    auto cursor = this->dls_row_cursors[row].sync();
1,023✔
234
    for (size_t lpc = 0; lpc < this->dls_headers.size();
5,561✔
235
         lpc++, cursor = cursor->next())
4,538✔
236
    {
237
        std::optional<text_attrs> user_attrs;
4,538✔
238

239
        if (lpc == this->dls_row_style_column) {
4,538✔
240
            if (!this->dls_row_styles_have_errors) {
9✔
241
                continue;
9✔
242
            }
243
        }
244

245
        const auto& hm = this->dls_headers[lpc];
4,532✔
246
        if (hm.hm_hidden) {
4,532✔
247
            continue;
3✔
248
        }
249
        if (row < (ssize_t) this->dls_row_styles.size()) {
4,529✔
250
            auto style_opt
251
                = this->dls_row_styles[row].rs_column_config.value_for(lpc);
18✔
252
            if (style_opt) {
18✔
253
                user_attrs = *style_opt.value();
6✔
254
            }
255
        }
256

257
        int left = cell_start;
4,529✔
258
        auto stlr = line_range{
259
            cell_start,
260
            (int) (cell_start + this->dls_cell_width[lpc]),
9,058✔
261
        };
4,529✔
262
        if (hm.is_graphable()) {
4,529✔
263
            std::optional<double> get_res;
1,091✔
264
            if (cursor->get_type() == lnav::cell_type::CT_INTEGER) {
1,091✔
265
                get_res = cursor->get_int();
774✔
266
            } else if (cursor->get_type() == lnav::cell_type::CT_FLOAT) {
317✔
267
                get_res = cursor->get_float();
313✔
268
            }
269
            if (get_res.has_value()) {
1,091✔
270
                hm.hm_chart.chart_attrs_for_value(tc,
1,087✔
271
                                                  left,
272
                                                  this->dls_cell_width[lpc],
1,087✔
273
                                                  hm.hm_name,
1,087✔
274
                                                  get_res.value(),
1,087✔
275
                                                  sa,
276
                                                  user_attrs);
277

278
                for (const auto& attr : sa) {
19,456✔
279
                    require_ge(attr.sa_range.lr_start, 0);
18,369✔
280
                }
281
            }
282
        } else if (user_attrs.has_value()) {
3,438✔
283
            sa.emplace_back(stlr, VC_STYLE.value(user_attrs.value()));
3✔
284
        }
285
        auto cell_sf = string_fragment::invalid();
4,529✔
286
        if (cursor->get_type() == lnav::cell_type::CT_TEXT) {
4,529✔
287
            cell_sf = cursor->get_text();
1,696✔
288
        } else if (cursor->get_type() == lnav::cell_type::CT_NULL) {
2,833✔
289
            sa.emplace_back(stlr, VC_ROLE.value(role_t::VCR_NULL));
1,018✔
290
        }
291
        if (lpc == this->dls_row_style_column) {
4,529✔
292
            sa.emplace_back(stlr, VC_ROLE.value(role_t::VCR_ERROR));
3✔
293
        } else if (cell_sf.is_valid() && cell_sf.length() > 2
6,219✔
294
                   && cell_sf.length() < MAX_JSON_WIDTH
1,455✔
295
                   && ((cell_sf.front() == '{' && cell_sf.back() == '}')
7,603✔
296
                       || (cell_sf.front() == '[' && cell_sf.back() == ']')))
1,384✔
297
        {
298
            auto cb = [&](const std::string& ptr, const scoped_value_t& sv) {
203✔
299
                auto val_opt = to_double(sv);
203✔
300
                if (val_opt) {
203✔
301
                    hm.hm_chart.chart_attrs_for_value(tc,
150✔
302
                                                      left,
303
                                                      this->dls_cell_width[lpc],
75✔
304
                                                      ptr,
305
                                                      val_opt.value(),
75✔
306
                                                      sa);
307
                    for (const auto& attr : sa) {
651✔
308
                        require_ge(attr.sa_range.lr_start, 0);
576✔
309
                    }
310
                }
311
            };
203✔
312
            json_ptr_walk jpw(cb);
126✔
313

314
            jpw.parse_fully(cell_sf);
126✔
315
        }
126✔
316
        cell_start += this->dls_cell_width[lpc] + 1;
4,529✔
317
    }
318

319
    for (const auto& attr : sa) {
9,846✔
320
        require_ge(attr.sa_range.lr_start, 0);
8,823✔
321
    }
322
}
323

324
void
325
db_label_source::set_col_as_graphable(int lpc)
719✔
326
{
327
    static auto& vc = view_colors::singleton();
719✔
328

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

344
void
345
db_label_source::push_header(const std::string& colstr, int type)
3,158✔
346
{
347
    this->dls_headers.emplace_back(colstr);
3,158✔
348
    this->dls_cell_width.push_back(0);
3,158✔
349

350
    auto& hm = this->dls_headers.back();
3,158✔
351

352
    hm.hm_column_size = utf8_string_length(colstr).unwrapOr(colstr.length());
3,158✔
353
    hm.hm_column_type = type;
3,158✔
354
    if (colstr == "log_time" || colstr == "min(log_time)"
6,246✔
355
        || colstr == "log_time_msecs")
6,246✔
356
    {
357
        this->dls_time_column_index = this->dls_headers.size() - 1;
76✔
358
    }
359
    if (colstr == "__lnav_style__") {
3,158✔
360
        this->dls_row_style_column = this->dls_headers.size() - 1;
3✔
361
    }
362
    if (colstr == "log_level") {
3,158✔
363
        this->dls_level_column = this->dls_headers.size() - 1;
56✔
364
    }
365
    hm.hm_chart.with_show_state(stacked_bar_chart_base::show_all{});
3,158✔
366
}
3,158✔
367

368
void
369
db_label_source::update_time_column(const timeval& tv)
324✔
370
{
371
    if (!this->dls_time_column.empty() && tv < this->dls_time_column.back()) {
324✔
372
        this->dls_time_column_invalidated_at = this->dls_time_column.size();
1✔
373
        this->dls_time_column_index = SIZE_MAX;
1✔
374
        this->dls_time_column.clear();
1✔
375
    } else {
376
        this->dls_time_column.push_back(tv);
323✔
377
    }
378
}
324✔
379

380
void
381
db_label_source::update_time_column(const string_fragment& sf)
303✔
382
{
383
    date_time_scanner dts;
303✔
384
    timeval tv;
385

386
    if (!dts.convert_to_timeval(sf.data(), sf.length(), nullptr, tv)) {
303✔
387
        tv.tv_sec = -1;
×
388
        tv.tv_usec = -1;
×
389
    }
390
    this->update_time_column(tv);
303✔
391
}
303✔
392

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

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

457
                this->update_time_column(to_timeval(us));
21✔
458
            }
459
        },
2,799✔
460
        [this, &width](double d) {
×
461
            char buffer[1];
462
            auto fmt_res = fmt::format_to_n(buffer, 0, FMT_STRING("{}"), d);
693✔
463
            width = fmt_res.size;
231✔
464
            this->dls_cell_container.push_float_cell(d);
231✔
465
        },
231✔
466
        [this, &width](null_value_t) {
9,599✔
467
            width = 6;
2,305✔
468
            this->dls_cell_container.push_null_cell();
2,305✔
469
        });
2,305✔
470

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

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

585
            col_sf
586
                = string_fragment::from_str("expecting a JSON object for style")
×
587
                      .to_owned(this->dls_cell_allocator);
×
588
            this->dls_row_styles_have_errors = true;
×
589
        }
590

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

601
    hm.hm_column_size = std::max(this->dls_headers[col].hm_column_size, width);
9,599✔
602
    if (hm.is_graphable()) {
9,599✔
603
        if (sv.is<int64_t>()) {
2,040✔
604
            hm.hm_chart.add_value(hm.hm_name, sv.get<int64_t>());
1,422✔
605
            hm.hm_tdigest.insert(sv.get<int64_t>());
1,422✔
606
        } else if (sv.is<double>()) {
618✔
607
            hm.hm_chart.add_value(hm.hm_name, sv.get<double>());
221✔
608
            hm.hm_tdigest.insert(sv.get<double>());
221✔
609
        } else if (sv.is<string_fragment>()) {
397✔
610
            auto sf = sv.get<string_fragment>();
388✔
611
            auto num_from_res = humanize::try_from<double>(sf);
388✔
612
            if (num_from_res) {
388✔
613
                hm.hm_chart.add_value(hm.hm_name, num_from_res.value());
388✔
614
                hm.hm_tdigest.insert(num_from_res.value());
388✔
615
            }
616
        }
617
    } else if (cv_sf.is_valid() && cv_sf.length() > 2
11,426✔
618
               && ((cv_sf.startswith("{") && cv_sf.endswith("}"))
14,606✔
619
                   || (cv_sf.startswith("[") && cv_sf.endswith("]"))))
3,180✔
620
    {
621
        auto cb = [this, &hm, &vc](const std::string& ptr,
1,124✔
622
                                   const scoped_value_t& sv) {
623
            auto ptr_sf = string_fragment::from_str(ptr);
1,124✔
624
            auto iter = hm.hm_json_columns.find(ptr_sf);
1,124✔
625
            if (iter == hm.hm_json_columns.end()) {
1,124✔
626
                auto owned_ptr_sf = ptr_sf.to_owned(this->dls_header_allocator);
919✔
627
                iter = hm.hm_json_columns
1,838✔
628
                           .emplace(owned_ptr_sf, hm.hm_json_columns.size())
919✔
629
                           .first;
630
            }
631
            if (sv.is<int64_t>()) {
1,124✔
632
                auto val = sv.get<int64_t>();
349✔
633
                auto& ci = hm.hm_chart.add_value(ptr, val);
349✔
634
                if (ci.ci_attrs.empty()) {
349✔
635
                    ci.ci_attrs = vc.attrs_for_ident(ptr);
319✔
636
                }
637
            } else if (sv.is<double>()) {
775✔
638
                auto val = sv.get<double>();
35✔
639
                auto& ci = hm.hm_chart.add_value(ptr, val);
35✔
640
                if (ci.ci_attrs.empty()) {
35✔
641
                    ci.ci_attrs = vc.attrs_for_ident(ptr);
35✔
642
                }
643
            }
644
        };
1,124✔
645
        json_ptr_walk jpw(cb);
418✔
646

647
        jpw.parse_fully(cv_sf);
418✔
648
    }
418✔
649
    hm.hm_chart.next_row();
9,599✔
650
}
9,599✔
651

652
void
653
db_label_source::clear()
2,683✔
654
{
655
    this->dls_generation += 1;
2,683✔
656
    this->dls_user_query.clear();
2,683✔
657
    this->dls_user_query_src_loc = std::nullopt;
2,683✔
658
    this->dls_user_query_vars.clear();
2,683✔
659
    this->dls_query_start = std::nullopt;
2,683✔
660
    this->dls_query_end = std::nullopt;
2,683✔
661
    this->dls_query_touches_log_data = false;
2,683✔
662
    this->dls_log_gen_at_query = 0;
2,683✔
663
    this->dls_log_line_count_at_query = 0;
2,683✔
664
    this->dls_headers.clear();
2,683✔
665
    this->dls_row_cursors.clear();
2,683✔
666
    this->dls_cell_container.reset();
2,683✔
667
    this->dls_time_column.clear();
2,683✔
668
    this->dls_time_column_index = SIZE_MAX;
2,683✔
669
    this->dls_cell_width.clear();
2,683✔
670
    this->dls_row_styles.clear();
2,683✔
671
    this->dls_row_styles_have_errors = false;
2,683✔
672
    this->dls_row_style_column = SIZE_MAX;
2,683✔
673
    this->dls_level_column = std::nullopt;
2,683✔
674
    this->dls_cell_allocator.reset();
2,683✔
675
    this->dls_header_allocator.reset();
2,683✔
676
    this->dls_step_rc = SQLITE_OK;
2,683✔
677
    if (this->tss_view != nullptr) {
2,683✔
678
        this->tss_view->get_bookmarks().clear();
351✔
679
    }
680
}
2,683✔
681

682
std::optional<size_t>
683
db_label_source::column_name_to_index(const std::string& name) const
15✔
684
{
685
    return this->dls_headers | lnav::itertools::find(name);
15✔
686
}
687

688
std::optional<vis_line_t>
689
db_label_source::row_for_time(timeval time_bucket)
5✔
690
{
691
    const auto iter = std::lower_bound(this->dls_time_column.begin(),
5✔
692
                                       this->dls_time_column.end(),
693
                                       time_bucket);
694
    if (iter != this->dls_time_column.end()) {
5✔
695
        return vis_line_t(std::distance(this->dls_time_column.begin(), iter));
8✔
696
    }
697
    return std::nullopt;
1✔
698
}
699

700
std::optional<text_time_translator::row_info>
701
db_label_source::time_for_row(vis_line_t row)
324✔
702
{
703
    if ((row < 0_vl) || (((size_t) row) >= this->dls_time_column.size())) {
324✔
704
        return std::nullopt;
266✔
705
    }
706

707
    return row_info{this->dls_time_column[row], row};
58✔
708
}
709

710
bool
711
db_label_source::text_handle_mouse(
×
712
    textview_curses& tc,
713
    const listview_curses::display_line_content_t&,
714
    mouse_event& me)
715
{
716
    if (tc.get_overlay_selection()) {
×
717
        auto nci = ncinput{};
×
718
        if (me.is_click_in(mouse_button_t::BUTTON_LEFT, 0, 3)) {
×
719
            nci.id = ' ';
×
720
            nci.eff_text[0] = ' ';
×
721
            this->list_input_handle_key(tc, nci);
×
722
        }
723
    }
724
    return true;
×
725
}
726

727
static constexpr string_attr_type<std::string> DBA_DETAILS("details");
728
static constexpr string_attr_type<std::string> DBA_COLUMN_NAME("column-name");
729

730
bool
731
db_label_source::list_input_handle_key(listview_curses& lv, const ncinput& ch)
×
732
{
733
    switch (ch.eff_text[0]) {
×
734
        case ' ': {
×
735
            auto ov_sel = lv.get_overlay_selection();
×
736
            if (ov_sel) {
×
737
                std::vector<attr_line_t> rows;
×
738
                auto* ov_source = lv.get_overlay_source();
×
739
                ov_source->list_value_for_overlay(
×
740
                    lv, lv.get_selection().value(), rows);
×
741
                if (ov_sel.value() < (ssize_t) rows.size()) {
×
742
                    auto& row_al = rows[ov_sel.value()];
×
743
                    auto col_attr
744
                        = get_string_attr(row_al.al_attrs, DBA_COLUMN_NAME);
×
745
                    if (col_attr) {
×
746
                        auto col_name = col_attr.value().get();
×
747
                        auto col_opt = this->column_name_to_index(col_name);
×
748
                        if (col_opt) {
×
749
                            this->dls_headers[col_opt.value()].hm_hidden
×
750
                                = !this->dls_headers[col_opt.value()].hm_hidden;
×
751
                        }
752
                    }
753
                }
754
                lv.set_needs_update();
×
755

756
                return true;
×
757
            }
758
            break;
×
759
        }
760
    }
761

762
    return false;
×
763
}
764

765
std::optional<json_string>
766
db_label_source::text_row_details(const textview_curses& tc)
3✔
767
{
768
    if (this->dls_row_cursors.empty()) {
3✔
769
        log_trace("db_label_source::text_row_details: empty");
×
770
        return std::nullopt;
×
771
    }
772
    if (!this->dls_query_end.has_value()) {
3✔
773
        log_trace("db_label_source::text_row_details: query in progress");
2✔
774
        return std::nullopt;
2✔
775
    }
776

777
    auto ov_sel = tc.get_overlay_selection();
1✔
778

779
    if (ov_sel.has_value()) {
1✔
780
        std::vector<attr_line_t> rows;
×
781
        auto* ov_source = tc.get_overlay_source();
×
782
        ov_source->list_value_for_overlay(tc, tc.get_selection().value(), rows);
×
783
        if (ov_sel.value() < (ssize_t) rows.size()) {
×
784
            auto& row_al = rows[ov_sel.value()];
×
785
            auto deets_attr = get_string_attr(row_al.al_attrs, DBA_DETAILS);
×
786
            if (deets_attr) {
×
787
                auto deets = deets_attr->get();
×
788
                if (!deets.empty()) {
×
789
                    return json_string(
×
790
                        auto_buffer::from(deets.c_str(), deets.length()));
×
791
                }
792
            }
793
        }
794
    } else {
×
795
        yajlpp_gen gen;
1✔
796

797
        {
798
            yajlpp_map root(gen);
1✔
799

800
            auto sel = tc.get_selection();
1✔
801
            if (sel) {
1✔
802
                root.gen("value");
1✔
803

804
                {
805
                    yajlpp_map value_map(gen);
1✔
806

807
                    auto cursor
808
                        = this->dls_row_cursors[tc.get_selection().value()]
1✔
809
                              .sync();
1✔
810
                    for (const auto& [col, hm] :
22✔
811
                         lnav::itertools::enumerate(this->dls_headers))
23✔
812
                    {
813
                        value_map.gen(hm.hm_name);
21✔
814

815
                        switch (cursor->get_type()) {
21✔
816
                            case lnav::cell_type::CT_NULL:
9✔
817
                                value_map.gen();
9✔
818
                                break;
9✔
819
                            case lnav::cell_type::CT_INTEGER:
5✔
820
                                value_map.gen(cursor->get_int());
5✔
821
                                break;
5✔
822
                            case lnav::cell_type::CT_FLOAT:
×
823
                                if (cursor->get_sub_value() == 0) {
×
824
                                    value_map.gen(cursor->get_float());
×
825
                                } else {
826
                                    value_map.gen(cursor->get_float_as_text());
×
827
                                }
828
                                break;
×
829
                            case lnav::cell_type::CT_TEXT:
7✔
830
                                value_map.gen(cursor->get_text());
7✔
831
                                break;
7✔
832
                        }
833
                        cursor = cursor->next();
21✔
834
                    }
835
                }
1✔
836
            }
837
        }
1✔
838

839
        return json_string{gen};
1✔
840
    }
1✔
841

842
    return std::nullopt;
×
843
}
844

845
Result<std::string, lnav::console::user_message>
846
db_label_source::text_reload_data(exec_context& ec)
×
847
{
848
    if (this->dls_user_query.empty()) {
×
849
        return ec.make_error("no previous query to re-run");
×
850
    }
851

852
    auto prev_query = this->dls_user_query;
×
853
    auto prev_loc = this->dls_user_query_src_loc.value_or(INTERNAL_SRC_LOC);
×
854
    auto prev_vars = this->dls_user_query_vars;
×
855
    std::string alt_msg;
×
856

857
    auto src_guard = ec.enter_source(
858
        prev_loc, fmt::format(FMT_STRING(";{}"), prev_query));
×
859
    auto db_guard = ec.enter_db_source(this);
×
860
    auto cb_guard = ec.push_callback(sql_callback);
×
861

862
    ec.ec_local_vars.emplace(std::move(prev_vars));
×
863
    auto vars_guard
864
        = finally([&ec]() { ec.ec_local_vars.pop(); });
×
865

866
    return execute_sql(ec, prev_query, alt_msg);
×
867
}
868

869
std::optional<std::string>
870
db_label_source::text_view_details() const
2✔
871
{
872
    if (this->dls_user_query.empty()) {
2✔
NEW
873
        return text_sub_source::text_view_details();
×
874
    }
875

876
    yajlpp_gen gen;
2✔
877
    {
878
        yajlpp_map root(gen);
2✔
879

880
        root.gen("zoom-level");
2✔
881
        root.gen(this->format_zoom_level());
2✔
882

883
        root.gen("query");
2✔
884
        root.gen(this->dls_user_query);
2✔
885

886
        if (this->dls_query_start.has_value()) {
2✔
887
            auto us = std::chrono::duration_cast<std::chrono::microseconds>(
2✔
888
                this->dls_query_start.value().time_since_epoch());
2✔
889
            root.gen("run-at");
2✔
890
            root.gen(lnav::to_rfc3339_string(us, 'T'));
2✔
891
        }
892

893
        if (this->dls_query_start.has_value()
2✔
894
            && this->dls_query_end.has_value())
2✔
895
        {
896
            int64_t us = std::chrono::duration_cast<std::chrono::microseconds>(
×
897
                             this->dls_query_end.value()
898
                             - this->dls_query_start.value())
×
899
                             .count();
×
NEW
900
            root.gen("duration-us");
×
901
            root.gen(us);
×
902
        }
903
    }
2✔
904

905
    return gen.to_string_fragment().to_string();
2✔
906
}
2✔
907

908
std::string
909
db_label_source::get_row_as_string(vis_line_t row)
1,478✔
910
{
911
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())) {
1,478✔
912
        return "";
×
913
    }
914

915
    if (this->dls_headers.size() == 1) {
1,478✔
916
        return this->dls_row_cursors[row]
1,472✔
917
            .sync()
1,472✔
918
            .value()
1,472✔
919
            .to_string_fragment(this->dls_cell_allocator)
2,944✔
920
            .to_string();
1,472✔
921
    }
922

923
    std::string retval;
6✔
924
    size_t lpc = 0;
6✔
925
    auto cursor = this->dls_row_cursors[row].sync();
6✔
926
    while (lpc < this->dls_headers.size() && cursor.has_value()) {
26✔
927
        const auto& hm = this->dls_headers[lpc];
20✔
928

929
        if (!retval.empty()) {
20✔
930
            retval.append("; ");
14✔
931
        }
932
        retval.append(hm.hm_name);
20✔
933
        retval.push_back('=');
20✔
934
        auto sf = cursor->to_string_fragment(this->dls_cell_allocator);
20✔
935
        retval += sf;
20✔
936

937
        cursor = cursor->next();
20✔
938
        lpc += 1;
20✔
939
    }
940
    this->dls_cell_allocator.reset();
6✔
941

942
    return retval;
6✔
943
}
6✔
944

945
std::string
946
db_label_source::get_cell_as_string(vis_line_t row, size_t col)
×
947
{
948
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())
×
949
        || col >= this->dls_headers.size())
×
950
    {
951
        return "";
×
952
    }
953

954
    this->dls_cell_allocator.reset();
×
955
    size_t lpc = 0;
×
956
    auto cursor = this->dls_row_cursors[row].sync();
×
957
    while (cursor.has_value()) {
×
958
        if (lpc == col) {
×
959
            return cursor->to_string_fragment(this->dls_cell_allocator)
×
960
                .to_string();
×
961
        }
962

963
        cursor = cursor->next();
×
964
        lpc += 1;
×
965
    }
966

967
    return "";
×
968
}
969

970
std::optional<int64_t>
971
db_label_source::get_cell_as_int64(vis_line_t row, size_t col) const
×
972
{
973
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())
×
974
        || col >= this->dls_headers.size())
×
975
    {
976
        return std::nullopt;
×
977
    }
978

979
    size_t lpc = 0;
×
980
    auto cursor = this->dls_row_cursors[row].sync();
×
981
    while (cursor.has_value()) {
×
982
        if (lpc == col) {
×
983
            if (cursor->get_type() == lnav::cell_type::CT_INTEGER) {
×
984
                return cursor->get_int();
×
985
            }
986
            return std::nullopt;
×
987
        }
988

989
        cursor = cursor->next();
×
990
        lpc += 1;
×
991
    }
992

993
    return std::nullopt;
×
994
}
995

996
std::optional<double>
997
db_label_source::get_cell_as_double(vis_line_t row, size_t col) const
×
998
{
999
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())
×
1000
        || col >= this->dls_headers.size())
×
1001
    {
1002
        return std::nullopt;
×
1003
    }
1004

1005
    size_t lpc = 0;
×
1006
    auto cursor = this->dls_row_cursors[row].sync();
×
1007
    while (cursor.has_value()) {
×
1008
        if (lpc == col) {
×
1009
            switch (cursor->get_type()) {
×
1010
                case lnav::cell_type::CT_INTEGER:
×
1011
                    return cursor->get_int();
×
1012
                case lnav::cell_type::CT_FLOAT:
×
1013
                    return cursor->get_float();
×
1014
                default:
×
1015
                    return std::nullopt;
×
1016
            }
1017
        }
1018

1019
        cursor = cursor->next();
×
1020
        lpc += 1;
×
1021
    }
1022

1023
    return std::nullopt;
×
1024
}
1025

1026
mapbox::util::variant<int64_t, double>
1027
db_label_source::get_cell_as_numeric(vis_line_t row, size_t col) const
×
1028
{
1029
    if (row < 0_vl || (((size_t) row) >= this->dls_row_cursors.size())
×
1030
        || col >= this->dls_headers.size())
×
1031
    {
1032
        return numeric_cell_t{mapbox::util::no_init{}};
×
1033
    }
1034

1035
    size_t lpc = 0;
×
1036
    auto cursor = this->dls_row_cursors[row].sync();
×
1037
    while (cursor.has_value()) {
×
1038
        if (lpc == col) {
×
1039
            switch (cursor->get_type()) {
×
1040
                case lnav::cell_type::CT_INTEGER:
×
1041
                    return cursor->get_int();
×
1042
                case lnav::cell_type::CT_FLOAT:
×
1043
                    return cursor->get_float();
×
1044
                default:
×
1045
                    return numeric_cell_t{mapbox::util::no_init{}};
×
1046
            }
1047
        }
1048

1049
        cursor = cursor->next();
×
1050
        lpc += 1;
×
1051
    }
1052

1053
    return numeric_cell_t{mapbox::util::no_init{}};
×
1054
}
1055

1056
void
1057
db_label_source::reset_user_state()
7✔
1058
{
1059
    for (auto& hm : this->dls_headers) {
7✔
1060
        hm.hm_hidden = false;
×
1061
    }
1062
}
7✔
1063

1064
std::optional<attr_line_t>
1065
db_overlay_source::list_header_for_overlay(const listview_curses& lv,
×
1066
                                           media_t media,
1067
                                           vis_line_t line)
1068
{
1069
    attr_line_t retval;
×
1070

1071
    retval.append("  Details for row ")
×
1072
        .append(
×
1073
            lnav::roles::number(fmt::format(FMT_STRING("{:L}"), (int) line)))
×
1074
        .append(". Press ")
×
1075
        .append("p"_hotkey)
×
1076
        .append(" to hide this panel.");
×
1077
    if (lv.get_overlay_selection()) {
×
1078
        retval.append(" Controls: ")
×
1079
            .append("c"_hotkey)
×
1080
            .append(" to copy a column value; ")
×
1081
            .append("SPC"_hotkey)
×
1082
            .append(" to hide/show a column");
×
1083
    } else {
1084
        retval.append("  Press ")
×
1085
            .append("CTRL-]"_hotkey)
×
1086
            .append(" to focus on this panel");
×
1087
    }
1088
    return retval;
×
1089
}
1090

1091
void
1092
db_overlay_source::list_value_for_overlay(const listview_curses& lv,
709✔
1093
                                          vis_line_t row,
1094
                                          std::vector<attr_line_t>& value_out)
1095
{
1096
    if (!this->dos_active || lv.get_inner_height() == 0) {
709✔
1097
        return;
709✔
1098
    }
1099

1100
    auto sel = lv.get_selection();
×
1101
    if (!sel || row != sel.value()) {
×
1102
        return;
×
1103
    }
1104

1105
    auto& vc = view_colors::singleton();
×
1106
    unsigned long width;
1107
    vis_line_t height;
×
1108

1109
    lv.get_dimensions(height, width);
×
1110

1111
    auto max_name_width = this->dos_labels->dls_headers
×
1112
        | lnav::itertools::map([](const auto& hm) { return hm.hm_name.size(); })
×
1113
        | lnav::itertools::max();
×
1114

1115
    auto cursor = this->dos_labels->dls_row_cursors[row].sync();
×
1116
    for (const auto& [col, hm] :
×
1117
         lnav::itertools::enumerate(this->dos_labels->dls_headers))
×
1118
    {
1119
        auto al = attr_line_t()
×
1120
                      .append(lnav::roles::h3(hm.hm_name))
×
1121
                      .right_justify(max_name_width.value_or(0) + 2);
×
1122

1123
        if (hm.hm_hidden) {
×
1124
            al.insert(1, "\u25c7"_comment);
×
1125
        } else {
1126
            al.insert(1, "\u25c6"_ok);
×
1127
        }
1128

1129
        auto sf
1130
            = cursor->to_string_fragment(this->dos_labels->dls_cell_allocator);
×
1131

1132
        al.al_attrs.emplace_back(line_range{0, -1},
×
1133
                                 DBA_COLUMN_NAME.value(hm.hm_name));
×
1134
        if (cursor->get_type() == lnav::cell_type::CT_TEXT
×
1135
            && (sf.startswith("[") || sf.startswith("{")))
×
1136
        {
1137
            auto parse_res = json_walk_collector::parse_fully(sf);
×
1138

1139
            if (parse_res.isOk()) {
×
1140
                auto jwc = parse_res.unwrap();
×
1141
                {
1142
                    yajlpp_gen gen;
×
1143

1144
                    {
1145
                        yajlpp_map root(gen);
×
1146

1147
                        root.gen("key");
×
1148
                        root.gen(hm.hm_name);
×
1149
                        root.gen("value");
×
1150
                        root.gen(sf);
×
1151
                    }
1152
                    al.al_attrs.emplace_back(
×
1153
                        line_range{0, -1},
×
1154
                        DBA_DETAILS.value(
×
1155
                            gen.to_string_fragment().to_string()));
×
1156
                }
1157
                value_out.emplace_back(al);
×
1158
                al.clear();
×
1159

1160
                stacked_bar_chart<std::string> chart;
×
1161
                int start_line = value_out.size();
×
1162

1163
                auto indent = 3 + max_name_width.value() - hm.hm_name.size();
×
1164
                chart.with_stacking_enabled(false)
×
1165
                    .with_margins(indent + 2, 0)
×
1166
                    .with_show_state(stacked_bar_chart_base::show_all{});
×
1167

1168
                for (const auto& [walk_index, jpw_value] :
×
1169
                     lnav::itertools::enumerate(jwc.jwc_values))
×
1170
                {
1171
                    {
1172
                        yajlpp_gen gen;
×
1173

1174
                        {
1175
                            yajlpp_map root(gen);
×
1176

1177
                            root.gen("key");
×
1178
                            root.gen(jpw_value.first);
×
1179
                            root.gen("value");
×
1180
                            root.gen(fmt::to_string(jpw_value.second));
×
1181
                        }
1182
                        al.al_attrs.emplace_back(
×
1183
                            line_range{0, -1},
×
1184
                            DBA_DETAILS.value(
×
1185
                                gen.to_string_fragment().to_string()));
×
1186
                    }
1187

1188
                    al.append(indent + 2, ' ')
×
1189
                        .append(lnav::roles::h5(jpw_value.first))
×
1190
                        .append(" = ")
×
1191
                        .append(fmt::to_string(jpw_value.second));
×
1192

1193
                    auto& sa = al.al_attrs;
×
1194
                    line_range lr(indent, indent + 1);
×
1195

1196
                    sa.emplace_back(
×
1197
                        lr,
1198
                        VC_GRAPHIC.value(walk_index < jwc.jwc_values.size() - 1
×
1199
                                             ? NCACS_LTEE
1200
                                             : NCACS_LLCORNER));
1201
                    lr.lr_start = indent + 2 + jpw_value.first.size() + 3;
×
1202
                    lr.lr_end = -1;
×
1203

1204
                    auto val_opt = to_double(jpw_value.second);
×
1205
                    if (val_opt) {
×
1206
                        auto attrs = vc.attrs_for_ident(jpw_value.first);
×
1207

1208
                        chart.add_value(jpw_value.first, val_opt.value());
×
1209
                        chart.with_attrs_for_ident(jpw_value.first, attrs);
×
1210
                        sa.emplace_back(lr, VC_ROLE.value(role_t::VCR_NUMBER));
×
1211
                    }
1212
                    value_out.emplace_back(al);
×
1213
                    al.clear();
×
1214
                }
1215

1216
                int curr_line = start_line;
×
1217
                for (auto iter = jwc.jwc_values.begin();
×
1218
                     iter != jwc.jwc_values.end();
×
1219
                     ++iter, curr_line++)
×
1220
                {
1221
                    auto val_opt = to_double(iter->second);
×
1222
                    if (!val_opt) {
×
1223
                        continue;
×
1224
                    }
1225

1226
                    auto& sa = value_out[curr_line].get_attrs();
×
1227
                    int left = indent + 2;
×
1228
                    chart.chart_attrs_for_value(
×
1229
                        lv, left, width, iter->first, val_opt.value(), sa);
×
1230
                }
1231
            } else {
×
1232
                yajlpp_gen gen;
×
1233

1234
                {
1235
                    yajlpp_map root(gen);
×
1236

1237
                    root.gen("key");
×
1238
                    root.gen(hm.hm_name);
×
1239
                    root.gen("value");
×
1240
                    root.gen(sf);
×
1241
                }
1242
                al.append(": ").append(sf);
×
1243
                al.al_attrs.emplace_back(
×
1244
                    line_range{0, -1},
×
1245
                    DBA_DETAILS.value(gen.to_string_fragment().to_string()));
×
1246
            }
1247
        } else {
×
1248
            yajlpp_gen gen;
×
1249

1250
            {
1251
                yajlpp_map root(gen);
×
1252

1253
                root.gen("key");
×
1254
                root.gen(hm.hm_name);
×
1255
                root.gen("value");
×
1256
                switch (cursor->get_type()) {
×
1257
                    case lnav::cell_type::CT_NULL:
×
1258
                        root.gen();
×
1259
                        break;
×
1260
                    case lnav::cell_type::CT_INTEGER:
×
1261
                        root.gen(cursor->get_int());
×
1262
                        break;
×
1263
                    case lnav::cell_type::CT_FLOAT:
×
1264
                        if (cursor->get_sub_value() == 0) {
×
1265
                            root.gen(cursor->get_float());
×
1266
                        } else {
1267
                            root.gen(cursor->get_float_as_text());
×
1268
                        }
1269
                        break;
×
1270
                    case lnav::cell_type::CT_TEXT:
×
1271
                        root.gen(cursor->get_text());
×
1272
                        break;
×
1273
                }
1274
            }
1275

1276
            al.append(": ");
×
1277
            auto sf_line_count = sf.trim("\n").count('\n') + 1;
×
1278
            if (sf_line_count > 1) {
×
1279
                al.al_attrs.emplace_back(
×
1280
                    line_range{0, -1},
×
1281
                    DBA_DETAILS.value(gen.to_string_fragment().to_string()));
×
1282
                value_out.emplace_back(al);
×
1283
                for (auto& line_al : attr_line_t().append(sf).split_lines()) {
×
1284
                    line_al.insert(0, "\t");
×
1285
                    line_al.al_attrs.emplace_back(
×
1286
                        line_range{0, -1},
×
1287
                        DBA_DETAILS.value(
×
1288
                            gen.to_string_fragment().to_string()));
×
1289
                    value_out.emplace_back(line_al);
×
1290
                }
1291

1292
                al.clear();
×
1293
            } else {
1294
                auto value_al = attr_line_t().append(sf.trim("\n"));
×
1295
                al.append(value_al);
×
1296
                al.al_attrs.emplace_back(
×
1297
                    line_range{0, -1},
×
1298
                    DBA_DETAILS.value(gen.to_string_fragment().to_string()));
×
1299
            }
1300
        }
1301

1302
        if (!al.empty()) {
×
1303
            value_out.emplace_back(al);
×
1304
        }
1305
        cursor = cursor->next();
×
1306
    }
1307

1308
    this->dos_labels->dls_cell_allocator.reset();
×
1309
}
1310

1311
bool
1312
db_overlay_source::list_static_overlay(const listview_curses& lv,
327✔
1313
                                       media_t media,
1314
                                       int y,
1315
                                       int bottom,
1316
                                       attr_line_t& value_out)
1317
{
1318
    if (y != 0) {
327✔
1319
        return false;
101✔
1320
    }
1321

1322
    const auto* dls = this->dos_labels;
226✔
1323

1324
    if (dls->dls_headers.empty()) {
226✔
1325
        if (media == media_t::display) {
10✔
1326
            value_out.append(
×
1327
                "The results of SQLite queries are shown in this view. "
1328
                "Press ");
1329
            value_out.append(lnav::roles::keyword(";"));
×
1330
            value_out.append(" to execute a query.");
×
1331
            value_out.with_attr_for_all(VC_ROLE.value(role_t::VCR_STATUS));
×
1332
            value_out.with_attr_for_all(
×
1333
                VC_STYLE.value(text_attrs::with_underline()));
×
1334
            return true;
×
1335
        }
1336
        return false;
10✔
1337
    }
1338

1339
    auto& line = value_out.get_string();
216✔
1340
    auto& sa = value_out.get_attrs();
216✔
1341

1342
    for (size_t lpc = 0; lpc < this->dos_labels->dls_headers.size(); lpc++) {
1,270✔
1343
        if (lpc == this->dos_labels->dls_row_style_column
1,054✔
1344
            && !this->dos_labels->dls_row_styles_have_errors)
3✔
1345
        {
1346
            continue;
3✔
1347
        }
1348

1349
        const auto& hm = dls->dls_headers[lpc];
1,052✔
1350
        if (hm.hm_hidden) {
1,052✔
1351
            continue;
1✔
1352
        }
1353
        auto actual_col_size
1354
            = std::min(dls->dls_max_column_width, hm.hm_column_size);
1,051✔
1355
        auto cell_title = hm.hm_name;
1,051✔
1356
        string_attrs_t cell_attrs;
1,051✔
1357
        scrub_ansi_string(cell_title, &cell_attrs);
1,051✔
1358
        truncate_to(cell_title, dls->dls_max_column_width);
1,051✔
1359

1360
        auto cell_length
1361
            = utf8_string_length(cell_title).unwrapOr(actual_col_size);
1,051✔
1362
        int total_fill = actual_col_size - cell_length;
1,051✔
1363
        auto line_len_before = line.length();
1,051✔
1364

1365
        int before = total_fill / 2;
1,051✔
1366
        total_fill -= before;
1,051✔
1367
        line.append(before, ' ');
1,051✔
1368
        shift_string_attrs(cell_attrs, 0, line.size());
1,051✔
1369
        line.append(cell_title);
1,051✔
1370
        line.append(total_fill, ' ');
1,051✔
1371
        auto header_range = line_range(line_len_before, line.length());
1,051✔
1372

1373
        line.append(1, ' ');
1,051✔
1374

1375
        require_ge(header_range.lr_start, 0);
1,051✔
1376

1377
        sa.emplace_back(header_range, VC_STYLE.value(hm.hm_title_attrs));
1,051✔
1378
        sa.insert(sa.end(), cell_attrs.begin(), cell_attrs.end());
1,051✔
1379
    }
1,051✔
1380

1381
    line_range lr(0);
216✔
1382

1383
    sa.emplace_back(lr, VC_ROLE.value(role_t::VCR_TABLE_HEADER));
216✔
1384
    sa.emplace_back(
216✔
1385
        lr,
1386
        VC_STYLE.value(text_attrs::with_styles(text_attrs::style::underline)));
432✔
1387
    return true;
216✔
1388
}
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