2011-09-02 18:51:20 +02:00
|
|
|
#ifndef display_buffer_hh_INCLUDED
|
|
|
|
#define display_buffer_hh_INCLUDED
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
#include "string.hh"
|
2011-10-14 16:29:53 +02:00
|
|
|
#include "line_and_column.hh"
|
2011-09-28 22:54:11 +02:00
|
|
|
#include "buffer.hh"
|
|
|
|
|
2011-09-02 18:51:20 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2011-10-14 16:29:53 +02:00
|
|
|
struct DisplayCoord : LineAndColumn<DisplayCoord>
|
|
|
|
{
|
|
|
|
DisplayCoord(int line = 0, int column = 0)
|
|
|
|
: LineAndColumn(line, column) {}
|
2011-10-15 06:45:49 +02:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
explicit DisplayCoord(const LineAndColumn<T>& other)
|
|
|
|
: LineAndColumn(other.line, other.column) {}
|
2011-10-14 16:29:53 +02:00
|
|
|
};
|
|
|
|
|
2011-09-02 18:51:20 +02:00
|
|
|
typedef int Attribute;
|
|
|
|
|
|
|
|
enum Attributes
|
|
|
|
{
|
2011-09-26 01:51:12 +02:00
|
|
|
Normal = 0,
|
|
|
|
Underline = 1,
|
|
|
|
Reverse = 2,
|
|
|
|
Blink = 4,
|
|
|
|
Bold = 8,
|
2012-02-22 22:48:14 +01:00
|
|
|
Final = 16
|
2011-09-26 01:51:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class Color
|
|
|
|
{
|
|
|
|
Default,
|
|
|
|
Black,
|
|
|
|
Red,
|
|
|
|
Green,
|
|
|
|
Yellow,
|
|
|
|
Blue,
|
|
|
|
Magenta,
|
|
|
|
Cyan,
|
|
|
|
White
|
2011-09-02 18:51:20 +02:00
|
|
|
};
|
|
|
|
|
2012-01-11 15:21:58 +01:00
|
|
|
// A DisplayAtom is a string of text with it's display style.
|
|
|
|
//
|
|
|
|
// The DisplayAtom class references the buffer string it represents
|
|
|
|
// with it's begin/end iterators and may replace it with another
|
|
|
|
// text stored in the replacement_string field.
|
2011-09-02 18:51:20 +02:00
|
|
|
struct DisplayAtom
|
|
|
|
{
|
2011-10-15 06:45:49 +02:00
|
|
|
const DisplayCoord& coord() const { return m_coord; }
|
|
|
|
const BufferIterator& begin() const { return m_begin; }
|
|
|
|
const BufferIterator& end() const { return m_end; }
|
|
|
|
const Color& fg_color() const { return m_fg_color; }
|
|
|
|
const Color& bg_color() const { return m_bg_color; }
|
|
|
|
const Attribute& attribute() const { return m_attribute; }
|
|
|
|
|
2012-07-03 23:23:07 +02:00
|
|
|
enum ContentMode
|
|
|
|
{
|
|
|
|
BufferText,
|
|
|
|
ReplacementText
|
|
|
|
};
|
|
|
|
ContentMode content_mode() const { return m_content_mode; }
|
2011-10-15 06:45:49 +02:00
|
|
|
|
|
|
|
Color& fg_color() { return m_fg_color; }
|
|
|
|
Color& bg_color() { return m_bg_color; }
|
|
|
|
Attribute& attribute() { return m_attribute; }
|
|
|
|
|
2012-03-08 22:23:29 +01:00
|
|
|
String content() const;
|
2011-10-15 06:45:49 +02:00
|
|
|
DisplayCoord end_coord() const;
|
|
|
|
BufferIterator iterator_at(const DisplayCoord& coord) const;
|
|
|
|
DisplayCoord line_and_column_at(const BufferIterator& iterator) const;
|
|
|
|
|
2012-07-03 23:23:07 +02:00
|
|
|
bool splitable() const { return m_content_mode != ReplacementText; }
|
2011-10-17 21:01:04 +02:00
|
|
|
|
2011-10-15 06:45:49 +02:00
|
|
|
private:
|
|
|
|
friend class DisplayBuffer;
|
2012-07-03 23:23:07 +02:00
|
|
|
DisplayAtom(DisplayCoord coord,
|
|
|
|
BufferIterator begin, BufferIterator end,
|
|
|
|
Color fg_color = Color::Default,
|
|
|
|
Color bg_color = Color::Default,
|
|
|
|
Attribute attribute = Attributes::Normal)
|
|
|
|
: m_content_mode(BufferText),
|
|
|
|
m_coord(std::move(coord)),
|
|
|
|
m_begin(std::move(begin)), m_end(std::move(end)),
|
|
|
|
m_fg_color(fg_color),
|
|
|
|
m_bg_color(bg_color),
|
|
|
|
m_attribute(attribute)
|
|
|
|
{}
|
2011-10-15 06:45:49 +02:00
|
|
|
|
2012-07-03 19:13:16 +02:00
|
|
|
ContentMode m_content_mode;
|
|
|
|
|
2011-10-15 06:45:49 +02:00
|
|
|
DisplayCoord m_coord;
|
|
|
|
BufferIterator m_begin;
|
|
|
|
BufferIterator m_end;
|
|
|
|
Color m_fg_color;
|
|
|
|
Color m_bg_color;
|
|
|
|
Attribute m_attribute;
|
2012-03-08 22:23:29 +01:00
|
|
|
String m_replacement_text;
|
2011-09-02 18:51:20 +02:00
|
|
|
};
|
|
|
|
|
2012-01-11 15:21:58 +01:00
|
|
|
// A DisplayBuffer is the visual content of a Window as a DisplayAtom list
|
|
|
|
//
|
|
|
|
// The DisplayBuffer class provides means to mutate and iterator on it's
|
|
|
|
// DisplayAtoms.
|
2011-09-02 18:51:20 +02:00
|
|
|
class DisplayBuffer
|
|
|
|
{
|
|
|
|
public:
|
2011-10-18 15:59:32 +02:00
|
|
|
typedef std::list<DisplayAtom> AtomList;
|
2011-09-02 18:51:20 +02:00
|
|
|
typedef AtomList::iterator iterator;
|
|
|
|
typedef AtomList::const_iterator const_iterator;
|
|
|
|
|
|
|
|
DisplayBuffer();
|
|
|
|
|
|
|
|
void clear() { m_atoms.clear(); }
|
2012-07-03 23:23:07 +02:00
|
|
|
iterator append(BufferIterator begin, BufferIterator end);
|
|
|
|
iterator insert_empty_atom_before(iterator where);
|
2011-10-07 16:19:58 +02:00
|
|
|
iterator split(iterator atom, const BufferIterator& pos);
|
2011-09-02 18:51:20 +02:00
|
|
|
|
2012-03-08 22:23:29 +01:00
|
|
|
void replace_atom_content(iterator atom, const String& replacement);
|
2011-10-15 06:45:49 +02:00
|
|
|
|
2011-09-02 18:51:20 +02:00
|
|
|
iterator begin() { return m_atoms.begin(); }
|
|
|
|
iterator end() { return m_atoms.end(); }
|
|
|
|
|
|
|
|
const_iterator begin() const { return m_atoms.begin(); }
|
|
|
|
const_iterator end() const { return m_atoms.end(); }
|
2011-09-29 11:10:27 +02:00
|
|
|
|
2011-10-17 21:00:38 +02:00
|
|
|
iterator atom_containing(const BufferIterator& where);
|
2011-10-23 22:26:30 +02:00
|
|
|
iterator atom_containing(const BufferIterator& where, iterator start);
|
2011-10-17 21:00:38 +02:00
|
|
|
|
2011-10-15 06:45:49 +02:00
|
|
|
const DisplayAtom& front() const { return m_atoms.front(); }
|
|
|
|
const DisplayAtom& back() const { return m_atoms.back(); }
|
|
|
|
|
2011-09-29 11:10:27 +02:00
|
|
|
void check_invariant() const;
|
2011-09-02 18:51:20 +02:00
|
|
|
private:
|
|
|
|
AtomList m_atoms;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // display_buffer_hh_INCLUDED
|