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

tstack / lnav / 20281835752-2752

16 Dec 2025 08:31PM UTC coverage: 68.903% (+0.03%) from 68.87%
20281835752-2752

push

github

tstack
[tests] update test data

51677 of 75000 relevant lines covered (68.9%)

434192.37 hits per line

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

60.0
/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_set>
36
#include <vector>
37

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

48
class textfile_header_overlay;
49

50
class textfile_sub_source
51
    : public text_sub_source
52
    , public vis_location_history
53
    , public text_time_translator
54
    , public text_accel_source
55
    , public text_anchors {
56
public:
57
    textfile_sub_source() { this->tss_supports_filtering = true; }
759✔
58

59
    bool empty() const override { return this->tss_files.empty(); }
1,196✔
60

61
    size_t size() const { return this->tss_files.size(); }
1,720✔
62

63
    size_t text_line_count() override;
64

65
    size_t text_line_width(textview_curses& curses) override;
66

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

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

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

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

86
        return this->tss_files.front().fvs_file;
12,522✔
87
    }
88

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

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

93
    void set_top_from_off(file_off_t off);
94

95
    void rotate_left();
96

97
    void rotate_right();
98

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

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

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

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

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

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

124
    void text_filters_changed() override;
125

126
    int get_filtered_count() const override;
127

128
    int get_filtered_count_for(size_t filter_index) const override;
129

130
    std::optional<text_format_t> get_text_format() const override;
131

132
    std::optional<location_history*> get_location_history() override
22✔
133
    {
134
        return this;
22✔
135
    }
136

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

140
    std::optional<vis_line_t> row_for_anchor(const std::string& id) override;
141

142
    std::optional<std::string> anchor_for_row(vis_line_t vl) override;
143

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

147
    std::unordered_set<std::string> get_anchors() override;
148

149
    std::optional<vis_line_t> row_for_time(timeval time_bucket) override;
150

151
    std::optional<row_info> time_for_row(vis_line_t row) override;
152

153
    void quiesce() override;
154

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

162
        return false;
×
163
    }
164

165
    logline* text_accel_get_line(vis_line_t vl) override;
166

167
    void scroll_invoked(textview_curses* tc) override;
168

169
    enum class view_mode {
170
        raw,
171
        rendered,
172
    };
173

174
    void set_view_mode(view_mode vm);
175

176
    view_mode get_effective_view_mode() const;
177

178
    bool tss_apply_default_init_location{false};
179

180
private:
181
    friend textfile_header_overlay;
182

183
    void detach_observer(std::shared_ptr<logfile> lf)
621✔
184
    {
185
        auto* lfo = (line_filter_observer*) lf->get_logline_observer();
621✔
186
        lf->set_logline_observer(nullptr);
621✔
187
        delete lfo;
621✔
188
    }
621✔
189

190
    struct file_view_state {
191
        explicit file_view_state(const std::shared_ptr<logfile>& f)
621✔
192
            : fvs_file(f)
621✔
193
        {
194
        }
621✔
195

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

201
        void save_from(const textview_curses& tc)
×
202
        {
203
            this->fvs_top = tc.get_top();
×
204
            this->fvs_selection = tc.get_selection();
×
205
        }
206

207
        void load_into(textview_curses& tc) const
×
208
        {
209
            if (this->fvs_selection.has_value()) {
×
210
                tc.set_selection(this->fvs_selection.value());
×
211
            }
212
            tc.set_top(this->fvs_top);
×
213
        }
214

215
        size_t text_line_count(view_mode mode) const;
216

217
        size_t text_line_width(view_mode mode, textview_curses& tc) const;
218

219
        std::optional<vis_line_t> row_for_anchor(view_mode mode,
220
                                                 const std::string& id);
221

222
        std::shared_ptr<logfile> fvs_file;
223
        vis_line_t fvs_top{0};
224
        std::optional<vis_line_t> fvs_selection;
225

226
        time_t fvs_mtime;
227
        file_ssize_t fvs_file_size;
228
        file_off_t fvs_file_indexed_size;
229
        std::string fvs_error;
230
        std::unique_ptr<plain_text_source> fvs_text_source;
231
        lnav::document::metadata fvs_metadata;
232
        bool fvs_consumed_init_location{false};
233
    };
234

235
    using file_iterator = std::deque<file_view_state>::iterator;
236
    using const_file_iterator = std::deque<file_view_state>::const_iterator;
237

238
    void move_to_init_location(file_iterator& iter);
239

240
    file_iterator current_file_state() { return this->tss_files.begin(); }
23,909✔
241

242
    const_file_iterator current_file_state() const
657✔
243
    {
244
        return this->tss_files.cbegin();
657✔
245
    }
246

247
    std::deque<file_view_state> tss_files;
248
    size_t tss_line_indent_size{0};
249
    bool tss_last_scan_aborted{false};
250
    attr_line_t tss_hex_line;
251
    string_attrs_t tss_plain_line_attrs;
252
    int64_t tss_content_line{0};
253
    view_mode tss_view_mode{view_mode::rendered};
254
};
255

256
class textfile_header_overlay : public text_overlay_menu {
257
public:
258
    explicit textfile_header_overlay(textfile_sub_source* src,
259
                                     text_sub_source* log_src);
260

261
    bool list_static_overlay(const listview_curses& lv,
262
                             media_t media,
263
                             int y,
264
                             int bottom,
265
                             attr_line_t& value_out) override;
266

267
    std::optional<attr_line_t> list_header_for_overlay(
268
        const listview_curses& lv, media_t media, vis_line_t line) override;
269

270
    void list_value_for_overlay(const listview_curses& lv,
271
                                vis_line_t line,
272
                                std::vector<attr_line_t>& value_out) override;
273

274
private:
275
    textfile_sub_source* tho_src;
276
    text_sub_source* tho_log_src;
277
    std::vector<attr_line_t> tho_static_lines;
278
    hasher::array_t tho_filter_state;
279
    attr_line_t tho_hex_line_header;
280
};
281

282
#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