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

tstack / lnav / 18602397746-2581

17 Oct 2025 07:07PM UTC coverage: 69.26% (-0.6%) from 69.886%
18602397746-2581

push

github

tstack
[log-view] if the top message is not fully in view, display the first line

82 of 105 new or added lines in 5 files covered. (78.1%)

481 existing lines in 35 files now uncovered.

50183 of 72456 relevant lines covered (69.26%)

415322.24 hits per line

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

5.7
/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 "files_sub_source.hh"
31

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

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

51
namespace files_model {
52
files_list_selection
53
from_selection(std::optional<vis_line_t> sel_vis)
39✔
54
{
55
    if (!sel_vis) {
39✔
56
        return no_selection{};
39✔
57
    }
58

UNCOV
59
    auto& fc = lnav_data.ld_active_files;
×
UNCOV
60
    int sel = sel_vis.value();
×
61

62
    {
UNCOV
63
        safe::ReadAccess<safe_name_to_errors> errs(*fc.fc_name_to_errors);
×
64

UNCOV
65
        if (sel < (ssize_t) errs->size()) {
×
66
            auto iter = errs->begin();
×
67

68
            std::advance(iter, sel);
69
            return error_selection::build(
×
70
                sel, std::make_pair(iter->first, iter->second.fei_description));
×
71
        }
72

UNCOV
73
        sel -= errs->size();
×
74
    }
75

UNCOV
76
    if (sel < (ssize_t) fc.fc_other_files.size()) {
×
77
        auto iter = fc.fc_other_files.begin();
×
78

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

UNCOV
83
    sel -= fc.fc_other_files.size();
×
84

UNCOV
85
    if (sel < (ssize_t) fc.fc_files.size()) {
×
UNCOV
86
        auto iter = fc.fc_files.begin();
×
87

88
        std::advance(iter, sel);
UNCOV
89
        return file_selection::build(sel, iter);
×
90
    }
91

92
    return no_selection{};
×
93
}
94
}  // namespace files_model
95

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

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

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

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

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

134
                    lv.reload_data();
×
135
                    set_view_mode(ln_mode_t::PAGING);
×
136
                });
×
137

138
            return true;
×
139
        }
140

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

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

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

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

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

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

189
            sel.match(
×
190
                [](files_model::no_selection) {},
×
191
                [&](files_model::error_selection& es) {
×
192
                    auto& fc = lnav_data.ld_active_files;
×
193

194
                    fc.fc_file_names.erase(es.sb_iter.first);
×
195

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

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

206
                        if (rp_opt) {
×
207
                            auto rp = *rp_opt;
×
208

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

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

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

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

245
    return retval;
3,667✔
246
}
247

248
size_t
249
files_sub_source::text_line_width(textview_curses& curses)
×
250
{
251
    return 512;
×
252
}
253

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

UNCOV
267
    this->fss_curr_line.clear();
×
UNCOV
268
    auto& al = this->fss_curr_line;
×
UNCOV
269
    attr_line_builder alb(al);
×
270

UNCOV
271
    if (selected) {
×
UNCOV
272
        al.append(" ", VC_GRAPHIC.value(NCACS_RARROW));
×
273
    } else {
274
        al.append(" ");
×
275
    }
276
    {
UNCOV
277
        safe::ReadAccess<safe_name_to_errors> errs(*fc.fc_name_to_errors);
×
278

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

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

289
                al.appendf(FMT_STRING("{:<{}}"), fn, filename_width);
×
290
            }
291
            al.append("   ").append(iter->second.fei_description);
×
292
            if (selected) {
×
293
                al.with_attr_for_all(VC_ROLE.value(cursor_role));
×
294
            }
295

296
            value_out = al.get_string();
×
297
            return {};
×
298
        }
299

UNCOV
300
        line -= errs->size();
×
301
    }
302

UNCOV
303
    if (line < (ssize_t) fc.fc_other_files.size()) {
×
304
        auto iter = std::next(fc.fc_other_files.begin(), line);
×
305
        auto path = std::filesystem::path(iter->first);
×
306
        auto fn = fmt::to_string(path);
×
307

308
        truncate_to(fn, filename_width);
×
309
        al.append("   ");
×
310
        {
311
            auto ag = alb.with_attr(VC_ROLE.value(role_t::VCR_FILE));
×
312

313
            al.appendf(FMT_STRING("{:<{}}"), fn, filename_width);
×
314
        }
315
        al.append("   ")
×
316
            .appendf(FMT_STRING("{:14}"), iter->second.ofd_format)
×
317
            .append("  ")
×
318
            .append(iter->second.ofd_description);
×
319
        if (selected) {
×
320
            al.with_attr_for_all(VC_ROLE.value(cursor_role));
×
321
        }
322
        if (line == (ssize_t) fc.fc_other_files.size() - 1) {
×
323
            al.with_attr_for_all(VC_STYLE.value(text_attrs::with_underline()));
×
324
        }
325

326
        value_out = al.get_string();
×
327
        return {};
×
328
    }
329

UNCOV
330
    line -= fc.fc_other_files.size();
×
331

UNCOV
332
    const auto& lf = fc.fc_files[line];
×
UNCOV
333
    auto ld_opt = lnav_data.ld_log_source.find_data(lf);
×
UNCOV
334
    auto fn = fmt::to_string(std::filesystem::path(lf->get_unique_path()));
×
335

UNCOV
336
    truncate_to(fn, filename_width);
×
UNCOV
337
    al.append(" ");
×
UNCOV
338
    if (ld_opt) {
×
UNCOV
339
        if (ld_opt.value()->ld_visible) {
×
UNCOV
340
            al.append("\u25c6"_ok);
×
341
        } else {
342
            al.append("\u25c7"_comment);
×
343
        }
344
    } else {
UNCOV
345
        al.append("\u25c6"_comment);
×
346
    }
UNCOV
347
    al.append(" ");
×
UNCOV
348
    al.appendf(FMT_STRING("{:<{}}"), fn, filename_width);
×
UNCOV
349
    al.append("  ");
×
350
    {
UNCOV
351
        auto ag = alb.with_attr(VC_ROLE.value(role_t::VCR_NUMBER));
×
352

UNCOV
353
        al.appendf(FMT_STRING("{:>8}"),
×
UNCOV
354
                   humanize::file_size(lf->get_index_size(),
×
355
                                       humanize::alignment::columnar));
356
    }
UNCOV
357
    if (selected) {
×
UNCOV
358
        al.with_attr_for_all(VC_ROLE.value(cursor_role));
×
359
    }
360

UNCOV
361
    value_out = al.get_string();
×
UNCOV
362
    this->fss_last_line_len = value_out.length();
×
363

UNCOV
364
    return {};
×
365
}
366

367
void
UNCOV
368
files_sub_source::text_attrs_for_line(textview_curses& tc,
×
369
                                      int line,
370
                                      string_attrs_t& value_out)
371
{
UNCOV
372
    value_out = this->fss_curr_line.get_attrs();
×
373
}
374

375
size_t
376
files_sub_source::text_size_for_line(textview_curses& tc,
×
377
                                     int line,
378
                                     text_sub_source::line_flags_t raw)
379
{
380
    return 0;
×
381
}
382

383
static auto
384
spinner_index()
×
385
{
386
    auto now = ui_clock::now();
×
387

388
    return std::chrono::duration_cast<std::chrono::milliseconds>(
×
389
               now.time_since_epoch())
×
390
               .count()
×
391
        / 100;
×
392
}
393

394
bool
395
files_overlay_source::list_static_overlay(const listview_curses& lv,
15✔
396
                                          media_t media,
397
                                          int y,
398
                                          int bottom,
399
                                          attr_line_t& value_out)
400
{
401
    if (y != 0) {
15✔
402
        return false;
12✔
403
    }
404
    static const char PROG[] = "-\\|/";
405
    constexpr size_t PROG_SIZE = sizeof(PROG) - 1;
3✔
406

407
    auto& fc = lnav_data.ld_active_files;
3✔
408
    auto fc_prog = fc.fc_progress;
3✔
409
    safe::WriteAccess<safe_scan_progress> sp(*fc_prog);
3✔
410

411
    if (!sp->sp_extractions.empty()) {
3✔
412
        const auto& prog = sp->sp_extractions.front();
×
413

414
        value_out.with_ansi_string(fmt::format(
×
415
            "{} Extracting " ANSI_COLOR(COLOR_CYAN) "{}" ANSI_NORM
416
                                                    "... {:>8}/{}",
417
            PROG[spinner_index() % PROG_SIZE],
×
418
            prog.ep_path.filename().string(),
×
419
            humanize::file_size(prog.ep_out_size, humanize::alignment::none),
×
420
            humanize::file_size(prog.ep_total_size,
×
421
                                humanize::alignment::none)));
422
        return true;
×
423
    }
424
    if (!sp->sp_tailers.empty()) {
3✔
425
        auto first_iter = sp->sp_tailers.begin();
×
426

427
        value_out.with_ansi_string(fmt::format(
×
428
            "{} Connecting to " ANSI_COLOR(COLOR_CYAN) "{}" ANSI_NORM ": {}",
429
            PROG[spinner_index() % PROG_SIZE],
×
430
            first_iter->first,
×
431
            first_iter->second.tp_message));
×
432
        return true;
×
433
    }
434

435
    return false;
3✔
436
}
3✔
437

438
bool
439
files_sub_source::text_handle_mouse(
×
440
    textview_curses& tc,
441
    const listview_curses::display_line_content_t&,
442
    mouse_event& me)
443
{
444
    auto nci = ncinput{};
×
445
    if (me.is_click_in(mouse_button_t::BUTTON_LEFT, 1, 3)) {
×
446
        nci.id = ' ';
×
447
        nci.eff_text[0] = ' ';
×
448
        this->list_input_handle_key(tc, nci);
×
449
    }
450
    if (me.is_double_click_in(mouse_button_t::BUTTON_LEFT, line_range{4, -1})) {
×
451
        nci.id = '\r';
×
452
        nci.eff_text[0] = '\r';
×
453
        this->list_input_handle_key(tc, nci);
×
454
    }
455

456
    return false;
×
457
}
458

459
void
460
files_sub_source::text_selection_changed(textview_curses& tc)
33✔
461
{
462
    auto sel = files_model::from_selection(tc.get_selection());
33✔
463
    std::vector<attr_line_t> details;
33✔
464

465
    this->fss_details_mtime = std::chrono::microseconds::zero();
33✔
466
    sel.match(
33✔
467
        [](files_model::no_selection) {},
×
468

469
        [&details](const files_model::error_selection& es) {
×
470
            auto path = std::filesystem::path(es.sb_iter.first);
×
471

472
            details.emplace_back(
×
473
                attr_line_t().appendf(FMT_STRING("Full path: {}"), path));
×
474
            details.emplace_back(attr_line_t("  ").append(
×
475
                lnav::roles::error(es.sb_iter.second)));
×
476
        },
×
477
        [&details](const files_model::other_selection& os) {
×
478
            auto path = std::filesystem::path(os.sb_iter->first);
×
479

480
            details.emplace_back(
×
481
                attr_line_t().appendf(FMT_STRING("Full path: {}"), path));
×
482
            details.emplace_back(attr_line_t("  ").append("Match Details"_h3));
×
483
            for (const auto& msg : os.sb_iter->second.ofd_details) {
×
484
                auto msg_al = msg.to_attr_line();
×
485

486
                for (auto& msg_line : msg_al.rtrim().split_lines()) {
×
487
                    msg_line.insert(0, 4, ' ');
×
488
                    details.emplace_back(msg_line);
×
489
                }
490
            }
491
        },
×
492
        [&details, this](const files_model::file_selection& fs) {
33✔
493
            static constexpr auto NAME_WIDTH = 17;
494

UNCOV
495
            auto lf = *fs.sb_iter;
×
UNCOV
496
            this->fss_details_mtime = lf->get_modified_time();
×
UNCOV
497
            auto path = lf->get_filename();
×
UNCOV
498
            auto actual_path = lf->get_actual_path();
×
UNCOV
499
            auto format = lf->get_format();
×
UNCOV
500
            const auto& open_opts = lf->get_open_options();
×
501

UNCOV
502
            details.emplace_back(attr_line_t()
×
UNCOV
503
                                     .appendf(FMT_STRING("{}"), path.filename())
×
UNCOV
504
                                     .with_attr_for_all(VC_STYLE.value(
×
UNCOV
505
                                         text_attrs::with_bold())));
×
UNCOV
506
            details.emplace_back(
×
UNCOV
507
                attr_line_t("  ")
×
UNCOV
508
                    .append(":open_file_folder:"_emoji)
×
UNCOV
509
                    .appendf(FMT_STRING(" {}"), path.parent_path()));
×
510

UNCOV
511
            const auto& decompress_err = lf->get_decompress_error();
×
UNCOV
512
            if (!decompress_err.empty()) {
×
513
                details.emplace_back(
×
514
                    attr_line_t("  ")
×
515
                        .append("Error"_h2)
×
516
                        .append(": ")
×
517
                        .append(lnav::roles::error(decompress_err)));
×
518
            }
519

UNCOV
520
            const auto notes = lf->get_notes();
×
UNCOV
521
            if (!notes.empty()) {
×
522
                details.emplace_back(
×
523
                    attr_line_t("  ").append("Notes"_h2).append(":"));
×
524
                for (const auto& [_kind, note_um] : notes) {
×
525
                    for (const auto& note_line :
×
526
                         note_um.to_attr_line().split_lines())
×
527
                    {
528
                        details.emplace_back(
×
529
                            attr_line_t("    ").append(note_line));
×
530
                    }
531
                }
532
            }
UNCOV
533
            details.emplace_back(attr_line_t("  ").append("General"_h2));
×
UNCOV
534
            if (actual_path) {
×
UNCOV
535
                if (path != actual_path.value()) {
×
536
                    auto line = attr_line_t()
×
537
                                    .append("Actual Path"_h3)
×
538
                                    .right_justify(NAME_WIDTH)
×
539
                                    .append(": ")
×
540
                                    .append(lnav::roles::file(
×
541
                                        fmt::to_string(actual_path.value())))
×
542
                                    .move();
×
543
                    details.emplace_back(line);
×
544
                }
545
            } else {
546
                details.emplace_back(attr_line_t().append("  Piped"));
×
547
            }
UNCOV
548
            details.emplace_back(
×
UNCOV
549
                attr_line_t()
×
UNCOV
550
                    .append("MIME Type"_h3)
×
UNCOV
551
                    .right_justify(NAME_WIDTH)
×
UNCOV
552
                    .append(": ")
×
UNCOV
553
                    .append(fmt::to_string(lf->get_text_format())));
×
UNCOV
554
            details.emplace_back(attr_line_t()
×
UNCOV
555
                                     .append("Last Modified"_h3)
×
UNCOV
556
                                     .right_justify(NAME_WIDTH)
×
UNCOV
557
                                     .append(": ")
×
UNCOV
558
                                     .append(lnav::to_rfc3339_string(
×
UNCOV
559
                                         convert_log_time_to_local(
×
560

UNCOV
561
                                             lf->get_stat().st_mtime),
×
562
                                         0,
563
                                         'T')));
UNCOV
564
            details.emplace_back(
×
UNCOV
565
                attr_line_t()
×
UNCOV
566
                    .append("Size"_h3)
×
UNCOV
567
                    .right_justify(NAME_WIDTH)
×
UNCOV
568
                    .append(": ")
×
UNCOV
569
                    .append(humanize::file_size(lf->get_index_size(),
×
570
                                                humanize::alignment::none)));
UNCOV
571
            if (lf->is_compressed()) {
×
572
                details.emplace_back(attr_line_t()
×
573
                                         .append("Compressed Size"_h3)
×
574
                                         .right_justify(NAME_WIDTH)
×
575
                                         .append(": ")
×
576
                                         .append(humanize::file_size(
×
577
                                             lf->get_stat().st_size,
×
578
                                             humanize::alignment::none)));
579
            }
580

UNCOV
581
            details.emplace_back(attr_line_t()
×
UNCOV
582
                                     .append("Lines"_h3)
×
UNCOV
583
                                     .right_justify(NAME_WIDTH)
×
UNCOV
584
                                     .append(": ")
×
UNCOV
585
                                     .append(lnav::roles::number(fmt::format(
×
UNCOV
586
                                         FMT_STRING("{:L}"), lf->size()))));
×
UNCOV
587
            if (format != nullptr && lf->size() > 0) {
×
UNCOV
588
                details.emplace_back(attr_line_t()
×
UNCOV
589
                                         .append("Time Range"_h3)
×
UNCOV
590
                                         .right_justify(NAME_WIDTH)
×
UNCOV
591
                                         .append(": ")
×
UNCOV
592
                                         .append(lnav::to_rfc3339_string(
×
UNCOV
593
                                             lf->front().get_timeval(), 'T'))
×
UNCOV
594
                                         .append(" - ")
×
UNCOV
595
                                         .append(lnav::to_rfc3339_string(
×
UNCOV
596
                                             lf->back().get_timeval(), 'T')));
×
UNCOV
597
                details.emplace_back(
×
UNCOV
598
                    attr_line_t()
×
UNCOV
599
                        .append("Duration"_h3)
×
UNCOV
600
                        .right_justify(NAME_WIDTH)
×
UNCOV
601
                        .append(": ")
×
UNCOV
602
                        .append(humanize::time::duration::from_tv(
×
UNCOV
603
                                    lf->back().get_timeval()
×
UNCOV
604
                                    - lf->front().get_timeval())
×
UNCOV
605
                                    .to_string()));
×
606
            }
607

UNCOV
608
            auto file_options_opt = lf->get_file_options();
×
UNCOV
609
            if (file_options_opt) {
×
610
                auto& [path, file_options] = file_options_opt.value();
×
611

612
                details.emplace_back(attr_line_t()
×
613
                                         .append("Options Path"_h3)
×
614
                                         .right_justify(NAME_WIDTH)
×
615
                                         .append(": ")
×
616
                                         .append(lnav::roles::file(path)));
×
617
                if (file_options.fo_default_zone.pp_value != nullptr) {
×
618
                    details.emplace_back(attr_line_t()
×
619
                                             .append("Timezone"_h3)
×
620
                                             .right_justify(NAME_WIDTH)
×
621
                                             .append(": ")
×
622
                                             .append(lnav::roles::symbol(
×
623
                                                 file_options.fo_default_zone
624
                                                     .pp_value->name())));
×
625
                }
626
            }
627

628
            {
UNCOV
629
                details.emplace_back(
×
UNCOV
630
                    attr_line_t()
×
UNCOV
631
                        .append("Provenance"_h3)
×
UNCOV
632
                        .right_justify(NAME_WIDTH)
×
UNCOV
633
                        .append(": ")
×
UNCOV
634
                        .append(fmt::to_string(open_opts.loo_source)));
×
UNCOV
635
                details.emplace_back(
×
UNCOV
636
                    attr_line_t()
×
UNCOV
637
                        .append("Flags"_h3)
×
UNCOV
638
                        .right_justify(NAME_WIDTH)
×
UNCOV
639
                        .append(": ")
×
UNCOV
640
                        .append(lnav::roles::for_flag(
×
UNCOV
641
                            "\u2022", open_opts.loo_include_in_session))
×
UNCOV
642
                        .append("include-in-session")
×
UNCOV
643
                        .append(", ")
×
UNCOV
644
                        .append(lnav::roles::for_flag(
×
UNCOV
645
                            "\u2022", open_opts.loo_detect_format))
×
646
                        .append("detect-format"));
UNCOV
647
                if (open_opts.loo_init_location.valid()) {
×
648
                    auto loc = open_opts.loo_init_location.match(
649
                        [](file_location_tail) { return std::string("tail"); },
×
650
                        [](int vl) {
×
651
                            return fmt::format(FMT_STRING("L{:L}"), vl);
×
652
                        },
653
                        [](std::string section) { return section; });
×
654
                    details.emplace_back(attr_line_t()
×
655
                                             .append("Initial Location"_h3)
×
656
                                             .right_justify(NAME_WIDTH)
×
657
                                             .append(": ")
×
658
                                             .append(loc));
659
                }
660
            }
661

662
            {
UNCOV
663
                auto line = attr_line_t("  ")
×
UNCOV
664
                                .append("Log Format"_h2)
×
UNCOV
665
                                .append(": ")
×
UNCOV
666
                                .move();
×
667

UNCOV
668
                if (format != nullptr) {
×
UNCOV
669
                    line.append(lnav::roles::identifier(
×
UNCOV
670
                        format->get_name().to_string()));
×
671
                } else {
UNCOV
672
                    line.append("(none)"_comment);
×
673
                }
UNCOV
674
                details.emplace_back(line);
×
675
            }
676

UNCOV
677
            if (lf->get_format_ptr() != nullptr) {
×
678
                const auto um = lnav::console::user_message::info(
UNCOV
679
                    attr_line_t("The file contents matched this log format and "
×
UNCOV
680
                                "will be shown in the LOG view"));
×
UNCOV
681
                um.to_attr_line().rtrim().split_lines()
×
UNCOV
682
                    | lnav::itertools::for_each([&details](const auto& al) {
×
UNCOV
683
                          details.emplace_back(attr_line_t("    ").append(al));
×
UNCOV
684
                      });
×
UNCOV
685
            } else {
×
686
                auto cmd
UNCOV
687
                    = attr_line_t("lnav -m format ")
×
UNCOV
688
                          .append("format-name",
×
UNCOV
689
                                  VC_STYLE.value(text_attrs::with_underline()))
×
UNCOV
690
                          .append(" test ")
×
UNCOV
691
                          .append(lf->get_filename())
×
UNCOV
692
                          .with_attr_for_all(
×
UNCOV
693
                              VC_ROLE.value(role_t::VCR_QUOTED_CODE));
×
694
                const auto um
UNCOV
695
                    = lnav::console::user_message::info(
×
696

697
                          "The file contents did not match any log "
698
                          "formats and can be accessed in the TEXT view")
UNCOV
699
                          .with_help(attr_line_t("If you expected this file to "
×
700
                                                 "match a particular "
701
                                                 "format, you can run the "
702
                                                 "following to get more "
703
                                                 "details:\n  ")
UNCOV
704
                                         .append(cmd));
×
UNCOV
705
                um.to_attr_line().rtrim().split_lines()
×
UNCOV
706
                    | lnav::itertools::for_each([&details](const auto& al) {
×
UNCOV
707
                          details.emplace_back(attr_line_t("    ").append(al));
×
UNCOV
708
                      });
×
709
            }
710

UNCOV
711
            const auto& match_msgs = lf->get_format_match_messages();
×
UNCOV
712
            details.emplace_back(
×
UNCOV
713
                attr_line_t("    ").append("Match Details"_h3));
×
UNCOV
714
            for (const auto& msg : match_msgs) {
×
UNCOV
715
                auto msg_al = msg.to_attr_line();
×
716

UNCOV
717
                for (auto& msg_line : msg_al.rtrim().split_lines()) {
×
UNCOV
718
                    msg_line.insert(0, 6, ' ');
×
UNCOV
719
                    details.emplace_back(msg_line);
×
720
                }
721
            }
722

UNCOV
723
            const auto& ili = lf->get_invalid_line_info();
×
UNCOV
724
            if (ili.ili_total > 0) {
×
725
                auto dotdot = ili.ili_total
×
726
                    > logfile::invalid_line_info::MAX_INVALID_LINES;
727
                auto um = lnav::console::user_message::error(
×
728
                              attr_line_t()
×
729
                                  .append(lnav::roles::number(
×
730
                                      fmt::to_string(ili.ili_total)))
×
731
                                  .append(" line(s) are not handled by the "
×
732
                                          "format and considered invalid"))
733
                              .with_note(attr_line_t("Lines: ")
×
734
                                             .join(ili.ili_lines, ", ")
×
735
                                             .append(dotdot ? ", ..." : ""))
×
736
                              .with_help(
×
737
                                  "The format may be need to be adjusted to "
738
                                  "capture these lines");
×
739

740
                details.emplace_back(attr_line_t());
×
741
                um.to_attr_line().rtrim().split_lines()
×
742
                    | lnav::itertools::for_each([&details](const auto& al) {
×
743
                          details.emplace_back(attr_line_t("    ").append(al));
×
744
                      });
×
745
            }
746

747
            {
UNCOV
748
                const auto& meta = lf->get_embedded_metadata();
×
749

UNCOV
750
                if (!meta.empty()) {
×
751
                    details.emplace_back(
×
752
                        attr_line_t("  ").append("Embedded Metadata:"_h2));
×
753
                    for (const auto& [index, meta_pair] :
×
754
                         lnav::itertools::enumerate(meta))
×
755
                    {
756
                        details.emplace_back(
×
757
                            attr_line_t("  ")
×
758
                                .appendf(FMT_STRING("[{}]"), index)
×
759
                                .append(" ")
×
760
                                .append(lnav::roles::h3(meta_pair.first)));
×
761
                        details.emplace_back(
×
762
                            attr_line_t("      MIME Type: ")
×
763
                                .append(lnav::roles::symbol(fmt::to_string(
×
764
                                    meta_pair.second.m_format))));
×
765
                        line_range lr{6, -1};
×
766
                        details.emplace_back(attr_line_t().with_attr(
×
767
                            string_attr{lr, VC_GRAPHIC.value(NCACS_HLINE)}));
×
768
                        const auto val_sf = string_fragment::from_str(
×
769
                            meta_pair.second.m_value);
×
770
                        for (const auto val_line : val_sf.split_lines()) {
×
771
                            details.emplace_back(
×
772
                                attr_line_t("      ").append(val_line));
×
773
                        }
774
                    }
775
                }
776
            }
UNCOV
777
        });
×
778

779
    this->fss_details_source->replace_with(details);
33✔
780
}
33✔
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