• 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

70.0
/src/plain_text_source.hh
1
/**
2
 * Copyright (c) 2015, 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 LNAV_PLAIN_TEXT_SOURCE_HH
31
#define LNAV_PLAIN_TEXT_SOURCE_HH
32

33
#include <string>
34
#include <vector>
35

36
#include "base/attr_line.hh"
37
#include "base/file_range.hh"
38
#include "document.sections.hh"
39
#include "textview_curses.hh"
40

41
class plain_text_source
42
    : public text_sub_source
43
    , public vis_location_history
44
    , public text_anchors {
45
public:
46
    struct text_line {
47
        text_line(file_off_t off, attr_line_t value)
23,193✔
48
            : tl_offset(off), tl_value(std::move(value))
23,193✔
49
        {
50
        }
23,193✔
51

52
        bool contains_offset(file_off_t off) const
6✔
53
        {
54
            return (this->tl_offset <= off
6✔
55
                    && off < this->tl_offset + this->tl_value.length());
6✔
56
        }
57

58
        file_off_t tl_offset;
59
        attr_line_t tl_value;
60
    };
61

62
    plain_text_source() = default;
6,326✔
63

64
    plain_text_source(const string_fragment& text);
65

66
    plain_text_source(const std::vector<std::string>& text_lines);
67

68
    plain_text_source(const std::vector<attr_line_t>& text_lines);
69

UNCOV
70
    plain_text_source& set_reverse_selection(bool val)
×
71
    {
UNCOV
72
        this->tds_reverse_selection = val;
×
UNCOV
73
        return *this;
×
74
    }
75

76
    plain_text_source& replace_with_mutable(attr_line_t& text_lines,
77
                                            text_format_t tf);
78

79
    plain_text_source& replace_with(const attr_line_t& text_lines);
80

81
    plain_text_source& replace_with(const std::vector<std::string>& text_lines);
82

83
    plain_text_source& replace_with(const std::vector<attr_line_t>& text_lines);
84

UNCOV
85
    plain_text_source& replace_with(const char *str)
×
86
    {
UNCOV
87
        return this->replace_with(attr_line_t::from_ansi_str(str));
×
88
    }
89

90
    void clear();
91

92
    plain_text_source& truncate_to(size_t max_lines);
93

94
    size_t text_line_count() override { return this->tds_lines.size(); }
15,443✔
95

96
    bool empty() const override { return this->tds_lines.empty(); }
3✔
97

98
    size_t text_line_width(textview_curses& curses) override;
99

100
    line_info text_value_for_line(textview_curses& tc,
101
                                  int row,
102
                                  std::string& value_out,
103
                                  line_flags_t flags) override;
104

105
    void text_attrs_for_line(textview_curses& tc,
106
                             int line,
107
                             string_attrs_t& value_out) override;
108

109
    size_t text_size_for_line(textview_curses& tc,
110
                              int row,
111
                              line_flags_t flags) override;
112

113
    text_format_t get_text_format() const override;
114

UNCOV
115
    const std::vector<text_line>& get_lines() const { return this->tds_lines; }
×
116

117
    plain_text_source& set_text_format(text_format_t format)
15✔
118
    {
119
        this->tds_text_format = format;
15✔
120
        return *this;
15✔
121
    }
122

123
    std::optional<location_history*> get_location_history() override
1✔
124
    {
125
        return this;
1✔
126
    }
127

128
    void text_crumbs_for_line(int line,
129
                              std::vector<breadcrumb::crumb>& crumbs) override;
130

131
    std::optional<vis_line_t> row_for_anchor(const std::string& id) override;
132
    std::optional<std::string> anchor_for_row(vis_line_t vl) override;
133
    std::unordered_set<std::string> get_anchors() override;
134
    std::optional<vis_line_t> adjacent_anchor(vis_line_t vl,
135
                                              direction dir) override;
136

137
protected:
138
    size_t compute_longest_line();
139

140
    std::optional<vis_line_t> line_for_offset(file_off_t off) const;
141

142
    std::vector<text_line> tds_lines;
143
    text_format_t tds_text_format{text_format_t::TF_UNKNOWN};
144
    size_t tds_longest_line{0};
145
    bool tds_reverse_selection{false};
146
    size_t tds_line_indent_size{0};
147
    lnav::document::metadata tds_doc_sections;
148
};
149

150
#endif  // LNAV_PLAIN_TEXT_SOURCE_HH
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