2015-07-08 13:35:36 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015, Timothy Stack
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of Timothy Stack nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2022-03-16 22:38:08 +00:00
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2015-07-08 13:35:36 +00:00
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LNAV_PLAIN_TEXT_SOURCE_HH
|
|
|
|
#define LNAV_PLAIN_TEXT_SOURCE_HH
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-04-12 23:07:13 +00:00
|
|
|
#include "base/attr_line.hh"
|
2022-05-11 04:58:32 +00:00
|
|
|
#include "base/file_range.hh"
|
2022-05-23 03:44:18 +00:00
|
|
|
#include "document.sections.hh"
|
2018-10-11 12:50:28 +00:00
|
|
|
#include "textview_curses.hh"
|
2017-03-26 13:02:53 +00:00
|
|
|
|
2015-07-08 13:35:36 +00:00
|
|
|
class plain_text_source
|
2022-03-16 22:38:08 +00:00
|
|
|
: public text_sub_source
|
2022-08-29 01:55:32 +00:00
|
|
|
, public vis_location_history
|
|
|
|
, public text_anchors {
|
2015-07-08 13:35:36 +00:00
|
|
|
public:
|
2022-05-11 04:58:32 +00:00
|
|
|
struct text_line {
|
|
|
|
text_line(file_off_t off, attr_line_t value)
|
|
|
|
: tl_offset(off), tl_value(std::move(value))
|
|
|
|
{
|
2015-07-08 13:35:36 +00:00
|
|
|
}
|
2022-05-11 04:58:32 +00:00
|
|
|
|
|
|
|
bool contains_offset(file_off_t off) const
|
|
|
|
{
|
|
|
|
return (this->tl_offset <= off
|
|
|
|
&& off < this->tl_offset + this->tl_value.length());
|
2015-07-08 13:35:36 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
file_off_t tl_offset;
|
|
|
|
attr_line_t tl_value;
|
|
|
|
};
|
2017-03-26 13:02:53 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
plain_text_source() = default;
|
2015-07-08 13:35:36 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
plain_text_source(const std::string& text);
|
2017-03-26 13:02:53 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
plain_text_source(const std::vector<std::string>& text_lines);
|
2017-03-31 14:01:11 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
plain_text_source(const std::vector<attr_line_t>& text_lines);
|
2017-04-02 14:17:31 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
plain_text_source& set_reverse_selection(bool val)
|
2022-03-16 22:38:08 +00:00
|
|
|
{
|
2022-05-11 04:58:32 +00:00
|
|
|
this->tds_reverse_selection = val;
|
2017-04-02 14:17:31 +00:00
|
|
|
return *this;
|
2022-04-12 23:07:13 +00:00
|
|
|
}
|
2017-03-31 14:01:11 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
plain_text_source& replace_with(const attr_line_t& text_lines);
|
|
|
|
|
|
|
|
plain_text_source& replace_with(const std::vector<std::string>& text_lines);
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
plain_text_source& truncate_to(size_t max_lines);
|
|
|
|
|
|
|
|
size_t text_line_count() override { return this->tds_lines.size(); }
|
2015-07-08 13:35:36 +00:00
|
|
|
|
2022-08-29 01:55:32 +00:00
|
|
|
bool empty() const { return this->tds_lines.empty(); }
|
2017-04-15 05:49:36 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
size_t text_line_width(textview_curses& curses) override;
|
2015-08-15 03:45:23 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
void text_value_for_line(textview_curses& tc,
|
2015-07-08 13:35:36 +00:00
|
|
|
int row,
|
2022-03-16 22:38:08 +00:00
|
|
|
std::string& value_out,
|
2022-05-11 04:58:32 +00:00
|
|
|
line_flags_t flags) override;
|
2017-03-26 13:02:53 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
void text_attrs_for_line(textview_curses& tc,
|
|
|
|
int line,
|
2022-05-11 04:58:32 +00:00
|
|
|
string_attrs_t& value_out) override;
|
2015-07-08 13:35:36 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
size_t text_size_for_line(textview_curses& tc,
|
|
|
|
int row,
|
|
|
|
line_flags_t flags) override;
|
2015-07-08 13:35:36 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
text_format_t get_text_format() const override;
|
2022-04-12 23:07:13 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
const std::vector<text_line>& get_lines() const { return this->tds_lines; }
|
2017-03-31 14:01:11 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
plain_text_source& set_text_format(text_format_t format)
|
|
|
|
{
|
2017-03-31 14:01:11 +00:00
|
|
|
this->tds_text_format = format;
|
|
|
|
return *this;
|
2022-04-12 23:07:13 +00:00
|
|
|
}
|
2017-03-31 14:01:11 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
nonstd::optional<location_history*> get_location_history() override
|
2018-12-14 14:18:31 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2022-05-23 03:44:18 +00:00
|
|
|
void text_crumbs_for_line(int line,
|
|
|
|
std::vector<breadcrumb::crumb>& crumbs) override;
|
|
|
|
|
2022-08-29 01:55:32 +00:00
|
|
|
nonstd::optional<vis_line_t> row_for_anchor(const std::string& id) override;
|
|
|
|
nonstd::optional<std::string> anchor_for_row(vis_line_t vl) override;
|
|
|
|
std::unordered_set<std::string> get_anchors() override;
|
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
protected:
|
|
|
|
size_t compute_longest_line();
|
|
|
|
|
2022-05-23 03:44:18 +00:00
|
|
|
nonstd::optional<vis_line_t> line_for_offset(file_off_t off) const;
|
2015-09-15 07:24:56 +00:00
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
std::vector<text_line> tds_lines;
|
2020-11-10 06:17:17 +00:00
|
|
|
text_format_t tds_text_format{text_format_t::TF_UNKNOWN};
|
|
|
|
size_t tds_longest_line{0};
|
2022-05-11 04:58:32 +00:00
|
|
|
bool tds_reverse_selection{false};
|
2022-05-23 03:44:18 +00:00
|
|
|
lnav::document::metadata tds_doc_sections;
|
2015-07-08 13:35:36 +00:00
|
|
|
};
|
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
#endif // LNAV_PLAIN_TEXT_SOURCE_HH
|