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

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

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

63.16
/src/textfile_sub_source.hh
1
/**
2
 * Copyright (c) 2007-2012, 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
#ifndef textfile_sub_source_hh
31
#define textfile_sub_source_hh
32

33
#include <deque>
34
#include <memory>
35
#include <unordered_map>
36

37
#include "base/attr_line.hh"
38
#include "base/file_range.hh"
39
#include "document.sections.hh"
40
#include "filter_observer.hh"
41
#include "logfile.hh"
42
#include "plain_text_source.hh"
43
#include "text_overlay_menu.hh"
44
#include "textview_curses.hh"
45

46
class textfile_sub_source
47
    : public text_sub_source
48
    , public vis_location_history
49
    , public text_time_translator
50
    , public text_accel_source
51
    , public text_anchors {
52
public:
53
    textfile_sub_source() { this->tss_supports_filtering = true; }
693✔
54

55
    bool empty() const override { return this->tss_files.empty(); }
10✔
56

UNCOV
57
    size_t size() const { return this->tss_files.size(); }
×
58

59
    size_t text_line_count() override;
60

61
    size_t text_line_width(textview_curses& curses) override
5,246✔
62
    {
63
        return this->tss_files.empty()
5,246✔
64
            ? 0
5,246✔
65
            : this->current_file()->get_longest_line_length();
5,246✔
66
    }
67

68
    line_info text_value_for_line(textview_curses& tc,
69
                                  int line,
70
                                  std::string& value_out,
71
                                  line_flags_t flags) override;
72

73
    void text_attrs_for_line(textview_curses& tc,
74
                             int row,
75
                             string_attrs_t& value_out) override;
76

77
    size_t text_size_for_line(textview_curses& tc,
78
                              int line,
79
                              line_flags_t flags) override;
80

81
    std::shared_ptr<logfile> current_file() const
3,862✔
82
    {
83
        if (this->tss_files.empty()) {
3,862✔
84
            return nullptr;
27✔
85
        }
86

87
        return this->tss_files.front().fvs_file;
3,835✔
88
    }
89

90
    void to_front(const std::shared_ptr<logfile>& lf);
91

92
    bool to_front(const std::string& filename);
93

94
    void set_top_from_off(file_off_t off);
95

96
    void rotate_left();
97

98
    void rotate_right();
99

100
    void remove(const std::shared_ptr<logfile>& lf);
101

102
    void push_back(const std::shared_ptr<logfile>& lf);
103

104
    class scan_callback {
105
    public:
106
        virtual ~scan_callback() = default;
4,029✔
107

108
        virtual void closed_files(
109
            const std::vector<std::shared_ptr<logfile>>& files)
110
            = 0;
111
        virtual void promote_file(const std::shared_ptr<logfile>& lf) = 0;
112
        virtual void scanned_file(const std::shared_ptr<logfile>& lf) = 0;
113
        virtual void renamed_file(const std::shared_ptr<logfile>& lf) = 0;
114
    };
115

116
    struct rescan_result_t {
117
        size_t rr_new_data{0};
118
        bool rr_scan_completed{true};
119
        bool rr_rescan_needed{false};
120
    };
121

122
    rescan_result_t rescan_files(scan_callback& callback,
123
                                 std::optional<ui_clock::time_point> deadline
124
                                 = std::nullopt);
125

126
    void text_filters_changed() override;
127

128
    int get_filtered_count() const override;
129

130
    int get_filtered_count_for(size_t filter_index) const override;
131

132
    text_format_t get_text_format() const override;
133

134
    std::optional<location_history*> get_location_history() override
13✔
135
    {
136
        return this;
13✔
137
    }
138

139
    void text_crumbs_for_line(int line,
140
                              std::vector<breadcrumb::crumb>& crumbs) override;
141

142
    std::optional<vis_line_t> row_for_anchor(const std::string& id) override;
143

144
    std::optional<std::string> anchor_for_row(vis_line_t vl) override;
145

146
    std::optional<vis_line_t> adjacent_anchor(vis_line_t vl,
147
                                              direction dir) override;
148

149
    std::unordered_set<std::string> get_anchors() override;
150

151
    std::optional<vis_line_t> row_for_time(timeval time_bucket) override;
152

153
    std::optional<row_info> time_for_row(vis_line_t row) override;
154

155
    void quiesce() override;
156

157
    bool is_time_offset_supported() const override
×
158
    {
159
        const auto lf = this->current_file();
×
160
        if (lf != nullptr && lf->has_line_metadata()) {
×
161
            return true;
×
162
        }
163

164
        return false;
×
165
    }
166

167
    logline* text_accel_get_line(vis_line_t vl) override;
168

169
    void scroll_invoked(textview_curses* tc) override;
170

171
    enum class view_mode {
172
        raw,
173
        rendered,
174
    };
175

176
    void set_view_mode(view_mode vm);
177

178
    view_mode get_effective_view_mode() const;
179

180
private:
181
    void detach_observer(std::shared_ptr<logfile> lf)
575✔
182
    {
183
        auto* lfo = (line_filter_observer*) lf->get_logline_observer();
575✔
184
        lf->set_logline_observer(nullptr);
575✔
185
        delete lfo;
575✔
186
    }
575✔
187

188
    struct file_view_state {
189
        explicit file_view_state(const std::shared_ptr<logfile>& f)
575✔
190
            : fvs_file(f)
575✔
191
        {
192
        }
575✔
193

194
        bool operator==(const std::shared_ptr<logfile>& lf) const
×
195
        {
196
            return this->fvs_file == lf;
×
197
        }
198

199
        void save_from(const textview_curses& tc)
×
200
        {
201
            this->fvs_top = tc.get_top();
×
202
            this->fvs_selection = tc.get_selection().value_or(-1_vl);
×
203
        }
204

205
        void load_into(textview_curses& tc) const
×
206
        {
207
            tc.set_selection(this->fvs_selection);
×
208
            tc.set_top(this->fvs_top);
×
209
        }
210

211
        std::shared_ptr<logfile> fvs_file;
212
        vis_line_t fvs_top{0};
213
        vis_line_t fvs_selection{0};
214

215
        time_t fvs_mtime;
216
        file_ssize_t fvs_file_size;
217
        file_off_t fvs_file_indexed_size;
218
        std::string fvs_error;
219
        std::unique_ptr<plain_text_source> fvs_text_source;
220
        lnav::document::metadata fvs_metadata;
221
    };
222

223
    using file_iterator = std::deque<file_view_state>::iterator;
224
    using const_file_iterator = std::deque<file_view_state>::const_iterator;
225

226
    file_iterator current_file_state() { return this->tss_files.begin(); }
13,484✔
227

228
    const_file_iterator current_file_state() const
208✔
229
    {
230
        return this->tss_files.cbegin();
208✔
231
    }
232

233
    std::deque<file_view_state> tss_files;
234
    size_t tss_line_indent_size{0};
235
    bool tss_last_scan_aborted{false};
236
    attr_line_t tss_hex_line;
237
    string_attrs_t tss_plain_line_attrs;
238
    int64_t tss_content_line{0};
239
    view_mode tss_view_mode{view_mode::rendered};
240
};
241

242
class textfile_header_overlay : public text_overlay_menu {
243
public:
244
    explicit textfile_header_overlay(
245
        textfile_sub_source* src,
246
        text_sub_source* log_src);
247

248
    bool list_static_overlay(const listview_curses& lv,
249
                             int y,
250
                             int bottom,
251
                             attr_line_t& value_out) override;
252

253
private:
254
    textfile_sub_source* tho_src;
255
    text_sub_source* tho_log_src;
256
    std::vector<attr_line_t> tho_static_lines;
257
    hasher::array_t tho_filter_state;
258
};
259

260
#endif
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