Pass a fg and bg color when displaying a menu
This commit is contained in:
parent
1fd99e7e88
commit
b58f614f40
|
@ -405,7 +405,8 @@ there are some builtins color aliases:
|
||||||
* +PrimaryCursor+: last character of the primary selection
|
* +PrimaryCursor+: last character of the primary selection
|
||||||
* +SecondaryCursor+: last character of the secondary selection
|
* +SecondaryCursor+: last character of the secondary selection
|
||||||
* +LineNumbers+: colors used by the number_lines highlighter
|
* +LineNumbers+: colors used by the number_lines highlighter
|
||||||
|
* +MenuForeground+: colors for the selected element in menus
|
||||||
|
* +MenuBackground+: colors for the not selected elements in menus
|
||||||
|
|
||||||
Shell expansion
|
Shell expansion
|
||||||
---------------
|
---------------
|
||||||
|
|
|
@ -46,6 +46,8 @@ ColorRegistry::ColorRegistry()
|
||||||
{ "PrimaryCursor", { Color::Black, Color::White } },
|
{ "PrimaryCursor", { Color::Black, Color::White } },
|
||||||
{ "SecondaryCursor", { Color::Black, Color::White } },
|
{ "SecondaryCursor", { Color::Black, Color::White } },
|
||||||
{ "LineNumbers", { Color::Black, Color::White } },
|
{ "LineNumbers", { Color::Black, Color::White } },
|
||||||
|
{ "MenuForeground", { Color::Blue, Color::Cyan } },
|
||||||
|
{ "MenuBackground", { Color::Cyan, Color::Blue } },
|
||||||
}
|
}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
@ -806,7 +806,7 @@ public:
|
||||||
void print_status(const String& , CharCount) override {}
|
void print_status(const String& , CharCount) override {}
|
||||||
void draw(const DisplayBuffer&, const String&) override {}
|
void draw(const DisplayBuffer&, const String&) override {}
|
||||||
void menu_show(const memoryview<String>&,
|
void menu_show(const memoryview<String>&,
|
||||||
const DisplayCoord&, MenuStyle) override {}
|
DisplayCoord, ColorPair, ColorPair, MenuStyle) override {}
|
||||||
void menu_select(int) override {}
|
void menu_select(int) override {}
|
||||||
void menu_hide() override {}
|
void menu_hide() override {}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "register_manager.hh"
|
#include "register_manager.hh"
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
#include "utf8.hh"
|
#include "utf8.hh"
|
||||||
|
#include "color_registry.hh"
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
@ -153,7 +154,9 @@ public:
|
||||||
m_selected(m_choices.begin())
|
m_selected(m_choices.begin())
|
||||||
{
|
{
|
||||||
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
|
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
|
void on_key(const Key& key) override
|
||||||
|
@ -375,7 +378,9 @@ public:
|
||||||
|
|
||||||
context().ui().menu_hide();
|
context().ui().menu_hide();
|
||||||
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
|
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>();
|
bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
|
||||||
String prefix = use_common_prefix ? common_prefix(candidates) : String();
|
String prefix = use_common_prefix ? common_prefix(candidates) : String();
|
||||||
|
@ -573,10 +578,8 @@ public:
|
||||||
{
|
{
|
||||||
m_context.ui().menu_hide();
|
m_context.ui().menu_hide();
|
||||||
m_current_candidate = m_matching_candidates.size();
|
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;
|
m_completions.end = cursor;
|
||||||
|
menu_show();
|
||||||
m_matching_candidates.push_back(prefix);
|
m_matching_candidates.push_back(prefix);
|
||||||
return;
|
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()
|
bool setup_ifn()
|
||||||
{
|
{
|
||||||
if (not m_completions.is_valid())
|
if (not m_completions.is_valid())
|
||||||
|
@ -615,10 +630,9 @@ private:
|
||||||
assert(cursor >= m_completions.begin);
|
assert(cursor >= m_completions.begin);
|
||||||
|
|
||||||
m_matching_candidates = m_completions.candidates;
|
m_matching_candidates = m_completions.candidates;
|
||||||
DisplayCoord menu_pos = m_context.window().display_position(m_completions.begin);
|
m_current_candidate = m_matching_candidates.size();
|
||||||
m_context.ui().menu_show(m_matching_candidates, menu_pos, MenuStyle::Inline);
|
menu_show();
|
||||||
m_matching_candidates.push_back(m_context.buffer().string(m_completions.begin, m_completions.end));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -322,11 +322,11 @@ void NCursesUI::draw_menu()
|
||||||
{
|
{
|
||||||
assert(m_menu_win);
|
assert(m_menu_win);
|
||||||
|
|
||||||
auto menu_fg = get_color_pair({ Color::Blue, Color::Cyan });
|
auto menu_fg = get_color_pair(m_menu_fg);
|
||||||
auto menu_bg = get_color_pair({ Color::Cyan, Color::Blue });
|
auto menu_bg = get_color_pair(m_menu_bg);
|
||||||
|
|
||||||
auto scroll_fg = get_color_pair({ Color::White, Color::White });
|
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));
|
wattron(m_menu_win, COLOR_PAIR(menu_bg));
|
||||||
wbkgdset(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,
|
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_menu_win == nullptr);
|
||||||
assert(m_choices.empty());
|
assert(m_choices.empty());
|
||||||
|
|
||||||
|
m_menu_fg = fg;
|
||||||
|
m_menu_bg = bg;
|
||||||
|
|
||||||
DisplayCoord maxsize = window_size(stdscr);
|
DisplayCoord maxsize = window_size(stdscr);
|
||||||
maxsize.column -= anchor.column;
|
maxsize.column -= anchor.column;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@ public:
|
||||||
Key get_key() override;
|
Key get_key() override;
|
||||||
|
|
||||||
void menu_show(const memoryview<String>& choices,
|
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_select(int selected) override;
|
||||||
void menu_hide() override;
|
void menu_hide() override;
|
||||||
|
|
||||||
|
@ -51,6 +52,8 @@ private:
|
||||||
|
|
||||||
WINDOW* m_menu_win = nullptr;
|
WINDOW* m_menu_win = nullptr;
|
||||||
std::vector<String> m_choices;
|
std::vector<String> m_choices;
|
||||||
|
ColorPair m_menu_fg;
|
||||||
|
ColorPair m_menu_bg;
|
||||||
int m_selected_choice = 0;
|
int m_selected_choice = 0;
|
||||||
int m_menu_columns = 1;
|
int m_menu_columns = 1;
|
||||||
LineCount m_menu_top_line = 0;
|
LineCount m_menu_top_line = 0;
|
||||||
|
|
|
@ -75,12 +75,17 @@ public:
|
||||||
write(memoryview<T>(vec));
|
write(memoryview<T>(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write(const ColorPair& colors)
|
||||||
|
{
|
||||||
|
write(colors.first);
|
||||||
|
write(colors.second);
|
||||||
|
}
|
||||||
|
|
||||||
void write(const DisplayAtom& atom)
|
void write(const DisplayAtom& atom)
|
||||||
{
|
{
|
||||||
write(atom.colors.first);
|
|
||||||
write(atom.colors.second);
|
|
||||||
write(atom.attribute);
|
|
||||||
write(atom.content.content());
|
write(atom.content.content());
|
||||||
|
write(atom.colors);
|
||||||
|
write(atom.attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const DisplayLine& line)
|
void write(const DisplayLine& line)
|
||||||
|
@ -144,15 +149,21 @@ std::vector<T> read_vector(int socket)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
ColorPair read<ColorPair>(int socket)
|
||||||
|
{
|
||||||
|
ColorPair res;
|
||||||
|
res.first = read<Color>(socket);
|
||||||
|
res.second = read<Color>(socket);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
DisplayAtom read<DisplayAtom>(int socket)
|
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)));
|
DisplayAtom atom(AtomContent(read<String>(socket)));
|
||||||
atom.colors = { fg_color, bg_color };
|
atom.colors = read<ColorPair>(socket);
|
||||||
atom.attribute = attribute;
|
atom.attribute = read<Attribute>(socket);
|
||||||
return atom;
|
return atom;
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
|
@ -178,7 +189,8 @@ public:
|
||||||
void print_status(const String& status, CharCount cursor_pos) override;
|
void print_status(const String& status, CharCount cursor_pos) override;
|
||||||
|
|
||||||
void menu_show(const memoryview<String>& choices,
|
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_select(int selected) override;
|
||||||
void menu_hide() 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,
|
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());
|
Message msg(m_socket_watcher.fd());
|
||||||
msg.write(RemoteUIMsg::MenuShow);
|
msg.write(RemoteUIMsg::MenuShow);
|
||||||
msg.write(choices);
|
msg.write(choices);
|
||||||
msg.write(anchor);
|
msg.write(anchor);
|
||||||
|
msg.write(fg);
|
||||||
|
msg.write(bg);
|
||||||
msg.write(style);
|
msg.write(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,8 +353,10 @@ void RemoteClient::process_next_message()
|
||||||
{
|
{
|
||||||
auto choices = read_vector<String>(socket);
|
auto choices = read_vector<String>(socket);
|
||||||
auto anchor = read<DisplayCoord>(socket);
|
auto anchor = read<DisplayCoord>(socket);
|
||||||
|
auto fg = read<ColorPair>(socket);
|
||||||
|
auto bg = read<ColorPair>(socket);
|
||||||
auto style = read<MenuStyle>(socket);
|
auto style = read<MenuStyle>(socket);
|
||||||
m_ui->menu_show(choices, anchor, style);
|
m_ui->menu_show(choices, anchor, fg, bg, style);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RemoteUIMsg::MenuSelect:
|
case RemoteUIMsg::MenuSelect:
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "keys.hh"
|
#include "keys.hh"
|
||||||
#include "units.hh"
|
#include "units.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
|
#include "color.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -28,7 +29,8 @@ public:
|
||||||
virtual void print_status(const String& status, CharCount cursor_pos = -1) = 0;
|
virtual void print_status(const String& status, CharCount cursor_pos = -1) = 0;
|
||||||
|
|
||||||
virtual void menu_show(const memoryview<String>& choices,
|
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_select(int selected) = 0;
|
||||||
virtual void menu_hide() = 0;
|
virtual void menu_hide() = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user