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

tstack / lnav / 20114321350-2741

10 Dec 2025 09:41PM UTC coverage: 68.836% (-0.07%) from 68.908%
20114321350-2741

push

github

tstack
[filters] add level filter

41 of 135 new or added lines in 10 files covered. (30.37%)

447 existing lines in 8 files now uncovered.

51534 of 74865 relevant lines covered (68.84%)

434761.7 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_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; }
758✔
54

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

57
    size_t size() const { return this->tss_files.size(); }
1,715✔
58

59
    size_t text_line_count() override;
60

61
    size_t text_line_width(textview_curses& curses) override;
62

63
    line_info text_value_for_line(textview_curses& tc,
64
                                  int line,
65
                                  std::string& value_out,
66
                                  line_flags_t flags) override;
67

68
    void text_attrs_for_line(textview_curses& tc,
69
                             int row,
70
                             string_attrs_t& value_out) override;
71

72
    size_t text_size_for_line(textview_curses& tc,
73
                              int line,
74
                              line_flags_t flags) override;
75

76
    std::shared_ptr<logfile> current_file() const
18,344✔
77
    {
78
        if (this->tss_files.empty()) {
18,344✔
79
            return nullptr;
3,163✔
80
        }
81

82
        return this->tss_files.front().fvs_file;
15,181✔
83
    }
84

85
    void to_front(const std::shared_ptr<logfile>& lf);
86

87
    bool to_front(const std::string& filename);
88

89
    void set_top_from_off(file_off_t off);
90

91
    void rotate_left();
92

93
    void rotate_right();
94

95
    void remove(const std::shared_ptr<logfile>& lf);
96

97
    void push_back(const std::shared_ptr<logfile>& lf);
98

99
    class scan_callback {
100
    public:
101
        virtual ~scan_callback() = default;
4,443✔
102

103
        virtual void closed_files(
104
            const std::vector<std::shared_ptr<logfile>>& files)
105
            = 0;
106
        virtual void promote_file(const std::shared_ptr<logfile>& lf) = 0;
107
        virtual void scanned_file(const std::shared_ptr<logfile>& lf) = 0;
108
        virtual void renamed_file(const std::shared_ptr<logfile>& lf) = 0;
109
    };
110

111
    struct rescan_result_t {
112
        size_t rr_new_data{0};
113
        bool rr_scan_completed{true};
114
        bool rr_rescan_needed{false};
115
    };
116

117
    rescan_result_t rescan_files(scan_callback& callback,
118
                                 std::optional<ui_clock::time_point> deadline
119
                                 = std::nullopt);
120

121
    void text_filters_changed() override;
122

123
    int get_filtered_count() const override;
124

125
    int get_filtered_count_for(size_t filter_index) const override;
126

127
    text_format_t get_text_format() const override;
128

129
    std::optional<location_history*> get_location_history() override
21✔
130
    {
131
        return this;
21✔
132
    }
133

134
    void text_crumbs_for_line(int line,
135
                              std::vector<breadcrumb::crumb>& crumbs) override;
136

137
    std::optional<vis_line_t> row_for_anchor(const std::string& id) override;
138

139
    std::optional<std::string> anchor_for_row(vis_line_t vl) override;
140

141
    std::optional<vis_line_t> adjacent_anchor(vis_line_t vl,
142
                                              direction dir) override;
143

144
    std::unordered_set<std::string> get_anchors() override;
145

146
    std::optional<vis_line_t> row_for_time(timeval time_bucket) override;
147

148
    std::optional<row_info> time_for_row(vis_line_t row) override;
149

150
    void quiesce() override;
151

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

159
        return false;
×
160
    }
161

162
    logline* text_accel_get_line(vis_line_t vl) override;
163

164
    void scroll_invoked(textview_curses* tc) override;
165

166
    enum class view_mode {
167
        raw,
168
        rendered,
169
    };
170

171
    void set_view_mode(view_mode vm);
172

173
    view_mode get_effective_view_mode() const;
174

175
    bool tss_apply_default_init_location{false};
176

177
private:
178
    void detach_observer(std::shared_ptr<logfile> lf)
620✔
179
    {
180
        auto* lfo = (line_filter_observer*) lf->get_logline_observer();
620✔
181
        lf->set_logline_observer(nullptr);
620✔
182
        delete lfo;
620✔
183
    }
620✔
184

185
    struct file_view_state {
186
        explicit file_view_state(const std::shared_ptr<logfile>& f)
620✔
187
            : fvs_file(f)
620✔
188
        {
189
        }
620✔
190

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

196
        void save_from(const textview_curses& tc)
×
197
        {
198
            this->fvs_top = tc.get_top();
×
199
            this->fvs_selection = tc.get_selection();
×
200
        }
201

202
        void load_into(textview_curses& tc) const
×
203
        {
204
            if (this->fvs_selection.has_value()) {
×
205
                tc.set_selection(this->fvs_selection.value());
×
206
            }
UNCOV
207
            tc.set_top(this->fvs_top);
×
208
        }
209

210
        size_t text_line_count(view_mode mode) const;
211

212
        size_t text_line_width(view_mode mode, textview_curses& tc) const;
213

214
        std::optional<vis_line_t>
215
        row_for_anchor(view_mode mode, const std::string& id);
216

217
        std::shared_ptr<logfile> fvs_file;
218
        vis_line_t fvs_top{0};
219
        std::optional<vis_line_t> fvs_selection;
220

221
        time_t fvs_mtime;
222
        file_ssize_t fvs_file_size;
223
        file_off_t fvs_file_indexed_size;
224
        std::string fvs_error;
225
        std::unique_ptr<plain_text_source> fvs_text_source;
226
        lnav::document::metadata fvs_metadata;
227
        bool fvs_consumed_init_location{false};
228
    };
229

230
    using file_iterator = std::deque<file_view_state>::iterator;
231
    using const_file_iterator = std::deque<file_view_state>::const_iterator;
232

233
    void move_to_init_location(file_iterator& iter);
234

235
    file_iterator current_file_state() { return this->tss_files.begin(); }
29,005✔
236

237
    const_file_iterator current_file_state() const
654✔
238
    {
239
        return this->tss_files.cbegin();
654✔
240
    }
241

242
    std::deque<file_view_state> tss_files;
243
    size_t tss_line_indent_size{0};
244
    bool tss_last_scan_aborted{false};
245
    attr_line_t tss_hex_line;
246
    string_attrs_t tss_plain_line_attrs;
247
    int64_t tss_content_line{0};
248
    view_mode tss_view_mode{view_mode::rendered};
249
};
250

251
class textfile_header_overlay : public text_overlay_menu {
252
public:
253
    explicit textfile_header_overlay(textfile_sub_source* src,
254
                                     text_sub_source* log_src);
255

256
    bool list_static_overlay(const listview_curses& lv,
257
                             media_t media,
258
                             int y,
259
                             int bottom,
260
                             attr_line_t& value_out) override;
261

262
private:
263
    textfile_sub_source* tho_src;
264
    text_sub_source* tho_log_src;
265
    std::vector<attr_line_t> tho_static_lines;
266
    hasher::array_t tho_filter_state;
267
};
268

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