summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-04-04 13:53:47 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-04-04 14:04:38 +0200
commitb58f614f40eefc737e2419cba3d9b887fa9c88eb (patch)
tree51014a955f0dc07d2424086c1fcfef4b57e64310 /src
parent1fd99e7e88c48d503a07b8a53580622467ae407f (diff)
Pass a fg and bg color when displaying a menu
Diffstat (limited to 'src')
-rw-r--r--src/color_registry.cc2
-rw-r--r--src/commands.cc2
-rw-r--r--src/input_handler.cc30
-rw-r--r--src/ncurses.cc12
-rw-r--r--src/ncurses.hh5
-rw-r--r--src/remote.cc39
-rw-r--r--src/user_interface.hh4
7 files changed, 68 insertions, 26 deletions
diff --git a/src/color_registry.cc b/src/color_registry.cc
index bee5f9eb..7d532b18 100644
--- a/src/color_registry.cc
+++ b/src/color_registry.cc
@@ -46,6 +46,8 @@ ColorRegistry::ColorRegistry()
{ "PrimaryCursor", { Color::Black, Color::White } },
{ "SecondaryCursor", { Color::Black, Color::White } },
{ "LineNumbers", { Color::Black, Color::White } },
+ { "MenuForeground", { Color::Blue, Color::Cyan } },
+ { "MenuBackground", { Color::Cyan, Color::Blue } },
}
{}
diff --git a/src/commands.cc b/src/commands.cc
index b4e4f46c..d7133baf 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -806,7 +806,7 @@ public:
void print_status(const String& , CharCount) override {}
void draw(const DisplayBuffer&, const String&) override {}
void menu_show(const memoryview<String>&,
- const DisplayCoord&, MenuStyle) override {}
+ DisplayCoord, ColorPair, ColorPair, MenuStyle) override {}
void menu_select(int) override {}
void menu_hide() override {}
diff --git a/src/input_handler.cc b/src/input_handler.cc
index a6b77fdf..ef2afd2a 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -5,6 +5,7 @@
#include "register_manager.hh"
#include "event_manager.hh"
#include "utf8.hh"
+#include "color_registry.hh"
#include <unordered_map>
@@ -153,7 +154,9 @@ public:
m_selected(m_choices.begin())
{
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
- context().ui().menu_show(choices, menu_pos, MenuStyle::Prompt);
+ ColorRegistry& colreg = ColorRegistry::instance();
+ context().ui().menu_show(choices, menu_pos, colreg["MenuForeground"],
+ colreg["MenuBackground"], MenuStyle::Prompt);
}
void on_key(const Key& key) override
@@ -375,7 +378,9 @@ public:
context().ui().menu_hide();
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
- context().ui().menu_show(candidates, menu_pos, MenuStyle::Prompt);
+ ColorRegistry& colreg = ColorRegistry::instance();
+ context().ui().menu_show(candidates, menu_pos, colreg["MenuForeground"],
+ colreg["MenuBackground"], MenuStyle::Prompt);
bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
String prefix = use_common_prefix ? common_prefix(candidates) : String();
@@ -573,10 +578,8 @@ public:
{
m_context.ui().menu_hide();
m_current_candidate = m_matching_candidates.size();
- DisplayCoord menu_pos = m_context.window().display_position(m_completions.begin);
- m_context.ui().menu_show(m_matching_candidates, menu_pos, MenuStyle::Inline);
- m_context.ui().menu_select(m_current_candidate);
m_completions.end = cursor;
+ menu_show();
m_matching_candidates.push_back(prefix);
return;
}
@@ -601,6 +604,18 @@ private:
}
}
+ void menu_show()
+ {
+ DisplayCoord menu_pos = m_context.window().display_position(m_completions.begin);
+
+ ColorRegistry& colreg = ColorRegistry::instance();
+ m_context.ui().menu_show(m_matching_candidates, menu_pos,
+ colreg["MenuForeground"],
+ colreg["MenuBackground"],
+ MenuStyle::Inline);
+ m_context.ui().menu_select(m_current_candidate);
+ }
+
bool setup_ifn()
{
if (not m_completions.is_valid())
@@ -615,10 +630,9 @@ private:
assert(cursor >= m_completions.begin);
m_matching_candidates = m_completions.candidates;
- DisplayCoord menu_pos = m_context.window().display_position(m_completions.begin);
- m_context.ui().menu_show(m_matching_candidates, menu_pos, MenuStyle::Inline);
+ m_current_candidate = m_matching_candidates.size();
+ menu_show();
m_matching_candidates.push_back(m_context.buffer().string(m_completions.begin, m_completions.end));
- m_current_candidate = m_matching_candidates.size() - 1;
}
return true;
}
diff --git a/src/ncurses.cc b/src/ncurses.cc
index 330d9508..d14fcccb 100644
--- a/src/ncurses.cc
+++ b/src/ncurses.cc
@@ -322,11 +322,11 @@ void NCursesUI::draw_menu()
{
assert(m_menu_win);
- auto menu_fg = get_color_pair({ Color::Blue, Color::Cyan });
- auto menu_bg = get_color_pair({ Color::Cyan, Color::Blue });
+ auto menu_fg = get_color_pair(m_menu_fg);
+ auto menu_bg = get_color_pair(m_menu_bg);
auto scroll_fg = get_color_pair({ Color::White, Color::White });
- auto scroll_bg = get_color_pair({ Color::White, Color::Blue });
+ auto scroll_bg = get_color_pair(m_menu_bg);
wattron(m_menu_win, COLOR_PAIR(menu_bg));
wbkgdset(m_menu_win, COLOR_PAIR(menu_bg));
@@ -362,11 +362,15 @@ void NCursesUI::draw_menu()
}
void NCursesUI::menu_show(const memoryview<String>& choices,
- const DisplayCoord& anchor, MenuStyle style)
+ DisplayCoord anchor, ColorPair fg, ColorPair bg,
+ MenuStyle style)
{
assert(m_menu_win == nullptr);
assert(m_choices.empty());
+ m_menu_fg = fg;
+ m_menu_bg = bg;
+
DisplayCoord maxsize = window_size(stdscr);
maxsize.column -= anchor.column;
diff --git a/src/ncurses.hh b/src/ncurses.hh
index d07f095d..6c37ad93 100644
--- a/src/ncurses.hh
+++ b/src/ncurses.hh
@@ -27,7 +27,8 @@ public:
Key get_key() override;
void menu_show(const memoryview<String>& choices,
- const DisplayCoord& anchor, MenuStyle style) override;
+ DisplayCoord anchor, ColorPair fg, ColorPair bg,
+ MenuStyle style) override;
void menu_select(int selected) override;
void menu_hide() override;
@@ -51,6 +52,8 @@ private:
WINDOW* m_menu_win = nullptr;
std::vector<String> m_choices;
+ ColorPair m_menu_fg;
+ ColorPair m_menu_bg;
int m_selected_choice = 0;
int m_menu_columns = 1;
LineCount m_menu_top_line = 0;
diff --git a/src/remote.cc b/src/remote.cc
index 2e19cc45..18cb48e3 100644
--- a/src/remote.cc
+++ b/src/remote.cc
@@ -75,12 +75,17 @@ public:
write(memoryview<T>(vec));
}
+ void write(const ColorPair& colors)
+ {
+ write(colors.first);
+ write(colors.second);
+ }
+
void write(const DisplayAtom& atom)
{
- write(atom.colors.first);
- write(atom.colors.second);
- write(atom.attribute);
write(atom.content.content());
+ write(atom.colors);
+ write(atom.attribute);
}
void write(const DisplayLine& line)
@@ -145,14 +150,20 @@ std::vector<T> read_vector(int socket)
}
template<>
+ColorPair read<ColorPair>(int socket)
+{
+ ColorPair res;
+ res.first = read<Color>(socket);
+ res.second = read<Color>(socket);
+ return res;
+}
+
+template<>
DisplayAtom read<DisplayAtom>(int socket)
{
- Color fg_color = read<Color>(socket);
- Color bg_color = read<Color>(socket);
- Attribute attribute = read<Attribute>(socket);
DisplayAtom atom(AtomContent(read<String>(socket)));
- atom.colors = { fg_color, bg_color };
- atom.attribute = attribute;
+ atom.colors = read<ColorPair>(socket);
+ atom.attribute = read<Attribute>(socket);
return atom;
}
template<>
@@ -178,7 +189,8 @@ public:
void print_status(const String& status, CharCount cursor_pos) override;
void menu_show(const memoryview<String>& choices,
- const DisplayCoord& anchor, MenuStyle style) override;
+ DisplayCoord anchor, ColorPair fg, ColorPair bg,
+ MenuStyle style) override;
void menu_select(int selected) override;
void menu_hide() override;
@@ -223,12 +235,15 @@ void RemoteUI::print_status(const String& status, CharCount cursor_pos)
}
void RemoteUI::menu_show(const memoryview<String>& choices,
- const DisplayCoord& anchor, MenuStyle style)
+ DisplayCoord anchor, ColorPair fg, ColorPair bg,
+ MenuStyle style)
{
Message msg(m_socket_watcher.fd());
msg.write(RemoteUIMsg::MenuShow);
msg.write(choices);
msg.write(anchor);
+ msg.write(fg);
+ msg.write(bg);
msg.write(style);
}
@@ -338,8 +353,10 @@ void RemoteClient::process_next_message()
{
auto choices = read_vector<String>(socket);
auto anchor = read<DisplayCoord>(socket);
+ auto fg = read<ColorPair>(socket);
+ auto bg = read<ColorPair>(socket);
auto style = read<MenuStyle>(socket);
- m_ui->menu_show(choices, anchor, style);
+ m_ui->menu_show(choices, anchor, fg, bg, style);
break;
}
case RemoteUIMsg::MenuSelect:
diff --git a/src/user_interface.hh b/src/user_interface.hh
index 9353fe7e..dd6b0448 100644
--- a/src/user_interface.hh
+++ b/src/user_interface.hh
@@ -5,6 +5,7 @@
#include "keys.hh"
#include "units.hh"
#include "utils.hh"
+#include "color.hh"
namespace Kakoune
{
@@ -28,7 +29,8 @@ public:
virtual void print_status(const String& status, CharCount cursor_pos = -1) = 0;
virtual void menu_show(const memoryview<String>& choices,
- const DisplayCoord& anchor, MenuStyle style) = 0;
+ DisplayCoord anchor, ColorPair fg, ColorPair bg,
+ MenuStyle style) = 0;
virtual void menu_select(int selected) = 0;
virtual void menu_hide() = 0;