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

tstack / lnav / 19243988760-2657

10 Nov 2025 07:37PM UTC coverage: 68.747% (-0.3%) from 69.055%
19243988760-2657

push

github

tstack
[logfile] lay groundwork for bounding log file times

Related to #1188

308 of 655 new or added lines in 35 files covered. (47.02%)

30 existing lines in 7 files now uncovered.

50645 of 73669 relevant lines covered (68.75%)

430651.53 hits per line

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

44.81
/src/files_sub_source.cc
1
/**
2
 * Copyright (c) 2020, 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 <vector>
31

32
#include "files_sub_source.hh"
33

34
#include "base/ansi_scrubber.hh"
35
#include "base/attr_line.builder.hh"
36
#include "base/fs_util.hh"
37
#include "base/humanize.hh"
38
#include "base/humanize.network.hh"
39
#include "base/humanize.time.hh"
40
#include "base/itertools.enumerate.hh"
41
#include "base/itertools.hh"
42
#include "base/opt_util.hh"
43
#include "base/string_util.hh"
44
#include "config.h"
45
#include "lnav.hh"
46
#include "mapbox/variant.hpp"
47
#include "md4cpp.hh"
48
#include "sql_util.hh"
49

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

53
namespace files_model {
54
files_list_selection
55
from_selection(std::optional<vis_line_t> sel_vis)
21✔
56
{
57
    if (!sel_vis) {
21✔
58
        return no_selection{};
13✔
59
    }
60

61
    auto& fc = lnav_data.ld_active_files;
8✔
62
    int sel = sel_vis.value();
8✔
63

64
    {
65
        safe::ReadAccess<safe_name_to_stubs> errs(*fc.fc_name_to_stubs);
8✔
66

67
        if (sel < (ssize_t) errs->size()) {
8✔
68
            auto iter = errs->begin();
×
69

70
            std::advance(iter, sel);
NEW
71
            return stub_selection::build(
×
72
                sel, std::make_pair(iter->first, iter->second.fei_description));
×
73
        }
74

75
        sel -= errs->size();
8✔
76
    }
8✔
77

78
    if (sel < (ssize_t) fc.fc_other_files.size()) {
8✔
79
        auto iter = fc.fc_other_files.begin();
×
80

81
        std::advance(iter, sel);
82
        return other_selection::build(sel, iter);
×
83
    }
84

85
    sel -= fc.fc_other_files.size();
8✔
86

87
    if (sel < (ssize_t) fc.fc_files.size()) {
8✔
88
        auto iter = fc.fc_files.begin();
8✔
89

90
        std::advance(iter, sel);
91
        return file_selection::build(sel, iter);
8✔
92
    }
93

94
    return no_selection{};
×
95
}
96
}  // namespace files_model
97

98
bool
99
files_sub_source::list_input_handle_key(listview_curses& lv, const ncinput& ch)
1✔
100
{
101
    switch (ch.eff_text[0]) {
1✔
102
        case NCKEY_ENTER:
×
103
        case '\r': {
104
            auto sel = files_model::from_selection(lv.get_selection());
×
105

106
            sel.match(
×
107
                [](files_model::no_selection) {},
×
NEW
108
                [](files_model::stub_selection) {},
×
109
                [](files_model::other_selection) {},
×
110
                [&](files_model::file_selection& fs) {
×
111
                    auto& lss = lnav_data.ld_log_source;
×
112
                    auto lf = *fs.sb_iter;
×
113

114
                    lf->set_indexing(true);
×
115
                    lss.find_data(lf) | [](auto ld) {
×
116
                        ld->set_visibility(true);
×
117
                        lnav_data.ld_log_source.text_filters_changed();
×
118
                    };
119

120
                    if (lf->get_format() != nullptr) {
×
121
                        auto& log_view = lnav_data.ld_views[LNV_LOG];
×
122
                        lss.row_for_time(lf->front().get_timeval()) |
×
123
                            [](auto row) {
×
124
                                lnav_data.ld_views[LNV_LOG].set_selection(row);
×
125
                            };
126
                        ensure_view(&log_view);
×
127
                    } else {
128
                        auto& tv = lnav_data.ld_views[LNV_TEXT];
×
129
                        auto& tss = lnav_data.ld_text_source;
×
130

131
                        tss.to_front(lf);
×
132
                        tv.reload_data();
×
133
                        ensure_view(&tv);
×
134
                    }
135

136
                    lv.reload_data();
×
137
                    set_view_mode(ln_mode_t::PAGING);
×
138
                });
×
139

140
            return true;
×
141
        }
142

143
        case ' ': {
×
144
            auto sel = files_model::from_selection(lv.get_selection());
×
145

146
            sel.match([](files_model::no_selection) {},
×
NEW
147
                      [](files_model::stub_selection) {},
×
148
                      [](files_model::other_selection) {},
×
149
                      [&](files_model::file_selection& fs) {
×
150
                          auto& lss = lnav_data.ld_log_source;
×
151
                          auto lf = *fs.sb_iter;
×
152

153
                          log_debug("toggling visibility of file: %s",
×
154
                                    lf->get_filename().c_str());
155
                          lss.find_data(lf) | [](auto ld) {
×
156
                              ld->get_file_ptr()->set_indexing(!ld->ld_visible);
×
157
                              ld->set_visibility(!ld->ld_visible);
×
158
                          };
159

160
                          auto top_view = *lnav_data.ld_view_stack.top();
×
161
                          auto tss = top_view->get_sub_source();
×
162

163
                          if (tss != nullptr) {
×
164
                              if (tss != &lss) {
×
165
                                  lss.text_filters_changed();
×
166
                                  lnav_data.ld_views[LNV_LOG].reload_data();
×
167
                              }
168
                              tss->text_filters_changed();
×
169
                              top_view->reload_data();
×
170
                          }
171

172
                          lv.reload_data();
×
173
                      });
×
174
            return true;
×
175
        }
176
        case 'n': {
×
177
            execute_command(lnav_data.ld_exec_context, "next-mark search");
×
178
            return true;
×
179
        }
180
        case 'N': {
×
181
            execute_command(lnav_data.ld_exec_context, "prev-mark search");
×
182
            return true;
×
183
        }
184
        case '/': {
×
185
            execute_command(lnav_data.ld_exec_context, "prompt search-files");
×
186
            return true;
×
187
        }
188
        case 'X': {
×
189
            auto sel = files_model::from_selection(lv.get_selection());
×
190

191
            sel.match(
×
192
                [](files_model::no_selection) {},
×
NEW
193
                [&](files_model::stub_selection& es) {
×
194
                    auto& fc = lnav_data.ld_active_files;
×
195

196
                    fc.fc_file_names.erase(es.sb_iter.first);
×
197

198
                    auto name_iter = fc.fc_file_names.begin();
×
199
                    while (name_iter != fc.fc_file_names.end()) {
×
200
                        if (name_iter->first == es.sb_iter.first) {
×
201
                            name_iter = fc.fc_file_names.erase(name_iter);
×
202
                            continue;
×
203
                        }
204

205
                        auto rp_opt = humanize::network::path::from_str(
206
                            name_iter->first);
×
207

208
                        if (rp_opt) {
×
209
                            auto rp = *rp_opt;
×
210

211
                            if (fmt::to_string(rp.home()) == es.sb_iter.first) {
×
212
                                fc.fc_other_files.erase(name_iter->first);
×
213
                                name_iter = fc.fc_file_names.erase(name_iter);
×
214
                                continue;
×
215
                            }
216
                        }
217
                        ++name_iter;
×
218
                    }
219

NEW
220
                    fc.fc_name_to_stubs->writeAccess()->erase(es.sb_iter.first);
×
221
                    fc.fc_invalidate_merge = true;
×
222
                    lv.reload_data();
×
223
                },
×
224
                [](files_model::other_selection) {},
×
225
                [](files_model::file_selection) {});
×
226
            return true;
×
227
        }
228
    }
229
    return false;
1✔
230
}
231

232
void
233
files_sub_source::list_input_handle_scroll_out(listview_curses& lv)
×
234
{
235
    set_view_mode(ln_mode_t::PAGING);
×
236
    lnav_data.ld_filter_view.reload_data();
×
237
}
238

239
size_t
240
files_sub_source::text_line_count()
3,700✔
241
{
242
    const auto& fc = lnav_data.ld_active_files;
3,700✔
243
    auto retval = fc.fc_name_to_stubs->readAccess()->size()
3,700✔
244
        + fc.fc_other_files.size() + fc.fc_files.size();
3,700✔
245

246
    return retval;
3,700✔
247
}
248

249
size_t
250
files_sub_source::text_line_width(textview_curses& curses)
1✔
251
{
252
    return 512;
1✔
253
}
254

255
line_info
256
files_sub_source::text_value_for_line(textview_curses& tc,
1✔
257
                                      int line,
258
                                      std::string& value_out,
259
                                      text_sub_source::line_flags_t flags)
260
{
261
    bool selected = line == tc.get_selection();
1✔
262
    role_t cursor_role = lnav_data.ld_mode == ln_mode_t::FILES
2✔
263
        ? role_t::VCR_CURSOR_LINE
1✔
264
        : role_t::VCR_DISABLED_CURSOR_LINE;
265
    const auto& fc = lnav_data.ld_active_files;
1✔
266
    auto filename_width = std::min(fc.fc_largest_path_length, (size_t) 30);
1✔
267

268
    this->fss_curr_line.clear();
1✔
269
    auto& al = this->fss_curr_line;
1✔
270
    attr_line_builder alb(al);
1✔
271

272
    if (selected) {
1✔
273
        al.append(" ", VC_GRAPHIC.value(NCACS_RARROW));
1✔
274
    } else {
275
        al.append(" ");
×
276
    }
277
    {
278
        safe::ReadAccess<safe_name_to_stubs> errs(*fc.fc_name_to_stubs);
1✔
279

280
        if (line < (ssize_t) errs->size()) {
1✔
281
            auto iter = std::next(errs->begin(), line);
×
282
            auto path = std::filesystem::path(iter->first);
×
283
            auto fn = fmt::to_string(path.filename());
×
284

285
            truncate_to(fn, filename_width);
×
286
            al.append("   ");
×
287
            {
NEW
288
                auto ag = alb.with_attr(VC_ROLE.value(role_t::VCR_FILE));
×
289

290
                al.appendf(FMT_STRING("{:<{}}"), fn, filename_width);
×
291
            }
NEW
292
            al.append("   ");
×
NEW
293
            ui_icon_t icon = ui_icon_t::ok;
×
NEW
294
            switch (iter->second.fei_description.um_level) {
×
NEW
295
                case lnav::console::user_message::level::raw:
×
NEW
296
                    break;
×
NEW
297
                case lnav::console::user_message::level::ok:
×
NEW
298
                    icon = ui_icon_t::ok;
×
NEW
299
                    break;
×
NEW
300
                case lnav::console::user_message::level::info:
×
NEW
301
                    icon = ui_icon_t::info;
×
NEW
302
                    break;
×
NEW
303
                case lnav::console::user_message::level::warning:
×
NEW
304
                    icon = ui_icon_t::warning;
×
NEW
305
                    break;
×
NEW
306
                case lnav::console::user_message::level::error:
×
NEW
307
                    icon = ui_icon_t::error;
×
NEW
308
                    break;
×
309
            }
NEW
310
            al.append(" ", VC_ICON.value(icon));
×
311
            if (selected) {
×
312
                al.with_attr_for_all(VC_ROLE.value(cursor_role));
×
313
            }
314

315
            value_out = al.get_string();
×
316
            return {};
×
317
        }
318

319
        line -= errs->size();
1✔
320
    }
1✔
321

322
    if (line < (ssize_t) fc.fc_other_files.size()) {
1✔
323
        auto iter = std::next(fc.fc_other_files.begin(), line);
×
324
        auto path = std::filesystem::path(iter->first);
×
325
        auto fn = fmt::to_string(path);
×
326

327
        truncate_to(fn, filename_width);
×
328
        al.append("   ");
×
329
        {
330
            auto ag = alb.with_attr(VC_ROLE.value(role_t::VCR_FILE));
×
331

332
            al.appendf(FMT_STRING("{:<{}}"), fn, filename_width);
×
333
        }
334
        al.append("   ")
×
335
            .appendf(FMT_STRING("{:14}"), iter->second.ofd_format)
×
336
            .append("  ")
×
337
            .append(iter->second.ofd_description);
×
338
        if (selected) {
×
339
            al.with_attr_for_all(VC_ROLE.value(cursor_role));
×
340
        }
341
        if (line == (ssize_t) fc.fc_other_files.size() - 1) {
×
342
            al.with_attr_for_all(VC_STYLE.value(text_attrs::with_underline()));
×
343
        }
344

345
        value_out = al.get_string();
×
346
        return {};
×
347
    }
348

349
    line -= fc.fc_other_files.size();
1✔
350

351
    const auto& lf = fc.fc_files[line];
1✔
352
    auto ld_opt = lnav_data.ld_log_source.find_data(lf);
1✔
353
    auto fn = fmt::to_string(std::filesystem::path(lf->get_unique_path()));
1✔
354

355
    truncate_to(fn, filename_width);
1✔
356
    al.append(" ");
1✔
357
    if (ld_opt) {
1✔
358
        if (ld_opt.value()->ld_visible) {
1✔
359
            al.append("\u25c6"_ok);
1✔
360
        } else {
361
            al.append("\u25c7"_comment);
×
362
        }
363
    } else {
364
        al.append("\u25c6"_comment);
×
365
    }
366
    al.append(" ");
1✔
367
    al.appendf(FMT_STRING("{:<{}}"), fn, filename_width);
4✔
368
    al.append("  ");
1✔
369
    {
370
        auto ag = alb.with_attr(VC_ROLE.value(role_t::VCR_NUMBER));
1✔
371

372
        al.appendf(FMT_STRING("{:>8}"),
4✔
373
                   humanize::file_size(lf->get_index_size(),
2✔
374
                                       humanize::alignment::columnar));
375
    }
1✔
376
    al.append(" ");
1✔
377
    auto indexed_size = lf->get_indexed_file_offset();
1✔
378
    auto total_size = lf->get_content_size();
1✔
379
    if (!lf->get_decompress_error().empty()) {
1✔
380
        al.append(" ", VC_ICON.value(ui_icon_t::error));
×
381
    } else if (!lf->get_notes().empty()) {
1✔
382
        al.append(" ", VC_ICON.value(ui_icon_t::warning));
×
383
    } else if (indexed_size < total_size) {
1✔
384
        al.append(humanize::sparkline(indexed_size, total_size));
×
385
    } else {
386
        al.append(" ", VC_ICON.value(ui_icon_t::ok));
1✔
387
    }
388
    if (selected) {
1✔
389
        al.with_attr_for_all(VC_ROLE.value(cursor_role));
1✔
390
    }
391

392
    value_out = al.get_string();
1✔
393
    this->fss_last_line_len = value_out.length();
1✔
394

395
    return {};
1✔
396
}
1✔
397

398
void
399
files_sub_source::text_attrs_for_line(textview_curses& tc,
1✔
400
                                      int line,
401
                                      string_attrs_t& value_out)
402
{
403
    value_out = this->fss_curr_line.get_attrs();
1✔
404
}
1✔
405

406
size_t
407
files_sub_source::text_size_for_line(textview_curses& tc,
×
408
                                     int line,
409
                                     text_sub_source::line_flags_t raw)
410
{
411
    return 0;
×
412
}
413

414
static auto
415
spinner_index()
×
416
{
417
    auto now = ui_clock::now();
×
418

419
    return std::chrono::duration_cast<std::chrono::milliseconds>(
×
420
               now.time_since_epoch())
×
421
               .count()
×
422
        / 100;
×
423
}
424

425
bool
426
files_overlay_source::list_static_overlay(const listview_curses& lv,
15✔
427
                                          media_t media,
428
                                          int y,
429
                                          int bottom,
430
                                          attr_line_t& value_out)
431
{
432
    if (y != 0) {
15✔
433
        return false;
12✔
434
    }
435
    static const char PROG[] = "-\\|/";
436
    constexpr size_t PROG_SIZE = sizeof(PROG) - 1;
3✔
437

438
    auto& fc = lnav_data.ld_active_files;
3✔
439
    auto fc_prog = fc.fc_progress;
3✔
440
    safe::WriteAccess<safe_scan_progress> sp(*fc_prog);
3✔
441

442
    if (!sp->sp_extractions.empty()) {
3✔
443
        const auto& prog = sp->sp_extractions.front();
×
444

445
        value_out.with_ansi_string(fmt::format(
×
446
            "{} Extracting " ANSI_COLOR(COLOR_CYAN) "{}" ANSI_NORM
447
                                                    "... {:>8}/{}",
448
            PROG[spinner_index() % PROG_SIZE],
×
449
            prog.ep_path.filename().string(),
×
450
            humanize::file_size(prog.ep_out_size, humanize::alignment::none),
×
451
            humanize::file_size(prog.ep_total_size,
×
452
                                humanize::alignment::none)));
453
        return true;
×
454
    }
455
    if (!sp->sp_tailers.empty()) {
3✔
456
        auto first_iter = sp->sp_tailers.begin();
×
457

458
        value_out.with_ansi_string(fmt::format(
×
459
            "{} Connecting to " ANSI_COLOR(COLOR_CYAN) "{}" ANSI_NORM ": {}",
460
            PROG[spinner_index() % PROG_SIZE],
×
461
            first_iter->first,
×
462
            first_iter->second.tp_message));
×
463
        return true;
×
464
    }
465

466
    return false;
3✔
467
}
3✔
468

469
bool
470
files_sub_source::text_handle_mouse(
×
471
    textview_curses& tc,
472
    const listview_curses::display_line_content_t&,
473
    mouse_event& me)
474
{
475
    auto nci = ncinput{};
×
476
    if (me.is_click_in(mouse_button_t::BUTTON_LEFT, 1, 3)) {
×
477
        nci.id = ' ';
×
478
        nci.eff_text[0] = ' ';
×
479
        this->list_input_handle_key(tc, nci);
×
480
    }
481
    if (me.is_double_click_in(mouse_button_t::BUTTON_LEFT, line_range{4, -1})) {
×
482
        nci.id = '\r';
×
483
        nci.eff_text[0] = '\r';
×
484
        this->list_input_handle_key(tc, nci);
×
485
    }
486

487
    return false;
×
488
}
489

490
void
491
files_sub_source::text_selection_changed(textview_curses& tc)
21✔
492
{
493
    auto sel = files_model::from_selection(tc.get_selection());
21✔
494
    std::vector<attr_line_t> details;
21✔
495

496
    this->fss_details_mtime = std::chrono::microseconds::zero();
21✔
497
    sel.match(
21✔
498
        [](files_model::no_selection) {},
×
499

NEW
500
        [&details](const files_model::stub_selection& es) {
×
NEW
501
            es.sb_iter.second.to_attr_line().split_lines(details);
×
502
        },
×
503
        [&details](const files_model::other_selection& os) {
×
504
            auto path = std::filesystem::path(os.sb_iter->first);
×
505

506
            details.emplace_back(
×
507
                attr_line_t().appendf(FMT_STRING("Full path: {}"), path));
×
508
            details.emplace_back(attr_line_t("  ").append("Match Details"_h3));
×
509
            for (const auto& msg : os.sb_iter->second.ofd_details) {
×
510
                auto msg_al = msg.to_attr_line();
×
511

512
                for (auto& msg_line : msg_al.rtrim().split_lines()) {
×
513
                    msg_line.insert(0, 4, ' ');
×
514
                    details.emplace_back(msg_line);
×
515
                }
516
            }
517
        },
×
518
        [&details, this](const files_model::file_selection& fs) {
21✔
519
            static constexpr auto NAME_WIDTH = 17;
520

521
            auto lf = *fs.sb_iter;
8✔
522
            this->fss_details_mtime = lf->get_modified_time();
8✔
523
            auto path = lf->get_filename();
8✔
524
            auto actual_path = lf->get_actual_path();
8✔
525
            auto format = lf->get_format();
8✔
526
            const auto& open_opts = lf->get_open_options();
8✔
527

528
            details.emplace_back(attr_line_t()
16✔
529
                                     .appendf(FMT_STRING("{}"), path.filename())
40✔
530
                                     .with_attr_for_all(VC_STYLE.value(
16✔
531
                                         text_attrs::with_bold())));
16✔
532
            details.emplace_back(
8✔
533
                attr_line_t("  ")
8✔
534
                    .append(":open_file_folder:"_emoji)
16✔
535
                    .appendf(FMT_STRING(" {}"), path.parent_path()));
32✔
536

537
            const auto& decompress_err = lf->get_decompress_error();
8✔
538
            if (!decompress_err.empty()) {
8✔
539
                details.emplace_back(
×
540
                    attr_line_t("  ")
×
541
                        .append("Error"_h2)
×
542
                        .append(": ")
×
543
                        .append(lnav::roles::error(decompress_err)));
×
544
            }
545

546
            const auto notes = lf->get_notes();
8✔
547
            if (!notes.empty()) {
8✔
548
                details.emplace_back(
×
549
                    attr_line_t("  ").append("Notes"_h2).append(":"));
×
550
                for (const auto& note_um : notes.values()) {
×
551
                    for (const auto& note_line :
×
552
                         note_um.to_attr_line().split_lines())
×
553
                    {
554
                        details.emplace_back(
×
555
                            attr_line_t("    ").append(note_line));
×
556
                    }
557
                }
558
            }
559
            details.emplace_back(attr_line_t("  ").append("General"_h2));
8✔
560
            if (actual_path) {
8✔
561
                if (path != actual_path.value()) {
8✔
562
                    auto line = attr_line_t()
×
563
                                    .append("Actual Path"_h3)
×
564
                                    .right_justify(NAME_WIDTH)
×
565
                                    .append(": ")
×
566
                                    .append(lnav::roles::file(
×
567
                                        fmt::to_string(actual_path.value())))
×
568
                                    .move();
×
569
                    details.emplace_back(line);
×
570
                }
571
            } else {
572
                details.emplace_back(attr_line_t().append("  Piped"));
×
573
            }
574
            details.emplace_back(
8✔
575
                attr_line_t()
8✔
576
                    .append("MIME Type"_h3)
8✔
577
                    .right_justify(NAME_WIDTH)
8✔
578
                    .append(": ")
8✔
579
                    .append(fmt::to_string(lf->get_text_format())));
16✔
580
            auto ltime = std::chrono::seconds{
581
                convert_log_time_to_local(lf->get_stat().st_mtime)};
8✔
582
            auto ltime_str = lnav::to_rfc3339_string(ltime, 'T');
8✔
583
            details.emplace_back(attr_line_t()
16✔
584
                                     .append("Last Modified"_h3)
8✔
585
                                     .right_justify(NAME_WIDTH)
8✔
586
                                     .append(": ")
8✔
587
                                     .append(ltime_str));
588
            details.emplace_back(
8✔
589
                attr_line_t()
8✔
590
                    .append("Size"_h3)
8✔
591
                    .right_justify(NAME_WIDTH)
8✔
592
                    .append(": ")
8✔
593
                    .append(humanize::file_size(lf->get_index_size(),
16✔
594
                                                humanize::alignment::none)));
595
            if (lf->is_compressed()) {
8✔
596
                details.emplace_back(attr_line_t()
×
597
                                         .append("Compressed Size"_h3)
×
598
                                         .right_justify(NAME_WIDTH)
×
599
                                         .append(": ")
×
600
                                         .append(humanize::file_size(
×
601
                                             lf->get_stat().st_size,
×
602
                                             humanize::alignment::none)));
603
            }
604

605
            details.emplace_back(attr_line_t()
16✔
606
                                     .append("Lines"_h3)
8✔
607
                                     .right_justify(NAME_WIDTH)
8✔
608
                                     .append(": ")
8✔
609
                                     .append(lnav::roles::number(fmt::format(
16✔
610
                                         FMT_STRING("{:L}"), lf->size()))));
32✔
611
            if (format != nullptr && lf->size() > 0) {
8✔
612
                auto tr = lf->get_content_time_range();
7✔
613
                details.emplace_back(attr_line_t()
14✔
614
                                         .append("Time Range"_h3)
7✔
615
                                         .right_justify(NAME_WIDTH)
7✔
616
                                         .append(": ")
7✔
617
                                         .append(lnav::to_rfc3339_string(
14✔
618
                                             to_timeval(tr.tr_begin), 'T'))
619
                                         .append(" - ")
7✔
620
                                         .append(lnav::to_rfc3339_string(
14✔
621
                                             to_timeval(tr.tr_end), 'T')));
622
                if (open_opts.loo_time_range.has_lower_bound()) {
7✔
NEW
623
                    details.emplace_back(
×
NEW
624
                        attr_line_t()
×
NEW
625
                            .append("Cutoff From"_h3)
×
NEW
626
                            .right_justify(NAME_WIDTH)
×
NEW
627
                            .append(": ")
×
NEW
628
                            .append(lnav::to_rfc3339_string(
×
629
                                to_timeval(open_opts.loo_time_range.tr_begin),
630
                                'T')));
631
                }
632
                if (open_opts.loo_time_range.has_upper_bound()) {
7✔
NEW
633
                    details.emplace_back(
×
NEW
634
                        attr_line_t()
×
NEW
635
                            .append("Cutoff To"_h3)
×
NEW
636
                            .right_justify(NAME_WIDTH)
×
NEW
637
                            .append(": ")
×
NEW
638
                            .append(lnav::to_rfc3339_string(
×
639
                                to_timeval(open_opts.loo_time_range.tr_end),
640
                                'T')));
641
                }
642
                details.emplace_back(
7✔
643
                    attr_line_t()
14✔
644
                        .append("Duration"_h3)
7✔
645
                        .right_justify(NAME_WIDTH)
7✔
646
                        .append(": ")
7✔
647
                        .append(humanize::time::duration::from_tv(
7✔
648
                                    lf->back().get_timeval()
7✔
649
                                    - lf->front().get_timeval())
14✔
650
                                    .to_string()));
14✔
651
            }
652

653
            auto file_options_opt = lf->get_file_options();
8✔
654
            if (file_options_opt) {
8✔
655
                auto& [path, file_options] = file_options_opt.value();
×
656

657
                details.emplace_back(attr_line_t()
×
658
                                         .append("Options Path"_h3)
×
659
                                         .right_justify(NAME_WIDTH)
×
660
                                         .append(": ")
×
661
                                         .append(lnav::roles::file(path)));
×
662
                if (file_options.fo_default_zone.pp_value != nullptr) {
×
663
                    details.emplace_back(attr_line_t()
×
664
                                             .append("Timezone"_h3)
×
665
                                             .right_justify(NAME_WIDTH)
×
666
                                             .append(": ")
×
667
                                             .append(lnav::roles::symbol(
×
668
                                                 file_options.fo_default_zone
669
                                                     .pp_value->name())));
×
670
                }
671
            }
672

673
            {
674
                details.emplace_back(
8✔
675
                    attr_line_t()
8✔
676
                        .append("Provenance"_h3)
8✔
677
                        .right_justify(NAME_WIDTH)
8✔
678
                        .append(": ")
8✔
679
                        .append(fmt::to_string(open_opts.loo_source)));
16✔
680
                details.emplace_back(
8✔
681
                    attr_line_t()
8✔
682
                        .append("Flags"_h3)
8✔
683
                        .right_justify(NAME_WIDTH)
8✔
684
                        .append(": ")
8✔
685
                        .append(lnav::roles::for_flag(
16✔
686
                            "\u2022", open_opts.loo_include_in_session))
8✔
687
                        .append("include-in-session")
8✔
688
                        .append(", ")
8✔
689
                        .append(lnav::roles::for_flag(
16✔
690
                            "\u2022", open_opts.loo_detect_format))
8✔
691
                        .append("detect-format"));
692
                if (open_opts.loo_init_location.valid()) {
8✔
693
                    auto loc = open_opts.loo_init_location.match(
694
                        [](default_for_text_format) {
8✔
695
                            return std::string("default");
16✔
696
                        },
697
                        [](file_location_tail) { return std::string("tail"); },
×
698
                        [](int vl) {
×
699
                            return fmt::format(FMT_STRING("L{:L}"), vl);
×
700
                        },
701
                        [](std::string section) { return section; });
8✔
702
                    details.emplace_back(attr_line_t()
16✔
703
                                             .append("Initial Location"_h3)
8✔
704
                                             .right_justify(NAME_WIDTH)
8✔
705
                                             .append(": ")
8✔
706
                                             .append(loc));
707
                }
8✔
708
            }
709

710
            {
711
                auto line = attr_line_t("  ")
16✔
712
                                .append("Log Format"_h2)
8✔
713
                                .append(": ")
8✔
714
                                .move();
8✔
715

716
                if (format != nullptr) {
8✔
717
                    line.append(lnav::roles::identifier(
7✔
718
                        format->get_name().to_string()));
14✔
719
                } else {
720
                    line.append("(none)"_comment);
1✔
721
                }
722
                details.emplace_back(line);
8✔
723
            }
8✔
724

725
            if (lf->get_format_ptr() != nullptr) {
8✔
726
                const auto um = lnav::console::user_message::info(
727
                    attr_line_t("The file contents matched this log format and "
14✔
728
                                "will be shown in the LOG view"));
7✔
729
                um.to_attr_line().rtrim().split_lines()
14✔
730
                    | lnav::itertools::for_each([&details](const auto& al) {
14✔
731
                          details.emplace_back(attr_line_t("    ").append(al));
7✔
732
                      });
7✔
733
            } else {
7✔
734
                auto cmd
735
                    = attr_line_t("lnav -m format ")
1✔
736
                          .append("format-name",
1✔
737
                                  VC_STYLE.value(text_attrs::with_underline()))
2✔
738
                          .append(" test ")
1✔
739
                          .append(lf->get_filename())
1✔
740
                          .with_attr_for_all(
1✔
741
                              VC_ROLE.value(role_t::VCR_QUOTED_CODE));
2✔
742
                const auto um
743
                    = lnav::console::user_message::info(
2✔
744

745
                          "The file contents did not match any log "
746
                          "formats and can be accessed in the TEXT view")
747
                          .with_help(attr_line_t("If you expected this file to "
2✔
748
                                                 "match a particular "
749
                                                 "format, you can run the "
750
                                                 "following to get more "
751
                                                 "details:\n  ")
752
                                         .append(cmd));
1✔
753
                um.to_attr_line().rtrim().split_lines()
2✔
754
                    | lnav::itertools::for_each([&details](const auto& al) {
2✔
755
                          details.emplace_back(attr_line_t("    ").append(al));
3✔
756
                      });
3✔
757
            }
1✔
758

759
            const auto& match_msgs = lf->get_format_match_messages();
8✔
760
            details.emplace_back(
8✔
761
                attr_line_t("    ").append("Match Details"_h3));
16✔
762
            for (const auto& msg : match_msgs) {
95✔
763
                auto msg_al = msg.to_attr_line();
87✔
764

765
                for (auto& msg_line : msg_al.rtrim().split_lines()) {
400✔
766
                    msg_line.insert(0, 6, ' ');
313✔
767
                    details.emplace_back(msg_line);
313✔
768
                }
87✔
769
            }
87✔
770

771
            const auto& ili = lf->get_invalid_line_info();
8✔
772
            if (ili.ili_total > 0) {
8✔
773
                auto dotdot = ili.ili_total
×
774
                    > logfile::invalid_line_info::MAX_INVALID_LINES;
775
                auto um = lnav::console::user_message::error(
×
776
                              attr_line_t()
×
777
                                  .append(lnav::roles::number(
×
778
                                      fmt::to_string(ili.ili_total)))
×
779
                                  .append(" line(s) are not handled by the "
×
780
                                          "format and considered invalid"))
781
                              .with_note(attr_line_t("Lines: ")
×
782
                                             .join(ili.ili_lines, ", ")
×
783
                                             .append(dotdot ? ", ..." : ""))
×
784
                              .with_help(
×
785
                                  "The format may be need to be adjusted to "
786
                                  "capture these lines");
×
787

788
                details.emplace_back(attr_line_t());
×
789
                um.to_attr_line().rtrim().split_lines()
×
790
                    | lnav::itertools::for_each([&details](const auto& al) {
×
791
                          details.emplace_back(attr_line_t("    ").append(al));
×
792
                      });
×
793
            }
794

795
            {
796
                const auto& meta = lf->get_embedded_metadata();
8✔
797

798
                if (!meta.empty()) {
8✔
799
                    details.emplace_back(
×
800
                        attr_line_t("  ").append("Embedded Metadata:"_h2));
×
801
                    for (const auto& [index, meta_pair] :
×
802
                         lnav::itertools::enumerate(meta))
×
803
                    {
804
                        details.emplace_back(
×
805
                            attr_line_t("  ")
×
806
                                .appendf(FMT_STRING("[{}]"), index)
×
807
                                .append(" ")
×
808
                                .append(lnav::roles::h3(meta_pair.first)));
×
809
                        details.emplace_back(
×
810
                            attr_line_t("      MIME Type: ")
×
811
                                .append(lnav::roles::symbol(fmt::to_string(
×
812
                                    meta_pair.second.m_format))));
×
813
                        line_range lr{6, -1};
×
814
                        details.emplace_back(attr_line_t().with_attr(
×
815
                            string_attr{lr, VC_GRAPHIC.value(NCACS_HLINE)}));
×
816
                        const auto val_sf = string_fragment::from_str(
×
817
                            meta_pair.second.m_value);
×
818
                        for (const auto val_line : val_sf.split_lines()) {
×
819
                            details.emplace_back(
×
820
                                attr_line_t("      ").append(val_line));
×
821
                        }
822
                    }
823
                }
824
            }
825
        });
8✔
826

827
    this->fss_details_source->replace_with(details);
21✔
828
}
21✔
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