DisplayBuffer: cleanup

This commit is contained in:
Maxime Coste 2011-09-25 23:51:12 +00:00
parent 639897517a
commit 6ff06ca985
3 changed files with 36 additions and 9 deletions

View File

@ -7,12 +7,28 @@
namespace Kakoune namespace Kakoune
{ {
typedef int Color;
typedef int Attribute; typedef int Attribute;
enum Attributes 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 struct DisplayAtom
@ -22,7 +38,11 @@ struct DisplayAtom
Color bg_color; Color bg_color;
Attribute attribute; 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 class DisplayBuffer

View File

@ -14,6 +14,14 @@
using namespace Kakoune; using namespace Kakoune;
using namespace std::placeholders; using namespace std::placeholders;
void set_attribute(int attribute, bool on)
{
if (on)
attron(attribute);
else
attroff(attribute);
}
void draw_window(Window& window) void draw_window(Window& window)
{ {
int max_x,max_y; int max_x,max_y;
@ -23,16 +31,15 @@ void draw_window(Window& window)
window.set_dimensions(WindowCoord(max_y, max_x)); window.set_dimensions(WindowCoord(max_y, max_x));
window.update_display_buffer(); window.update_display_buffer();
WindowCoord position; WindowCoord position;
for (const DisplayAtom& atom : window.display_buffer()) for (const DisplayAtom& atom : window.display_buffer())
{ {
const std::string& content = atom.content; const std::string& content = atom.content;
if (atom.attribute & UNDERLINE) set_attribute(A_UNDERLINE, atom.attribute & Underline);
attron(A_UNDERLINE); set_attribute(A_REVERSE, atom.attribute & Reverse);
else set_attribute(A_BLINK, atom.attribute & Blink);
attroff(A_UNDERLINE); set_attribute(A_BOLD, atom.attribute & Bold);
size_t pos = 0; size_t pos = 0;
size_t end; size_t end;

View File

@ -214,7 +214,7 @@ void Window::update_display_buffer()
{ {
DisplayAtom atom; DisplayAtom atom;
atom.content = m_buffer.string(sel.begin(), sel.end()); atom.content = m_buffer.string(sel.begin(), sel.end());
atom.attribute = UNDERLINE; atom.attribute = Underline;
m_display_buffer.append(atom); m_display_buffer.append(atom);
} }
current_position = sel.end(); current_position = sel.end();