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

tstack / lnav / 20245728190-2749

15 Dec 2025 07:59PM UTC coverage: 68.864% (-0.07%) from 68.929%
20245728190-2749

push

github

tstack
[text_format] add plaintext type

Related to #1296

85 of 132 new or added lines in 24 files covered. (64.39%)

73 existing lines in 10 files now uncovered.

51605 of 74938 relevant lines covered (68.86%)

434003.35 hits per line

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

85.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 <optional>
34
#include <string>
35
#include <unordered_set>
36
#include <vector>
37

38
#include "base/attr_line.hh"
39
#include "base/file_range.hh"
40
#include "base/intern_string.hh"
41
#include "document.sections.hh"
42
#include "textview_curses.hh"
43
#include "vis_line.hh"
44

45
class plain_text_source
46
    : public text_sub_source
47
    , public vis_location_history
48
    , public text_anchors {
49
public:
50
    struct text_line {
51
        text_line(file_off_t off, attr_line_t value)
29,625✔
52
            : tl_offset(off), tl_value(std::move(value))
29,625✔
53
        {
54
        }
29,625✔
55

56
        bool contains_offset(file_off_t off) const
6✔
57
        {
58
            return (this->tl_offset <= off
6✔
59
                    && off < this->tl_offset + this->tl_value.length());
6✔
60
        }
61

62
        file_off_t tl_offset;
63
        attr_line_t tl_value;
64
    };
65

66
    plain_text_source() = default;
6,928✔
67

68
    plain_text_source(const string_fragment& text);
69

70
    plain_text_source(const std::vector<std::string>& text_lines);
71

72
    plain_text_source(const std::vector<attr_line_t>& text_lines);
73

74
    plain_text_source& set_reverse_selection(bool val)
2✔
75
    {
76
        this->tds_reverse_selection = val;
2✔
77
        return *this;
2✔
78
    }
79

80
    plain_text_source& replace_with_mutable(attr_line_t& text_lines,
81
                                            std::optional<text_format_t> tf);
82

83
    plain_text_source& replace_with(const attr_line_t& text_lines);
84

85
    plain_text_source& replace_with(const std::vector<std::string>& text_lines);
86

87
    plain_text_source& replace_with(const std::vector<attr_line_t>& text_lines);
88

NEW
89
    plain_text_source& replace_with(const char* str)
×
90
    {
91
        return this->replace_with(attr_line_t::from_ansi_str(str));
×
92
    }
93

94
    void clear();
95

96
    plain_text_source& truncate_to(size_t max_lines);
97

98
    size_t text_line_count() override { return this->tds_lines.size(); }
21,405✔
99

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

102
    size_t text_line_width(textview_curses& curses) override;
103

104
    line_info text_value_for_line(textview_curses& tc,
105
                                  int row,
106
                                  std::string& value_out,
107
                                  line_flags_t flags) override;
108

109
    void text_attrs_for_line(textview_curses& tc,
110
                             int line,
111
                             string_attrs_t& value_out) override;
112

113
    size_t text_size_for_line(textview_curses& tc,
114
                              int row,
115
                              line_flags_t flags) override;
116

117
    std::optional<text_format_t> get_text_format() const override;
118

119
    const std::vector<text_line>& get_lines() const { return this->tds_lines; }
×
120

121
    plain_text_source& set_text_format(std::optional<text_format_t> format)
19✔
122
    {
123
        this->tds_text_format = format;
19✔
124
        return *this;
19✔
125
    }
126

127
    std::optional<location_history*> get_location_history() override
4✔
128
    {
129
        return this;
4✔
130
    }
131

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

135
    std::optional<vis_line_t> row_for_anchor(const std::string& id) override;
136
    std::optional<std::string> anchor_for_row(vis_line_t vl) override;
137
    std::unordered_set<std::string> get_anchors() override;
138
    std::optional<vis_line_t> adjacent_anchor(vis_line_t vl,
139
                                              direction dir) override;
140

141
protected:
142
    size_t compute_longest_line();
143

144
    std::optional<vis_line_t> line_for_offset(file_off_t off) const;
145

146
    std::vector<text_line> tds_lines;
147
    std::optional<text_format_t> tds_text_format;
148
    size_t tds_longest_line{0};
149
    bool tds_reverse_selection{false};
150
    size_t tds_line_indent_size{0};
151
    lnav::document::metadata tds_doc_sections;
152
};
153

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