Refactor ncurses assistant option handling
The option is now ncurses_assistant, defaults to clippy, none and off a recognized to disable assistant.
This commit is contained in:
parent
accc510d15
commit
ec1d5509bb
|
@ -29,19 +29,20 @@ using std::max;
|
||||||
|
|
||||||
struct NCursesWin : WINDOW {};
|
struct NCursesWin : WINDOW {};
|
||||||
|
|
||||||
static const Vector<String> cat_assistant =
|
static const StringView assistant_cat[] =
|
||||||
{ " ___ ",
|
{ R"( ___ )",
|
||||||
" / __) ",
|
R"( / __) )",
|
||||||
" \\ \\ ╭",
|
R"( \ \ ╭)",
|
||||||
" .·' '. │",
|
R"( .·' '. │)",
|
||||||
" ” ' ╯",
|
R"( ” ' ╯)",
|
||||||
" |\\_/\\ ╯ ",
|
R"( |\_/\ ╯ )",
|
||||||
" / . | ",
|
R"( / . | )",
|
||||||
" | | | ’l_╯ ",
|
R"( | | | ’l_╯ )",
|
||||||
" \\_ -__/ ' ",
|
R"( \_ -__/ ' )",
|
||||||
" /_/ /_/ ",
|
R"( /_/ /_/ )",
|
||||||
" "};
|
R"( )"};
|
||||||
static const Vector<String> trombon_assistant =
|
|
||||||
|
static const StringView assistant_clippy[] =
|
||||||
{ " ╭──╮ ",
|
{ " ╭──╮ ",
|
||||||
" │ │ ",
|
" │ │ ",
|
||||||
" @ @ ╭",
|
" @ @ ╭",
|
||||||
|
@ -50,8 +51,6 @@ static const Vector<String> trombon_assistant =
|
||||||
" │╰─╯│ ",
|
" │╰─╯│ ",
|
||||||
" ╰───╯ ",
|
" ╰───╯ ",
|
||||||
" " };
|
" " };
|
||||||
static Vector<String> s_assistant = trombon_assistant;
|
|
||||||
|
|
||||||
|
|
||||||
static void set_attribute(WINDOW* window, int attribute, bool on)
|
static void set_attribute(WINDOW* window, int attribute, bool on)
|
||||||
{
|
{
|
||||||
|
@ -244,7 +243,8 @@ NCursesUI::NCursesUI()
|
||||||
: m_stdin_watcher{0, [this](FDWatcher&, EventMode mode) {
|
: m_stdin_watcher{0, [this](FDWatcher&, EventMode mode) {
|
||||||
if (m_input_callback)
|
if (m_input_callback)
|
||||||
m_input_callback(mode);
|
m_input_callback(mode);
|
||||||
}}
|
}},
|
||||||
|
m_assistant(assistant_clippy)
|
||||||
{
|
{
|
||||||
initscr();
|
initscr();
|
||||||
raw();
|
raw();
|
||||||
|
@ -713,13 +713,12 @@ static CharCoord compute_pos(CharCoord anchor, CharCoord size,
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool assist = true>
|
String make_info_box(StringView title, StringView message, CharCount max_width,
|
||||||
String make_info_box(StringView title, StringView message,
|
ArrayView<StringView> assistant)
|
||||||
CharCount max_width)
|
|
||||||
{
|
{
|
||||||
CharCoord assistant_size;
|
CharCoord assistant_size;
|
||||||
if (assist)
|
if (not assistant.empty())
|
||||||
assistant_size = { (int)s_assistant.size(), s_assistant[0].char_length() };
|
assistant_size = { (int)assistant.size(), assistant[0].char_length() };
|
||||||
|
|
||||||
const CharCount max_bubble_width = max_width - assistant_size.column - 6;
|
const CharCount max_bubble_width = max_width - assistant_size.column - 6;
|
||||||
Vector<StringView> lines = wrap_lines(message, max_bubble_width);
|
Vector<StringView> lines = wrap_lines(message, max_bubble_width);
|
||||||
|
@ -734,8 +733,8 @@ String make_info_box(StringView title, StringView message,
|
||||||
for (LineCount i = 0; i < line_count; ++i)
|
for (LineCount i = 0; i < line_count; ++i)
|
||||||
{
|
{
|
||||||
constexpr Codepoint dash{L'─'};
|
constexpr Codepoint dash{L'─'};
|
||||||
if (assist)
|
if (not assistant.empty())
|
||||||
result += s_assistant[min((int)i, (int)assistant_size.line-1)];
|
result += assistant[min((int)i, (int)assistant_size.line-1)];
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
if (title.empty())
|
if (title.empty())
|
||||||
|
@ -772,7 +771,8 @@ void NCursesUI::info_show(StringView title, StringView content,
|
||||||
String fancy_info_box;
|
String fancy_info_box;
|
||||||
if (style == InfoStyle::Prompt)
|
if (style == InfoStyle::Prompt)
|
||||||
{
|
{
|
||||||
fancy_info_box = make_info_box(title, content, m_dimensions.column);
|
fancy_info_box = make_info_box(title, content, m_dimensions.column,
|
||||||
|
m_assistant);
|
||||||
info_box = fancy_info_box;
|
info_box = fancy_info_box;
|
||||||
anchor = CharCoord{m_status_on_top ? 0 : m_dimensions.line,
|
anchor = CharCoord{m_status_on_top ? 0 : m_dimensions.line,
|
||||||
m_dimensions.column-1};
|
m_dimensions.column-1};
|
||||||
|
@ -843,11 +843,16 @@ void NCursesUI::abort()
|
||||||
void NCursesUI::set_ui_options(const Options& options)
|
void NCursesUI::set_ui_options(const Options& options)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
auto it = options.find("assistant");
|
auto it = options.find("ncurses_assistant");
|
||||||
if (it != options.end())
|
if (it != options.end())
|
||||||
s_assistant = (it->second == "cat") ? cat_assistant :
|
{
|
||||||
(it->second == "trombon") ? trombon_assistant :
|
if (it->second == "cat")
|
||||||
s_assistant;
|
m_assistant = assistant_cat;
|
||||||
|
else if (it->second == "clippy")
|
||||||
|
m_assistant = assistant_clippy;
|
||||||
|
else if (it->second == "none" or it->second == "off")
|
||||||
|
m_assistant = ArrayView<StringView>{};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
#include "face.hh"
|
#include "face.hh"
|
||||||
#include "user_interface.hh"
|
#include "user_interface.hh"
|
||||||
|
#include "array_view.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -72,6 +73,7 @@ private:
|
||||||
InputCallback m_input_callback;
|
InputCallback m_input_callback;
|
||||||
|
|
||||||
bool m_status_on_top = false;
|
bool m_status_on_top = false;
|
||||||
|
ArrayView<StringView> m_assistant;
|
||||||
|
|
||||||
bool m_dirty = false;
|
bool m_dirty = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user