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

tstack / lnav / 30942001121-3077

04 Aug 2026 07:02PM UTC coverage: 70.346% (+0.1%) from 70.251%
30942001121-3077

push

github

tstack
[cmds] add support for named searches

Related to #1736

463 of 588 new or added lines in 17 files covered. (78.74%)

467 existing lines in 16 files now uncovered.

58081 of 82565 relevant lines covered (70.35%)

670976.06 hits per line

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

78.74
/src/session.export.cc
1
/**
2
 * Copyright (c) 2022, 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 "session.export.hh"
31

32
#include "base/injector.hh"
33
#include "base/itertools.hh"
34
#include "bound_tags.hh"
35
#include "lnav.hh"
36
#include "log_vtab_impl.hh"
37
#include "sqlitepp.client.hh"
38
#include "sqlitepp.hh"
39
#include "textview_curses.hh"
40

41
struct log_message_session_state {
42
    int64_t lmss_time_msecs;
43
    std::string lmss_format;
44
    bool lmss_mark;
45
    std::optional<std::string> lmss_comment;
46
    std::optional<std::string> lmss_tags;
47
    std::optional<std::string> lmss_annotations;
48
    std::optional<std::string> lmss_opid;
49
    std::string lmss_hash;
50
};
51

52
template<>
53
struct from_sqlite<log_message_session_state> {
54
    log_message_session_state operator()(int argc,
3✔
55
                                         sqlite3_value** argv,
56
                                         int argi)
57
    {
58
        return {
59
            from_sqlite<int64_t>()(argc, argv, argi + 0),
3✔
60
            from_sqlite<std::string>()(argc, argv, argi + 1),
×
61
            from_sqlite<bool>()(argc, argv, argi + 2),
×
62
            from_sqlite<std::optional<std::string>>()(argc, argv, argi + 3),
×
63
            from_sqlite<std::optional<std::string>>()(argc, argv, argi + 4),
×
64
            from_sqlite<std::optional<std::string>>()(argc, argv, argi + 5),
×
65
            from_sqlite<std::optional<std::string>>()(argc, argv, argi + 6),
×
66
            from_sqlite<std::string>()(argc, argv, argi + 7),
3✔
67
        };
3✔
68
    }
3✔
69
};
70

71
struct log_filter_session_state {
72
    std::string lfss_name;
73
    bool lfss_enabled;
74
    std::string lfss_type;
75
    std::string lfss_language;
76
    std::string lfss_pattern;
77
};
78

79
template<>
80
struct from_sqlite<log_filter_session_state> {
81
    log_filter_session_state operator()(int argc,
4✔
82
                                        sqlite3_value** argv,
83
                                        int argi)
84
    {
85
        return {
86
            from_sqlite<std::string>()(argc, argv, argi + 0),
4✔
87
            from_sqlite<bool>()(argc, argv, argi + 1),
×
88
            from_sqlite<std::string>()(argc, argv, argi + 2),
×
89
            from_sqlite<std::string>()(argc, argv, argi + 3),
×
90
            from_sqlite<std::string>()(argc, argv, argi + 4),
4✔
91
        };
4✔
92
    }
4✔
93
};
94

95
struct named_search_session_state {
96
    std::string nsss_view_name;
97
    std::string nsss_name;
98
    std::string nsss_pattern;
99
};
100

101
template<>
102
struct from_sqlite<named_search_session_state> {
103
    named_search_session_state operator()(int argc,
2✔
104
                                          sqlite3_value** argv,
105
                                          int argi)
106
    {
107
        return {
108
            from_sqlite<std::string>()(argc, argv, argi + 0),
2✔
NEW
109
            from_sqlite<std::string>()(argc, argv, argi + 1),
×
110
            from_sqlite<std::string>()(argc, argv, argi + 2),
2✔
111
        };
2✔
112
    }
2✔
113
};
114

115
struct log_file_session_state {
116
    std::string lfss_content_id;
117
    std::string lfss_format;
118
    int64_t lfss_time_offset;
119
};
120

121
template<>
122
struct from_sqlite<log_file_session_state> {
123
    log_file_session_state operator()(int argc, sqlite3_value** argv, int argi)
×
124
    {
125
        return {
126
            from_sqlite<std::string>()(argc, argv, argi + 0),
×
127
            from_sqlite<std::string>()(argc, argv, argi + 1),
×
128
            from_sqlite<int64_t>()(argc, argv, argi + 2),
×
129
        };
130
    }
131
};
132

133
namespace lnav::session {
134

135
static std::optional<std::filesystem::path>
136
find_container_dir(std::filesystem::path file_path)
7✔
137
{
138
    if (!std::filesystem::exists(file_path)) {
7✔
139
        return std::nullopt;
×
140
    }
141

142
    std::optional<std::filesystem::path> dir_with_last_readme;
7✔
143

144
    while (file_path.has_parent_path()
7✔
145
           && file_path != file_path.root_directory())
16✔
146
    {
147
        auto parent = file_path.parent_path();
16✔
148
        bool has_readme_entry = false;
16✔
149
        std::error_code ec;
16✔
150

151
        for (const auto& entry :
16✔
152
             std::filesystem::directory_iterator(parent, ec))
62,106✔
153
        {
154
            if (!entry.is_regular_file()) {
31,045✔
155
                continue;
223✔
156
            }
157

158
            auto entry_filename = tolower(entry.path().filename().string());
30,822✔
159
            if (startswith(entry_filename, "readme")) {
30,822✔
160
                has_readme_entry = true;
9✔
161
                dir_with_last_readme = parent;
9✔
162
            }
163
        }
30,838✔
164
        if (!has_readme_entry && dir_with_last_readme) {
16✔
165
            return dir_with_last_readme;
7✔
166
        }
167

168
        file_path = parent;
9✔
169
    }
16✔
170

171
    return std::nullopt;
×
172
}
7✔
173

174
static std::string
175
replace_home_dir(std::string path)
2✔
176
{
177
    const auto home_dir_opt = getenv_opt("HOME");
2✔
178

179
    if (!home_dir_opt) {
2✔
180
        return path;
×
181
    }
182

183
    const auto* home_dir = home_dir_opt.value();
2✔
184

185
    if (startswith(path, home_dir)) {
2✔
186
        auto retval = path.substr(strlen(home_dir));
×
187

188
        if (retval.front() != '/') {
×
189
            retval.insert(0, "/");
×
190
        }
191
        retval.insert(0, "$HOME");
×
192
        return retval;
×
193
    }
194

195
    return path;
2✔
196
}
197

198
Result<void, lnav::console::user_message>
199
export_to(FILE* file)
7✔
200
{
201
    auto* vtab_manager = injector::get<log_vtab_manager*>();
7✔
202
    static auto& lnav_db = injector::get<auto_sqlite3&>();
7✔
203

204
    static const char* BOOKMARK_QUERY = R"(
205
SELECT log_time_msecs, log_format, log_mark, log_comment, log_tags, log_annotations, log_user_opid, log_line_hash
206
   FROM all_logs
207
   WHERE log_mark = 1 OR
208
         log_comment IS NOT NULL OR
209
         log_tags IS NOT NULL OR
210
         log_annotations IS NOT NULL OR
211
         (log_user_opid IS NOT NULL AND log_user_opid != '')
212
)";
213

214
    static const char* FILTER_QUERY = R"(
215
SELECT view_name, enabled, type, language, pattern FROM lnav_view_filters
216
)";
217

218
    static const char* SEARCH_QUERY = R"(
219
SELECT view_name, name, pattern FROM lnav_view_searches
220
)";
221

222
    static const char* FILE_QUERY = R"(
223
SELECT content_id, format, time_offset FROM lnav_file
224
  WHERE format IS NOT NULL AND time_offset != 0
225
)";
226

227
    static constexpr char HEADER[] = R"(#!lnav -Nf
228
# This file is an export of an lnav session.  You can type
229
# '|/path/to/this/file' in lnav to execute this file and
230
# restore the state of the session.
231

232
;SELECT raise_error('This session export was made with a newer version of lnav, please upgrade to ' || {0} || ' or later')
233
   WHERE lnav_version() < {0} COLLATE naturalcase
234

235
# The files loaded into the session were:
236

237
)";
238

239
    static constexpr char LOG_DIR_INSERT[] = R"(
240
# Set this environment variable to override this value or edit this script.
241
;INSERT OR IGNORE INTO environ (name, value) VALUES ('LOG_DIR_{}', {})
242
)";
243

244
    static constexpr char MARK_HEADER[] = R"(
245

246
# The following SQL statements will restore the bookmarks,
247
# comments, and tags that were added in the session.
248

249
;SELECT total_changes() AS before_mark_changes
250
)";
251

252
    static constexpr char MARK_FOOTER[] = R"(
253
;SELECT {} - (total_changes() - $before_mark_changes) AS failed_mark_changes
254
;SELECT echoln(printf('%sERROR%s: failed to restore %d bookmarks',
255
                      $ansi_red, $ansi_norm, $failed_mark_changes))
256
    WHERE $failed_mark_changes != 0
257
)";
258

259
    static const char* FILTER_HEADER = R"(
260

261
# The following SQL statements will restore the filters that
262
# were added in the session.
263

264
)";
265

266
    static const char* SEARCH_HEADER = R"(
267

268
# The following SQL statements will restore the named searches
269
# that were created in the session.
270

271
)";
272

273
    static const char* FILE_HEADER = R"(
274

275
# The following SQL statements will restore the state of the
276
# files in the session.
277

278
;SELECT total_changes() AS before_file_changes
279
)";
280

281
    static const char* FIELD_HEADER = R"(
282
# The following field visibility commands were run by the
283
# original user during this session.  Uncomment them if
284
# desired.
285
)";
286

287
    static const char* HIGHLIGHT_HEADER = R"(
288
# The following highlight commands were run by the
289
# original user during this session.  Uncomment them if
290
# desired.
291
)";
292

293
    static constexpr char FILE_FOOTER[] = R"(
294
;SELECT {} - (total_changes() - $before_file_changes) AS failed_file_changes
295
;SELECT echoln(printf('%sERROR%s: failed to restore the state of %d files',
296
                      $ansi_red, $ansi_norm, $failed_file_changes))
297
   WHERE $failed_file_changes != 0
298
)";
299

300
    static constexpr char VIEW_HEADER[] = R"(
301

302
# The following commands will restore the state of the {} view.
303

304
)";
305

306
    auto prep_mark_res = prepare_stmt(lnav_db.in(), BOOKMARK_QUERY);
7✔
307
    if (prep_mark_res.isErr()) {
7✔
308
        return Err(
×
309
            console::user_message::error("unable to export log bookmarks")
×
310
                .with_reason(prep_mark_res.unwrapErr()));
×
311
    }
312

313
    fmt::print(file, FMT_STRING(HEADER), sqlitepp::quote(PACKAGE_VERSION).in());
35✔
314

315
    std::map<std::string, std::vector<std::string>> file_containers;
7✔
316
    std::set<std::string> raw_files;
7✔
317
    for (const auto& name_pair : lnav_data.ld_active_files.fc_file_names) {
15✔
318
        const auto& open_opts = name_pair.second;
8✔
319

320
        if (!open_opts.loo_is_visible || !open_opts.loo_include_in_session
8✔
321
            || !open_opts.loo_filename.empty()
7✔
322
            || open_opts.loo_source != logfile_name_source::USER)
16✔
323
        {
324
            continue;
2✔
325
        }
326

327
        const auto& file_path_str = name_pair.first;
6✔
328
        auto file_path = std::filesystem::path(file_path_str);
6✔
329
        auto container_path_opt = find_container_dir(file_path);
6✔
330
        if (container_path_opt) {
6✔
331
            auto container_parent = container_path_opt.value().parent_path();
6✔
332
            auto file_container_path
333
                = std::filesystem::relative(file_path, container_parent)
12✔
334
                      .string();
6✔
335
            file_containers[container_parent.string()].push_back(
6✔
336
                file_container_path);
337
        } else {
6✔
338
            raw_files.insert(file_path_str);
×
339
        }
340
    }
6✔
341
    for (const auto& lf : lnav_data.ld_active_files.fc_files) {
15✔
342
        if (lf->is_valid_filename()) {
8✔
343
            continue;
6✔
344
        }
345
        if (!lf->get_open_options().loo_include_in_session) {
2✔
346
            continue;
×
347
        }
348

349
        const auto& open_options = lf->get_open_options();
2✔
350
        if (open_options.loo_piper) {
2✔
351
            raw_files.emplace(open_options.loo_piper->get_url());
2✔
352
        }
353
    }
354
    for (const auto& file_path_str : raw_files) {
9✔
355
        fmt::print(
2✔
356
            file, FMT_STRING(":open {}\n"), replace_home_dir(file_path_str));
8✔
357
    }
358
    size_t container_index = 0;
7✔
359
    for (const auto& container_pair : file_containers) {
12✔
360
        fmt::print(file,
5✔
361
                   FMT_STRING(LOG_DIR_INSERT),
10✔
362
                   container_index,
363
                   sqlitepp::quote(container_pair.first).in());
10✔
364
        for (const auto& file_path_str : container_pair.second) {
11✔
365
            fmt::print(file,
6✔
366
                       FMT_STRING(":open $LOG_DIR_{}/{}\n"),
24✔
367
                       container_index,
368
                       file_path_str);
369
        }
370
        container_index += 1;
5✔
371
    }
372

373
    fmt::print(file, FMT_STRING("\n:rebuild\n"));
28✔
374

375
    auto mark_count = 0;
7✔
376
    auto each_mark_res
377
        = prep_mark_res.unwrap().for_each_row<log_message_session_state>(
14✔
378
            [file, &mark_count](const log_message_session_state& lmss) {
3✔
379
                if (mark_count == 0) {
3✔
380
                    fmt::print(file, FMT_STRING(MARK_HEADER));
15✔
381
                }
382
                mark_count += 1;
3✔
383
                fmt::print(file,
6✔
384
                           FMT_STRING(";UPDATE all_logs "
9✔
385
                                      "SET log_mark = {}, "
386
                                      "log_comment = {}, "
387
                                      "log_tags = {}, "
388
                                      "log_annotations = {}, "
389
                                      "log_opid = {} "
390
                                      "WHERE log_time_msecs = {} AND "
391
                                      "log_format = {} AND "
392
                                      "log_line_hash = {}\n"),
393
                           lmss.lmss_mark ? "1" : "0",
3✔
394
                           sqlitepp::quote(lmss.lmss_comment).in(),
6✔
395
                           sqlitepp::quote(lmss.lmss_tags).in(),
6✔
396
                           sqlitepp::quote(lmss.lmss_annotations).in(),
6✔
397
                           sqlitepp::quote(lmss.lmss_opid).in(),
6✔
398
                           lmss.lmss_time_msecs,
3✔
399
                           sqlitepp::quote(lmss.lmss_format).in(),
6✔
400
                           sqlitepp::quote(lmss.lmss_hash).in());
6✔
401
                return false;
3✔
402
            });
7✔
403

404
    if (each_mark_res.isErr()) {
7✔
405
        return Err(console::user_message::error(
×
406
                       "failed to fetch bookmark metadata for log message")
407
                       .with_reason(each_mark_res.unwrapErr().fe_msg));
×
408
    }
409

410
    if (mark_count > 0) {
7✔
411
        fmt::print(file, FMT_STRING(MARK_FOOTER), mark_count);
15✔
412
    }
413

414
    auto prep_filter_res = prepare_stmt(lnav_db.in(), FILTER_QUERY);
7✔
415
    if (prep_filter_res.isErr()) {
7✔
416
        return Err(console::user_message::error("unable to export filter state")
×
417
                       .with_reason(prep_filter_res.unwrapErr()));
×
418
    }
419

420
    auto added_filter_header = false;
7✔
421
    auto each_filter_res
422
        = prep_filter_res.unwrap().for_each_row<log_filter_session_state>(
14✔
423
            [file, &added_filter_header](const log_filter_session_state& lfss) {
4✔
424
                if (!added_filter_header) {
4✔
425
                    fmt::print(file, FMT_STRING("{}"), FILTER_HEADER);
16✔
426
                    added_filter_header = true;
4✔
427
                }
428
                fmt::print(
4✔
429
                    file,
430
                    FMT_STRING(";REPLACE INTO lnav_view_filters "
8✔
431
                               "(view_name, enabled, type, language, pattern) "
432
                               "VALUES ({}, {}, {}, {}, {})\n"),
433
                    sqlitepp::quote(lfss.lfss_name).in(),
8✔
434
                    lfss.lfss_enabled ? 1 : 0,
4✔
435
                    sqlitepp::quote(lfss.lfss_type).in(),
8✔
436
                    sqlitepp::quote(lfss.lfss_language).in(),
8✔
437
                    sqlitepp::quote(lfss.lfss_pattern).in());
8✔
438
                return false;
4✔
439
            });
7✔
440

441
    if (each_filter_res.isErr()) {
7✔
442
        return Err(console::user_message::error(
×
443
                       "failed to fetch filter state for views")
444
                       .with_reason(each_filter_res.unwrapErr().fe_msg));
×
445
    }
446

447
    auto prep_search_res = prepare_stmt(lnav_db.in(), SEARCH_QUERY);
7✔
448
    if (prep_search_res.isErr()) {
7✔
NEW
449
        return Err(
×
NEW
450
            console::user_message::error("unable to export named searches")
×
NEW
451
                .with_reason(prep_search_res.unwrapErr()));
×
452
    }
453

454
    auto added_search_header = false;
7✔
455
    auto each_search_res
456
        = prep_search_res.unwrap().for_each_row<named_search_session_state>(
14✔
457
            [file, &added_search_header](
2✔
458
                const named_search_session_state& nsss) {
459
                if (!added_search_header) {
2✔
460
                    fmt::print(file, FMT_STRING("{}"), SEARCH_HEADER);
4✔
461
                    added_search_header = true;
1✔
462
                }
463
                fmt::print(file,
2✔
464
                           FMT_STRING(";INSERT INTO lnav_view_searches "
4✔
465
                                      "(view_name, name, pattern) "
466
                                      "VALUES ({}, {}, {})\n"),
467
                           sqlitepp::quote(nsss.nsss_view_name).in(),
4✔
468
                           sqlitepp::quote(nsss.nsss_name).in(),
4✔
469
                           sqlitepp::quote(nsss.nsss_pattern).in());
4✔
470
                return false;
2✔
471
            });
7✔
472

473
    if (each_search_res.isErr()) {
7✔
NEW
474
        return Err(console::user_message::error(
×
475
                       "failed to fetch named searches for views")
NEW
476
                       .with_reason(each_search_res.unwrapErr().fe_msg));
×
477
    }
478

479
    auto prep_file_res = prepare_stmt(lnav_db.in(), FILE_QUERY);
7✔
480
    if (prep_file_res.isErr()) {
7✔
481
        return Err(console::user_message::error("unable to export file state")
×
482
                       .with_reason(prep_file_res.unwrapErr()));
×
483
    }
484

485
    auto file_count = 0;
7✔
486
    auto file_stmt = prep_file_res.unwrap();
7✔
487
    auto each_file_res = file_stmt.for_each_row<log_file_session_state>(
488
        [file, &file_count](const log_file_session_state& lfss) {
×
489
            if (file_count == 0) {
×
490
                fmt::print(file, FMT_STRING("{}"), FILE_HEADER);
×
491
            }
492
            file_count += 1;
×
493
            fmt::print(file,
×
494
                       FMT_STRING(";UPDATE lnav_file "
×
495
                                  "SET time_offset = {} "
496
                                  "WHERE content_id = {} AND format = {}\n"),
497
                       lfss.lfss_time_offset,
×
498
                       sqlitepp::quote(lfss.lfss_content_id).in(),
×
499
                       sqlitepp::quote(lfss.lfss_format).in());
×
500
            return false;
×
501
        });
7✔
502

503
    if (each_file_res.isErr()) {
7✔
504
        return Err(console::user_message::error("failed to fetch file state")
×
505
                       .with_reason(each_file_res.unwrapErr().fe_msg));
×
506
    }
507

508
    if (file_count > 0) {
7✔
509
        fmt::print(file, FMT_STRING(FILE_FOOTER), file_count);
×
510
    }
511

512
    for (auto view_index : {LNV_LOG, LNV_TEXT}) {
21✔
513
        auto& tc = lnav_data.ld_views[view_index];
14✔
514
        if (tc.get_inner_height() == 0_vl) {
14✔
515
            continue;
7✔
516
        }
517

518
        fmt::print(file, FMT_STRING(VIEW_HEADER), lnav_view_titles[view_index]);
28✔
519
        fmt::print(file,
7✔
520
                   FMT_STRING(":switch-to-view {}\n"),
21✔
521
                   lnav_view_strings[view_index]);
7✔
522

523
        if (view_index == LNV_LOG) {
7✔
524
            std::vector<std::string> field_cmds;
7✔
525
            for (const auto& format : log_format::get_root_formats()) {
582✔
526
                auto field_states = format->get_field_states();
575✔
527

528
                for (const auto& fs_pair : field_states) {
8,105✔
529
                    if (!fs_pair.second.lvm_user_hidden) {
7,530✔
530
                        continue;
7,529✔
531
                    }
532

533
                    if (fs_pair.second.lvm_user_hidden.value()) {
1✔
534
                        field_cmds.emplace_back(
1✔
535
                            fmt::format(FMT_STRING("# :hide-fields {}.{}\n"),
4✔
536

537
                                        format->get_name(),
2✔
538
                                        fs_pair.first));
1✔
539
                    } else if (fs_pair.second.lvm_hidden) {
×
540
                        field_cmds.emplace_back(
×
541
                            fmt::format(FMT_STRING("# :show-fields {}.{}\n"),
×
542
                                        format->get_name().to_string(),
×
543
                                        fs_pair.first));
×
544
                    }
545
                }
546
            }
575✔
547

548
            if (!field_cmds.empty()) {
7✔
549
                fmt::print(file, FMT_STRING("{}"), FIELD_HEADER);
4✔
550
                field_cmds
551
                    | lnav::itertools::for_each([&file](const auto& cmd) {
1✔
552
                          fmt::print(file, FMT_STRING("{}"), cmd);
4✔
553
                      });
1✔
554
            }
555
        }
7✔
556

557
        {
558
            std::vector<std::string> hl_cmds;
7✔
559
            const auto& hm = tc.get_highlights();
7✔
560
            for (const auto& hl_pair : hm) {
39✔
561
                if (hl_pair.first.first != highlight_source_t::INTERACTIVE) {
32✔
562
                    continue;
31✔
563
                }
564

565
                auto cmd = fmt::format(FMT_STRING("# :highlight {}\n"),
3✔
566
                                       hl_pair.second.h_regex->get_pattern());
1✔
567
                hl_cmds.emplace_back(cmd);
1✔
568
            }
1✔
569

570
            if (!hl_cmds.empty()) {
7✔
571
                fmt::print(file, FMT_STRING("{}"), HIGHLIGHT_HEADER);
4✔
572
                hl_cmds | lnav::itertools::for_each([&file](const auto& cmd) {
1✔
573
                    fmt::print(file, FMT_STRING("{}"), cmd);
4✔
574
                });
1✔
575
                fmt::println(file, FMT_STRING(""));
5✔
576
            }
577
        }
7✔
578

579
        auto* tss = tc.get_sub_source();
7✔
580
        auto* ttt = dynamic_cast<text_time_translator*>(tss);
7✔
581
        if (ttt != nullptr) {
7✔
582
            char tsbuf[128];
583
            auto min_time_opt = ttt->get_min_row_time();
7✔
584
            if (min_time_opt) {
7✔
585
                sql_strftime(tsbuf, sizeof(tsbuf), min_time_opt.value(), 'T');
1✔
586
                fmt::print(file, FMT_STRING(":hide-lines-before {}\n"), tsbuf);
5✔
587
            }
588
            auto max_time_opt = ttt->get_max_row_time();
7✔
589
            if (max_time_opt) {
7✔
590
                sql_strftime(tsbuf, sizeof(tsbuf), max_time_opt.value(), 'T');
1✔
591
                fmt::print(file, FMT_STRING(":hide-lines-after {}\n"), tsbuf);
5✔
592
            }
593
        }
594

595
        auto* lss = dynamic_cast<logfile_sub_source*>(tss);
7✔
596
        if (lss != nullptr) {
7✔
597
            auto min_level = lss->get_min_log_level();
7✔
598

599
            if (min_level != LEVEL_UNKNOWN) {
7✔
600
                fmt::print(file,
1✔
601
                           FMT_STRING(":set-min-log-level {}\n"),
4✔
602
                           level_names[min_level]);
1✔
603
            }
604

605
            for (const auto& ld : *lss) {
15✔
606
                if (ld->is_visible()) {
8✔
607
                    continue;
7✔
608
                }
609

610
                if (ld->get_file_ptr()->get_open_options().loo_source
1✔
611
                    == logfile_name_source::ARCHIVE)
1✔
612
                {
613
                    continue;
×
614
                }
615

616
                auto container_path_opt
617
                    = find_container_dir(ld->get_file_ptr()->get_path());
1✔
618
                if (!container_path_opt) {
1✔
619
                    fmt::print(file,
×
620
                               FMT_STRING(":hide-file {}\n"),
×
621
                               ld->get_file_ptr()->get_path().string());
×
622
                    continue;
×
623
                }
624
                auto container_parent
625
                    = container_path_opt.value().parent_path();
1✔
626
                auto file_container_path = std::filesystem::relative(
627
                    ld->get_file_ptr()->get_path(), container_parent);
1✔
628
                fmt::print(file,
1✔
629
                           FMT_STRING(":hide-file */{}\n"),
3✔
630
                           file_container_path.string());
2✔
631
            }
1✔
632
        }
633

634
        if (!tc.get_current_search().empty()) {
7✔
635
            fmt::print(file, FMT_STRING("/{}\n"), tc.get_current_search());
5✔
636
        }
637

638
        fmt::print(file,
7✔
639
                   FMT_STRING(":goto {}\n"),
14✔
640
                   (int) tc.get_selection().value_or(tc.get_top()));
14✔
641
    }
642

643
    for (const auto& [name, vi] : *vtab_manager) {
669✔
644
        if (vi->vi_provenance != log_vtab_impl::provenance_t::user) {
662✔
645
            continue;
661✔
646
        }
647

648
        auto cmd_opt = vi->get_command();
1✔
649
        if (!cmd_opt) {
1✔
650
            continue;
×
651
        }
652

653
        fmt::print(file, FMT_STRING("\n{}\n"), cmd_opt.value());
4✔
654
    }
1✔
655

656
    return Ok();
7✔
657
}
7✔
658

659
}  // namespace lnav::session
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