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

tstack / lnav / 18882433814-2607

28 Oct 2025 04:45PM UTC coverage: 68.89% (-1.1%) from 70.002%
18882433814-2607

push

github

tstack
[hasher] fixup hasher::to_string() for sse2

5 of 5 new or added lines in 1 file covered. (100.0%)

2926 existing lines in 57 files now uncovered.

50208 of 72881 relevant lines covered (68.89%)

424460.54 hits per line

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

61.54
/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/math_util.hh"
41
#include "base/time_util.hh"
42
#include "base/types.hh"
43
#include "config.h"
44
#include "hist_source_T.hh"
45
#include "scn/scan.h"
46
#include "yajlpp/json_ptr.hh"
47
#include "yajlpp/yajlpp_def.hh"
48

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

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

53
constexpr ssize_t MAX_JSON_WIDTH = 16 * 1024;
54

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

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

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

74
    return retval;
9✔
75
}
12✔
76

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

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

112
        if (row < (int) this->dls_row_styles.size()) {
4,401✔
113
            auto style_iter
114
                = this->dls_row_styles[row].rs_column_config.find(lpc);
18✔
115
            if (style_iter != this->dls_row_styles[row].rs_column_config.end())
18✔
116
            {
117
                if (style_iter->second.ta_align.has_value()) {
6✔
118
                    align = style_iter->second.ta_align.value();
3✔
119
                }
120
            }
121
        }
122

123
        auto sf = cell_cursor->to_string_fragment(this->dls_cell_allocator);
4,401✔
124
        auto al = attr_line_t::from_table_cell_content(
125
            sf, this->dls_max_column_width);
4,401✔
126

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

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

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

181
    return {};
988✔
182
}
183

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

192
    line_range lr(0, 0);
988✔
193
    const line_range lr2(0, -1);
988✔
194

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

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

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

227
    for (const auto& attr : sa) {
7,726✔
228
        require_ge(attr.sa_range.lr_start, 0);
6,738✔
229
    }
230
    int cell_start = 0;
988✔
231
    auto cursor = this->dls_row_cursors[row].sync();
988✔
232
    for (size_t lpc = 0; lpc < this->dls_headers.size();
5,398✔
233
         lpc++, cursor = cursor->next())
4,410✔
234
    {
235
        std::optional<text_attrs> user_attrs;
4,410✔
236

237
        if (lpc == this->dls_row_style_column) {
4,410✔
238
            if (!this->dls_row_styles_have_errors) {
9✔
239
                continue;
9✔
240
            }
241
        }
242

243
        const auto& hm = this->dls_headers[lpc];
4,404✔
244
        if (hm.hm_hidden) {
4,404✔
245
            continue;
3✔
246
        }
247
        if (row < (ssize_t) this->dls_row_styles.size()) {
4,401✔
248
            auto style_iter
249
                = this->dls_row_styles[row].rs_column_config.find(lpc);
18✔
250
            if (style_iter != this->dls_row_styles[row].rs_column_config.end())
18✔
251
            {
252
                user_attrs = style_iter->second;
6✔
253
            }
254
        }
255

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

277
                for (const auto& attr : sa) {
18,817✔
278
                    require_ge(attr.sa_range.lr_start, 0);
17,759✔
279
                }
280
            }
281
        } else if (user_attrs.has_value()) {
3,343✔
282
            sa.emplace_back(stlr, VC_STYLE.value(user_attrs.value()));
3✔
283
        }
284
        auto cell_sf = string_fragment::invalid();
4,401✔
285
        if (cursor->get_type() == lnav::cell_type::CT_TEXT) {
4,401✔
286
            cell_sf = cursor->get_text();
1,633✔
287
        } else if (cursor->get_type() == lnav::cell_type::CT_NULL) {
2,768✔
288
            sa.emplace_back(stlr, VC_ROLE.value(role_t::VCR_NULL));
1,005✔
289
        }
290
        if (lpc == this->dls_row_style_column) {
4,401✔
291
            sa.emplace_back(stlr, VC_ROLE.value(role_t::VCR_ERROR));
3✔
292
        } else if (cell_sf.is_valid() && cell_sf.length() > 2
6,028✔
293
                   && cell_sf.length() < MAX_JSON_WIDTH
1,394✔
294
                   && ((cell_sf.front() == '{' && cell_sf.back() == '}')
7,365✔
295
                       || (cell_sf.front() == '[' && cell_sf.back() == ']')))
1,337✔
296
        {
297
            auto cb = [&](const std::string& ptr, const scoped_value_t& sv) {
181✔
298
                auto val_opt = to_double(sv);
181✔
299
                if (val_opt) {
181✔
300
                    hm.hm_chart.chart_attrs_for_value(tc,
126✔
301
                                                      left,
302
                                                      this->dls_cell_width[lpc],
63✔
303
                                                      ptr,
304
                                                      val_opt.value(),
63✔
305
                                                      sa);
306
                    for (const auto& attr : sa) {
573✔
307
                        require_ge(attr.sa_range.lr_start, 0);
510✔
308
                    }
309
                }
310
            };
181✔
311
            json_ptr_walk jpw(cb);
112✔
312

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
751
    return false;
×
752
}
753

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

868
    return retval;
8✔
869
}
8✔
870

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

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

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

UNCOV
893
    return "";
×
894
}
895

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

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

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

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

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

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

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

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

952
void
953
db_label_source::reset_user_state()
6✔
954
{
955
    for (auto& hm : this->dls_headers) {
6✔
UNCOV
956
        hm.hm_hidden = false;
×
957
    }
958
}
6✔
959

960
std::optional<attr_line_t>
UNCOV
961
db_overlay_source::list_header_for_overlay(const listview_curses& lv,
×
962
                                           vis_line_t line)
963
{
UNCOV
964
    attr_line_t retval;
×
965

966
    retval.append("  Details for row ")
×
967
        .append(
×
968
            lnav::roles::number(fmt::format(FMT_STRING("{:L}"), (int) line)))
×
969
        .append(". Press ")
×
970
        .append("p"_hotkey)
×
971
        .append(" to hide this panel.");
×
972
    if (lv.get_overlay_selection()) {
×
973
        retval.append(" Controls: ")
×
974
            .append("c"_hotkey)
×
975
            .append(" to copy a column value; ")
×
976
            .append("SPC"_hotkey)
×
UNCOV
977
            .append(" to hide/show a column");
×
978
    } else {
979
        retval.append("  Press ")
×
980
            .append("CTRL-]"_hotkey)
×
UNCOV
981
            .append(" to focus on this panel");
×
982
    }
UNCOV
983
    return retval;
×
984
}
985

986
void
987
db_overlay_source::list_value_for_overlay(const listview_curses& lv,
690✔
988
                                          vis_line_t row,
989
                                          std::vector<attr_line_t>& value_out)
990
{
991
    if (!this->dos_active || lv.get_inner_height() == 0) {
690✔
992
        return;
690✔
993
    }
994

995
    auto sel = lv.get_selection();
×
996
    if (!sel || row != sel.value()) {
×
UNCOV
997
        return;
×
998
    }
999

UNCOV
1000
    auto& vc = view_colors::singleton();
×
1001
    unsigned long width;
UNCOV
1002
    vis_line_t height;
×
1003

UNCOV
1004
    lv.get_dimensions(height, width);
×
1005

1006
    auto max_name_width = this->dos_labels->dls_headers
×
1007
        | lnav::itertools::map([](const auto& hm) { return hm.hm_name.size(); })
×
UNCOV
1008
        | lnav::itertools::max();
×
1009

1010
    auto cursor = this->dos_labels->dls_row_cursors[row].sync();
×
1011
    for (const auto& [col, hm] :
×
UNCOV
1012
         lnav::itertools::enumerate(this->dos_labels->dls_headers))
×
1013
    {
1014
        auto al = attr_line_t()
×
1015
                      .append(lnav::roles::h3(hm.hm_name))
×
UNCOV
1016
                      .right_justify(max_name_width.value_or(0) + 2);
×
1017

1018
        if (hm.hm_hidden) {
×
UNCOV
1019
            al.insert(1, "\u25c7"_comment);
×
1020
        } else {
UNCOV
1021
            al.insert(1, "\u25c6"_ok);
×
1022
        }
1023

1024
        auto sf
UNCOV
1025
            = cursor->to_string_fragment(this->dos_labels->dls_cell_allocator);
×
1026

1027
        al.al_attrs.emplace_back(line_range{0, -1},
×
1028
                                 DBA_COLUMN_NAME.value(hm.hm_name));
×
1029
        if (cursor->get_type() == lnav::cell_type::CT_TEXT
×
UNCOV
1030
            && (sf.startswith("[") || sf.startswith("{")))
×
1031
        {
UNCOV
1032
            auto parse_res = json_walk_collector::parse_fully(sf);
×
1033

1034
            if (parse_res.isOk()) {
×
UNCOV
1035
                auto jwc = parse_res.unwrap();
×
1036
                {
UNCOV
1037
                    yajlpp_gen gen;
×
1038

1039
                    {
UNCOV
1040
                        yajlpp_map root(gen);
×
1041

1042
                        root.gen("key");
×
1043
                        root.gen(hm.hm_name);
×
1044
                        root.gen("value");
×
UNCOV
1045
                        root.gen(sf);
×
1046
                    }
1047
                    al.al_attrs.emplace_back(
×
1048
                        line_range{0, -1},
×
1049
                        DBA_DETAILS.value(
×
UNCOV
1050
                            gen.to_string_fragment().to_string()));
×
1051
                }
1052
                value_out.emplace_back(al);
×
UNCOV
1053
                al.clear();
×
1054

1055
                stacked_bar_chart<std::string> chart;
×
UNCOV
1056
                int start_line = value_out.size();
×
1057

1058
                auto indent = 3 + max_name_width.value() - hm.hm_name.size();
×
1059
                chart.with_stacking_enabled(false)
×
1060
                    .with_margins(indent + 2, 0)
×
UNCOV
1061
                    .with_show_state(stacked_bar_chart_base::show_all{});
×
1062

1063
                for (const auto& [walk_index, jpw_value] :
×
UNCOV
1064
                     lnav::itertools::enumerate(jwc.jwc_values))
×
1065
                {
1066
                    {
UNCOV
1067
                        yajlpp_gen gen;
×
1068

1069
                        {
UNCOV
1070
                            yajlpp_map root(gen);
×
1071

1072
                            root.gen("key");
×
1073
                            root.gen(jpw_value.first);
×
1074
                            root.gen("value");
×
UNCOV
1075
                            root.gen(fmt::to_string(jpw_value.second));
×
1076
                        }
1077
                        al.al_attrs.emplace_back(
×
1078
                            line_range{0, -1},
×
1079
                            DBA_DETAILS.value(
×
UNCOV
1080
                                gen.to_string_fragment().to_string()));
×
1081
                    }
1082

1083
                    al.append(indent + 2, ' ')
×
1084
                        .append(lnav::roles::h5(jpw_value.first))
×
1085
                        .append(" = ")
×
UNCOV
1086
                        .append(fmt::to_string(jpw_value.second));
×
1087

1088
                    auto& sa = al.al_attrs;
×
UNCOV
1089
                    line_range lr(indent, indent + 1);
×
1090

UNCOV
1091
                    sa.emplace_back(
×
1092
                        lr,
UNCOV
1093
                        VC_GRAPHIC.value(walk_index < jwc.jwc_values.size() - 1
×
1094
                                             ? NCACS_LTEE
1095
                                             : NCACS_LLCORNER));
1096
                    lr.lr_start = indent + 2 + jpw_value.first.size() + 3;
×
UNCOV
1097
                    lr.lr_end = -1;
×
1098

1099
                    auto val_opt = to_double(jpw_value.second);
×
1100
                    if (val_opt) {
×
UNCOV
1101
                        auto attrs = vc.attrs_for_ident(jpw_value.first);
×
1102

1103
                        chart.add_value(jpw_value.first, val_opt.value());
×
1104
                        chart.with_attrs_for_ident(jpw_value.first, attrs);
×
UNCOV
1105
                        sa.emplace_back(lr, VC_ROLE.value(role_t::VCR_NUMBER));
×
1106
                    }
1107
                    value_out.emplace_back(al);
×
UNCOV
1108
                    al.clear();
×
1109
                }
1110

1111
                int curr_line = start_line;
×
1112
                for (auto iter = jwc.jwc_values.begin();
×
1113
                     iter != jwc.jwc_values.end();
×
UNCOV
1114
                     ++iter, curr_line++)
×
1115
                {
1116
                    auto val_opt = to_double(iter->second);
×
1117
                    if (!val_opt) {
×
UNCOV
1118
                        continue;
×
1119
                    }
1120

1121
                    auto& sa = value_out[curr_line].get_attrs();
×
1122
                    int left = indent + 2;
×
1123
                    chart.chart_attrs_for_value(
×
UNCOV
1124
                        lv, left, width, iter->first, val_opt.value(), sa);
×
1125
                }
1126
            } else {
×
UNCOV
1127
                yajlpp_gen gen;
×
1128

1129
                {
UNCOV
1130
                    yajlpp_map root(gen);
×
1131

1132
                    root.gen("key");
×
1133
                    root.gen(hm.hm_name);
×
1134
                    root.gen("value");
×
UNCOV
1135
                    root.gen(sf);
×
1136
                }
1137
                al.append(": ").append(sf);
×
1138
                al.al_attrs.emplace_back(
×
1139
                    line_range{0, -1},
×
UNCOV
1140
                    DBA_DETAILS.value(gen.to_string_fragment().to_string()));
×
1141
            }
1142
        } else {
×
UNCOV
1143
            yajlpp_gen gen;
×
1144

1145
            {
UNCOV
1146
                yajlpp_map root(gen);
×
1147

1148
                root.gen("key");
×
1149
                root.gen(hm.hm_name);
×
1150
                root.gen("value");
×
1151
                switch (cursor->get_type()) {
×
1152
                    case lnav::cell_type::CT_NULL:
×
1153
                        root.gen();
×
1154
                        break;
×
1155
                    case lnav::cell_type::CT_INTEGER:
×
1156
                        root.gen(cursor->get_int());
×
1157
                        break;
×
1158
                    case lnav::cell_type::CT_FLOAT:
×
1159
                        if (cursor->get_sub_value() == 0) {
×
UNCOV
1160
                            root.gen(cursor->get_float());
×
1161
                        } else {
UNCOV
1162
                            root.gen(cursor->get_float_as_text());
×
1163
                        }
1164
                        break;
×
1165
                    case lnav::cell_type::CT_TEXT:
×
1166
                        root.gen(cursor->get_text());
×
UNCOV
1167
                        break;
×
1168
                }
1169
            }
1170

1171
            auto value_al = attr_line_t::from_table_cell_content(sf, 1000);
×
1172
            al.append(": ").append(value_al);
×
1173
            al.al_attrs.emplace_back(
×
1174
                line_range{0, -1},
×
UNCOV
1175
                DBA_DETAILS.value(gen.to_string_fragment().to_string()));
×
1176
        }
1177

1178
        if (!al.empty()) {
×
UNCOV
1179
            value_out.emplace_back(al);
×
1180
        }
UNCOV
1181
        cursor = cursor->next();
×
1182
    }
1183

UNCOV
1184
    this->dos_labels->dls_cell_allocator.reset();
×
1185
}
1186

1187
bool
1188
db_overlay_source::list_static_overlay(const listview_curses& lv,
315✔
1189
                                       media_t media,
1190
                                       int y,
1191
                                       int bottom,
1192
                                       attr_line_t& value_out)
1193
{
1194
    if (y != 0) {
315✔
1195
        return false;
97✔
1196
    }
1197

1198
    auto& line = value_out.get_string();
218✔
1199
    const auto* dls = this->dos_labels;
218✔
1200
    auto& sa = value_out.get_attrs();
218✔
1201

1202
    for (size_t lpc = 0; lpc < this->dos_labels->dls_headers.size(); lpc++) {
1,231✔
1203
        if (lpc == this->dos_labels->dls_row_style_column
1,013✔
1204
            && !this->dos_labels->dls_row_styles_have_errors)
3✔
1205
        {
1206
            continue;
3✔
1207
        }
1208

1209
        const auto& hm = dls->dls_headers[lpc];
1,011✔
1210
        if (hm.hm_hidden) {
1,011✔
1211
            continue;
1✔
1212
        }
1213
        auto actual_col_size
1214
            = std::min(dls->dls_max_column_width, hm.hm_column_size);
1,010✔
1215
        auto cell_title = hm.hm_name;
1,010✔
1216
        string_attrs_t cell_attrs;
1,010✔
1217
        scrub_ansi_string(cell_title, &cell_attrs);
1,010✔
1218
        truncate_to(cell_title, dls->dls_max_column_width);
1,010✔
1219

1220
        auto cell_length
1221
            = utf8_string_length(cell_title).unwrapOr(actual_col_size);
1,010✔
1222
        int total_fill = actual_col_size - cell_length;
1,010✔
1223
        auto line_len_before = line.length();
1,010✔
1224

1225
        int before = total_fill / 2;
1,010✔
1226
        total_fill -= before;
1,010✔
1227
        line.append(before, ' ');
1,010✔
1228
        shift_string_attrs(cell_attrs, 0, line.size());
1,010✔
1229
        line.append(cell_title);
1,010✔
1230
        line.append(total_fill, ' ');
1,010✔
1231
        auto header_range = line_range(line_len_before, line.length());
1,010✔
1232

1233
        line.append(1, ' ');
1,010✔
1234

1235
        require_ge(header_range.lr_start, 0);
1,010✔
1236

1237
        sa.emplace_back(header_range, VC_STYLE.value(hm.hm_title_attrs));
1,010✔
1238
        sa.insert(sa.end(), cell_attrs.begin(), cell_attrs.end());
1,010✔
1239
    }
1,010✔
1240

1241
    line_range lr(0);
218✔
1242

1243
    sa.emplace_back(
218✔
1244
        lr,
1245
        VC_STYLE.value(text_attrs::with_styles(text_attrs::style::bold,
436✔
1246
                                               text_attrs::style::underline)));
1247
    return true;
218✔
1248
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc