aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/message.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/message.c')
-rw-r--r--src/nvim/message.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 30e906cd5f..8999365d32 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -228,20 +228,25 @@ int msg_attr(const char *s, const int attr)
}
/// similar to msg_outtrans_attr, but support newlines and tabs.
-void msg_multiline_attr(const char *s, int attr, bool check_int)
+void msg_multiline_attr(const char *s, int attr,
+ bool check_int, bool *need_clear)
FUNC_ATTR_NONNULL_ALL
{
const char *next_spec = s;
- while (next_spec != NULL && (!check_int || !got_int)) {
+ while (next_spec != NULL) {
+ if (check_int && got_int) {
+ return;
+ }
next_spec = strpbrk(s, "\t\n\r");
if (next_spec != NULL) {
// Printing all char that are before the char found by strpbrk
- msg_outtrans_len_attr((char_u *)s, next_spec - s, attr);
+ msg_outtrans_len_attr((const char_u *)s, next_spec - s, attr);
- if (*next_spec != TAB) {
+ if (*next_spec != TAB && *need_clear) {
msg_clr_eos();
+ *need_clear = false;
}
msg_putchar_attr((uint8_t)(*next_spec), attr);
s = next_spec + 1;
@@ -253,6 +258,7 @@ void msg_multiline_attr(const char *s, int attr, bool check_int)
if (*s != NUL) {
msg_outtrans_attr((char_u *)s, attr);
}
+ return;
}
@@ -300,23 +306,21 @@ bool msg_attr_keep(char_u *s, int attr, bool keep, bool multiline)
add_msg_hist((const char *)s, -1, attr, multiline);
}
- /* When displaying keep_msg, don't let msg_start() free it, caller must do
- * that. */
- if (s == keep_msg)
- keep_msg = NULL;
-
/* Truncate the message if needed. */
msg_start();
buf = msg_strtrunc(s, FALSE);
if (buf != NULL)
s = buf;
+ bool need_clear = true;
if (multiline) {
- msg_multiline_attr((char *)s, attr, false);
+ msg_multiline_attr((char *)s, attr, false, &need_clear);
} else {
msg_outtrans_attr(s, attr);
}
- msg_clr_eos();
+ if (need_clear) {
+ msg_clr_eos();
+ }
retval = msg_end();
if (keep && retval && vim_strsize(s) < (int)(Rows - cmdline_row - 1)
@@ -1375,7 +1379,7 @@ static void msg_home_replace_attr(char_u *fname, int attr)
/*
* Output 'len' characters in 'str' (including NULs) with translation
- * if 'len' is -1, output upto a NUL character.
+ * if 'len' is -1, output up to a NUL character.
* Use attributes 'attr'.
* Return the number of characters it takes on the screen.
*/
@@ -1384,12 +1388,12 @@ int msg_outtrans(char_u *str)
return msg_outtrans_attr(str, 0);
}
-int msg_outtrans_attr(char_u *str, int attr)
+int msg_outtrans_attr(const char_u *str, int attr)
{
return msg_outtrans_len_attr(str, (int)STRLEN(str), attr);
}
-int msg_outtrans_len(char_u *str, int len)
+int msg_outtrans_len(const char_u *str, int len)
{
return msg_outtrans_len_attr(str, len, 0);
}
@@ -1402,7 +1406,7 @@ char_u *msg_outtrans_one(char_u *p, int attr)
{
int l;
- if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
+ if ((l = utfc_ptr2len(p)) > 1) {
msg_outtrans_len_attr(p, l, attr);
return p + l;
}
@@ -1410,7 +1414,7 @@ char_u *msg_outtrans_one(char_u *p, int attr)
return p + 1;
}
-int msg_outtrans_len_attr(char_u *msgstr, int len, int attr)
+int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr)
{
int retval = 0;
const char *str = (const char *)msgstr;
@@ -1498,7 +1502,7 @@ void msg_make(char_u *arg)
}
}
-/// Output the string 'str' upto a NUL character.
+/// Output the string 'str' up to a NUL character.
/// Return the number of characters it takes on the screen.
///
/// If K_SPECIAL is encountered, then it is taken in conjunction with the
@@ -1512,7 +1516,8 @@ void msg_make(char_u *arg)
/// the character/string -- webb
int msg_outtrans_special(
const char_u *strstart,
- int from ///< true for LHS of a mapping
+ bool from, ///< true for LHS of a mapping
+ int maxlen ///< screen columns, 0 for unlimeted
)
{
if (strstart == NULL) {
@@ -1532,6 +1537,9 @@ int msg_outtrans_special(
string = str2special((const char **)&str, from, false);
}
const int len = vim_strsize((char_u *)string);
+ if (maxlen > 0 && retval + len >= maxlen) {
+ break;
+ }
// Highlight special keys
msg_puts_attr(string, (len > 1
&& (*mb_ptr2len)((char_u *)string) <= 1
@@ -2561,10 +2569,15 @@ static int do_more_prompt(int typed_char)
msgchunk_T *mp;
int i;
+ // If headless mode is enabled and no input is required, this variable
+ // will be true. However If server mode is enabled, the message "--more--"
+ // should be displayed.
+ bool no_need_more = headless_mode && !embedded_mode;
+
// We get called recursively when a timer callback outputs a message. In
// that case don't show another prompt. Also when at the hit-Enter prompt
// and nothing was typed.
- if (entered || (State == HITRETURN && typed_char == 0)) {
+ if (no_need_more || entered || (State == HITRETURN && typed_char == 0)) {
return false;
}
entered = true;