DisplayBuffer: cleanup
This commit is contained in:
parent
639897517a
commit
6ff06ca985
|
@ -7,12 +7,28 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
typedef int Color;
|
||||
typedef int Attribute;
|
||||
|
||||
enum Attributes
|
||||
{
|
||||
UNDERLINE = 1
|
||||
Normal = 0,
|
||||
Underline = 1,
|
||||
Reverse = 2,
|
||||
Blink = 4,
|
||||
Bold = 8,
|
||||
};
|
||||
|
||||
enum class Color
|
||||
{
|
||||
Default,
|
||||
Black,
|
||||
Red,
|
||||
Green,
|
||||
Yellow,
|
||||
Blue,
|
||||
Magenta,
|
||||
Cyan,
|
||||
White
|
||||
};
|
||||
|
||||
struct DisplayAtom
|
||||
|
@ -22,7 +38,11 @@ struct DisplayAtom
|
|||
Color bg_color;
|
||||
Attribute attribute;
|
||||
|
||||
DisplayAtom() : fg_color(0), bg_color(0), attribute(0) {}
|
||||
DisplayAtom()
|
||||
: fg_color(Color::Default),
|
||||
bg_color(Color::Default),
|
||||
attribute(Attributes::Normal)
|
||||
{}
|
||||
};
|
||||
|
||||
class DisplayBuffer
|
||||
|
|
17
src/main.cc
17
src/main.cc
|
@ -14,6 +14,14 @@
|
|||
using namespace Kakoune;
|
||||
using namespace std::placeholders;
|
||||
|
||||
void set_attribute(int attribute, bool on)
|
||||
{
|
||||
if (on)
|
||||
attron(attribute);
|
||||
else
|
||||
attroff(attribute);
|
||||
}
|
||||
|
||||
void draw_window(Window& window)
|
||||
{
|
||||
int max_x,max_y;
|
||||
|
@ -23,16 +31,15 @@ void draw_window(Window& window)
|
|||
window.set_dimensions(WindowCoord(max_y, max_x));
|
||||
window.update_display_buffer();
|
||||
|
||||
|
||||
WindowCoord position;
|
||||
for (const DisplayAtom& atom : window.display_buffer())
|
||||
{
|
||||
const std::string& content = atom.content;
|
||||
|
||||
if (atom.attribute & UNDERLINE)
|
||||
attron(A_UNDERLINE);
|
||||
else
|
||||
attroff(A_UNDERLINE);
|
||||
set_attribute(A_UNDERLINE, atom.attribute & Underline);
|
||||
set_attribute(A_REVERSE, atom.attribute & Reverse);
|
||||
set_attribute(A_BLINK, atom.attribute & Blink);
|
||||
set_attribute(A_BOLD, atom.attribute & Bold);
|
||||
|
||||
size_t pos = 0;
|
||||
size_t end;
|
||||
|
|
|
@ -214,7 +214,7 @@ void Window::update_display_buffer()
|
|||
{
|
||||
DisplayAtom atom;
|
||||
atom.content = m_buffer.string(sel.begin(), sel.end());
|
||||
atom.attribute = UNDERLINE;
|
||||
atom.attribute = Underline;
|
||||
m_display_buffer.append(atom);
|
||||
}
|
||||
current_position = sel.end();
|
||||
|
|
Loading…
Reference in New Issue
Block a user