summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-09-25 23:51:12 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-09-25 23:51:12 +0000
commit6ff06ca98523f7aff016cbc8d00b9faa756739db (patch)
tree08ea37f839a2b89e7e03d7f651b9e7fee5f963a7 /src
parent639897517a2fabc78d274fb17fe57c21e951bf83 (diff)
DisplayBuffer: cleanup
Diffstat (limited to 'src')
-rw-r--r--src/display_buffer.hh26
-rw-r--r--src/main.cc17
-rw-r--r--src/window.cc2
3 files changed, 36 insertions, 9 deletions
diff --git a/src/display_buffer.hh b/src/display_buffer.hh
index 37c5cbfc..fd609134 100644
--- a/src/display_buffer.hh
+++ b/src/display_buffer.hh
@@ -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
diff --git a/src/main.cc b/src/main.cc
index dd955acc..e971b066 100644
--- a/src/main.cc
+++ b/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;
diff --git a/src/window.cc b/src/window.cc
index 54d618f8..e73ef4f1 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -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();