summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-11-08 17:59:38 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-11-08 18:01:55 +0000
commite1fc2677e3a01b779c689a971cd2207ef08746d7 (patch)
tree632d806ab78dde010c73c69676b0413088304d6a /src
parent484fffc288d0ce2a29ab1737b5c6122fa67dc5ac (diff)
Add a MenuDoc style for info box, that will place it next to the menu
Diffstat (limited to 'src')
-rw-r--r--src/client.cc2
-rw-r--r--src/commands.cc4
-rw-r--r--src/input_handler.cc2
-rw-r--r--src/insert_completer.cc8
-rw-r--r--src/ncurses.cc12
-rw-r--r--src/ncurses.hh2
-rw-r--r--src/normal.cc6
-rw-r--r--src/remote.cc6
-rw-r--r--src/user_interface.hh9
9 files changed, 29 insertions, 22 deletions
diff --git a/src/client.cc b/src/client.cc
index 3143a0a7..daa89f6f 100644
--- a/src/client.cc
+++ b/src/client.cc
@@ -144,7 +144,7 @@ void Client::check_buffer_fs_timestamp()
"reload '" + buffer.display_name() + "' ?",
"'" + buffer.display_name() + "' was modified externally\n"
"press r or y to reload, k or n to keep",
- pos, get_face("Information"), MenuStyle::Prompt);
+ pos, get_face("Information"), InfoStyle::Prompt);
m_input_handler.on_next_key(KeymapMode::None,
[this, filename](Key key, Context& context) {
diff --git a/src/commands.cc b/src/commands.cc
index 46dbd650..25060d18 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -1234,7 +1234,7 @@ const CommandDesc info_cmd = {
context.ui().info_hide();
if (parser.positional_count() > 0)
{
- MenuStyle style = MenuStyle::Prompt;
+ InfoStyle style = InfoStyle::Prompt;
CharCoord pos = context.ui().dimensions();
pos.column -= 1;
if (parser.has_option("anchor"))
@@ -1247,7 +1247,7 @@ const CommandDesc info_cmd = {
ByteCoord coord{str_to_int(anchor.substr(0, dotb))-1,
str_to_int(anchor.substr(dotb+1))-1};
pos = context.window().display_position(coord);
- style = MenuStyle::Inline;
+ style = InfoStyle::Inline;
}
const String& title = parser.has_option("title") ? parser.option_value("title") : "";
context.ui().info_show(title, parser[0], pos, get_face("Information"), style);
diff --git a/src/input_handler.cc b/src/input_handler.cc
index fde0aa51..5db479f1 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -118,7 +118,7 @@ public:
Face col = get_face("Information");
CharCoord pos = context().window().dimensions();
pos.column -= 1;
- context().ui().info_show(key_to_str(key), it->second.docstring, pos, col, MenuStyle::Prompt);
+ context().ui().info_show(key_to_str(key), it->second.docstring, pos, col, InfoStyle::Prompt);
}
it->second.func(context(), m_count);
}
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index a42c4b62..2a683310 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -279,12 +279,8 @@ void InsertCompleter::select(int offset)
{
m_context.ui().menu_select(m_current_candidate);
if (not candidate.second.empty())
- {
- CharCoord pos = m_context.window().dimensions();
- pos.column -= 1;
- m_context.ui().info_show(candidate.first, candidate.second, pos,
- get_face("Information"), MenuStyle::Prompt);
- }
+ m_context.ui().info_show(candidate.first, candidate.second, CharCoord{},
+ get_face("Information"), InfoStyle::MenuDoc);
}
// when we select a match, remove non displayed matches from the candidates
// which are considered as invalid with the new completion timestamp
diff --git a/src/ncurses.cc b/src/ncurses.cc
index ef1bba40..03e44cb1 100644
--- a/src/ncurses.cc
+++ b/src/ncurses.cc
@@ -767,22 +767,26 @@ static String make_info_box(StringView title, StringView message,
}
void NCursesUI::info_show(StringView title, StringView content,
- CharCoord anchor, Face face, MenuStyle style)
+ CharCoord anchor, Face face, InfoStyle style)
{
if (m_info_win)
delwin(m_info_win);
StringView info_box = content;
String fancy_info_box;
- if (style == MenuStyle::Prompt)
+ if (style == InfoStyle::Prompt)
{
fancy_info_box = make_info_box(title, content, m_dimensions.column);
info_box = fancy_info_box;
}
CharCoord size = compute_needed_size(info_box);
-
- CharCoord pos = compute_pos(anchor, size, m_menu_win);
+ CharCoord pos;
+ if (style == InfoStyle::MenuDoc and m_menu_win and m_menu_columns == 1)
+ pos = window_pos(m_menu_win) +
+ CharCoord{0_line, window_size(m_menu_win).column};
+ else
+ pos = compute_pos(anchor, size, m_menu_win);
m_info_win = (NCursesWin*)newwin((int)size.line, (int)size.column,
(int)pos.line, (int)pos.column);
diff --git a/src/ncurses.hh b/src/ncurses.hh
index d321f06a..8674f075 100644
--- a/src/ncurses.hh
+++ b/src/ncurses.hh
@@ -34,7 +34,7 @@ public:
void info_show(StringView title, StringView content,
CharCoord anchor, Face face,
- MenuStyle style) override;
+ InfoStyle style) override;
void info_hide() override;
void refresh() override;
diff --git a/src/normal.cc b/src/normal.cc
index fcf28ac6..5d258e59 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -116,7 +116,7 @@ bool show_auto_info_ifn(StringView title, StringView info,
Face face = get_face("Information");
CharCoord pos = context.window().dimensions();
pos.column -= 1;
- context.ui().info_show(title, info, pos, face, MenuStyle::Prompt);
+ context.ui().info_show(title, info, pos, face, InfoStyle::Prompt);
return true;
}
@@ -366,7 +366,7 @@ void command(Context& context, int)
CharCoord pos = context.window().dimensions();
pos.column -= 1;
if (not info.first.empty() and not info.second.empty())
- context.ui().info_show(info.first, info.second, pos , col, MenuStyle::Prompt);
+ context.ui().info_show(info.first, info.second, pos , col, InfoStyle::Prompt);
}
}
if (event == PromptEvent::Validate)
@@ -569,7 +569,7 @@ void regex_prompt(Context& context, const String prompt, T func)
Face face = get_face("Information");
CharCoord pos = context.window().dimensions();
pos.column -= 1;
- context.ui().info_show("regex error", err.what(), pos, face, MenuStyle::Prompt);
+ context.ui().info_show("regex error", err.what(), pos, face, InfoStyle::Prompt);
}
}
}
diff --git a/src/remote.cc b/src/remote.cc
index 7ca652f7..b7a4b4cf 100644
--- a/src/remote.cc
+++ b/src/remote.cc
@@ -256,7 +256,7 @@ public:
void info_show(StringView title, StringView content,
CharCoord anchor, Face face,
- MenuStyle style) override;
+ InfoStyle style) override;
void info_hide() override;
void draw(const DisplayBuffer& display_buffer,
@@ -323,7 +323,7 @@ void RemoteUI::menu_hide()
void RemoteUI::info_show(StringView title, StringView content,
CharCoord anchor, Face face,
- MenuStyle style)
+ InfoStyle style)
{
Message msg(m_socket_watcher.fd());
msg.write(RemoteUIMsg::InfoShow);
@@ -490,7 +490,7 @@ void RemoteClient::process_next_message()
auto content = read<String>(socket);
auto anchor = read<CharCoord>(socket);
auto face = read<Face>(socket);
- auto style = read<MenuStyle>(socket);
+ auto style = read<InfoStyle>(socket);
m_ui->info_show(title, content, anchor, face, style);
break;
}
diff --git a/src/user_interface.hh b/src/user_interface.hh
index 631309ad..07f6eaa8 100644
--- a/src/user_interface.hh
+++ b/src/user_interface.hh
@@ -20,6 +20,13 @@ enum class MenuStyle
Inline
};
+enum class InfoStyle
+{
+ Prompt,
+ Inline,
+ MenuDoc
+};
+
using InputCallback = std::function<void()>;
class UserInterface : public SafeCountable
@@ -35,7 +42,7 @@ public:
virtual void info_show(StringView title, StringView content,
CharCoord anchor, Face face,
- MenuStyle style) = 0;
+ InfoStyle style) = 0;
virtual void info_hide() = 0;
virtual void draw(const DisplayBuffer& display_buffer,