summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-11-10 13:28:06 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-11-10 13:37:17 +0000
commit7d4c9c2ccf75f56e449dc28e91f960be144fdafd (patch)
tree54f7fd57122c9869b76727025086b1d7047315c5 /src
parent075e4985d79c81b23842ade9ccc1ac83ec312af3 (diff)
Support hinting if an inline info should be above or below the anchor
Used by ctags function info, we always want it *above* the opening parenthesis so that it does not hide multi line parameter lists.
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc11
-rw-r--r--src/ncurses.cc21
-rw-r--r--src/user_interface.hh2
3 files changed, 29 insertions, 5 deletions
diff --git a/src/commands.cc b/src/commands.cc
index 7106df89..6e5a2836 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -1224,6 +1224,7 @@ const CommandDesc info_cmd = {
"info <switches> <params>...: display an info box with the params as content",
ParameterDesc{
SwitchMap{ { "anchor", { true, "set info anchoring <line>.<column>" } },
+ { "placement", { true, "set placement relative to anchor (above, below)" } },
{ "title", { true, "set info title" } } },
ParameterDesc::Flags::None, 0, 1
},
@@ -1247,6 +1248,16 @@ const CommandDesc info_cmd = {
str_to_int(anchor.substr(dotb+1))-1};
pos = context.window().display_position(coord);
style = InfoStyle::Inline;
+ if (parser.has_option("placement"))
+ {
+ auto placement = parser.option_value("placement");
+ if (placement == "above")
+ style = InfoStyle::InlineAbove;
+ else if (placement == "below")
+ style = InfoStyle::InlineBelow;
+ else
+ throw runtime_error("invalid placement " + placement);
+ }
}
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/ncurses.cc b/src/ncurses.cc
index 88a4a93b..2931e340 100644
--- a/src/ncurses.cc
+++ b/src/ncurses.cc
@@ -642,12 +642,23 @@ static CharCoord compute_needed_size(StringView str)
}
static CharCoord compute_pos(CharCoord anchor, CharCoord size,
- WINDOW* opt_window_to_avoid = nullptr)
+ WINDOW* opt_window_to_avoid = nullptr,
+ bool prefer_above = false)
{
CharCoord scrsize = window_size(stdscr);
- CharCoord pos = { anchor.line+1, anchor.column };
- if (pos.line + size.line >= scrsize.line)
- pos.line = max(0_line, anchor.line - size.line);
+ CharCoord pos;
+ if (prefer_above)
+ {
+ pos = anchor - CharCoord{size.line};
+ if (pos.line < 0)
+ prefer_above = false;
+ }
+ if (not prefer_above)
+ {
+ pos = anchor + CharCoord{1_line};
+ if (pos.line + size.line >= scrsize.line)
+ pos.line = max(0_line, anchor.line - size.line);
+ }
if (pos.column + size.column >= scrsize.column)
pos.column = max(0_char, anchor.column - size.column+1);
@@ -790,7 +801,7 @@ void NCursesUI::info_show(StringView title, StringView content,
pos = window_pos(m_menu_win) +
CharCoord{0_line, window_size(m_menu_win).column};
else
- pos = compute_pos(anchor, size, m_menu_win);
+ pos = compute_pos(anchor, size, m_menu_win, style == InfoStyle::InlineAbove);
m_info_win = (NCursesWin*)newwin((int)size.line, (int)size.column,
(int)pos.line, (int)pos.column);
diff --git a/src/user_interface.hh b/src/user_interface.hh
index 07f6eaa8..4f959544 100644
--- a/src/user_interface.hh
+++ b/src/user_interface.hh
@@ -24,6 +24,8 @@ enum class InfoStyle
{
Prompt,
Inline,
+ InlineAbove,
+ InlineBelow,
MenuDoc
};