mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 10:56:31 +00:00
Merge #10098 'win: fix msg_puts_printf()'
This commit is contained in:
@@ -2305,18 +2305,19 @@ int msg_use_printf(void)
|
||||
static void msg_puts_printf(const char *str, const ptrdiff_t maxlen)
|
||||
{
|
||||
const char *s = str;
|
||||
char buf[4];
|
||||
char buf[7];
|
||||
char *p;
|
||||
|
||||
while ((maxlen < 0 || s - str < maxlen) && *s != NUL) {
|
||||
int len = utf_ptr2len((const char_u *)s);
|
||||
if (!(silent_mode && p_verbose == 0)) {
|
||||
// NL --> CR NL translation (for Unix, not for "--version")
|
||||
p = &buf[0];
|
||||
if (*s == '\n' && !info_message) {
|
||||
*p++ = '\r';
|
||||
}
|
||||
*p++ = *s;
|
||||
*p = '\0';
|
||||
memcpy(p, s, len);
|
||||
*(p + len) = '\0';
|
||||
if (info_message) {
|
||||
mch_msg(buf);
|
||||
} else {
|
||||
@@ -2324,21 +2325,22 @@ static void msg_puts_printf(const char *str, const ptrdiff_t maxlen)
|
||||
}
|
||||
}
|
||||
|
||||
int cw = utf_char2cells(utf_ptr2char((const char_u *)s));
|
||||
// primitive way to compute the current column
|
||||
if (cmdmsg_rl) {
|
||||
if (*s == '\r' || *s == '\n') {
|
||||
msg_col = Columns - 1;
|
||||
} else {
|
||||
msg_col--;
|
||||
msg_col -= cw;
|
||||
}
|
||||
} else {
|
||||
if (*s == '\r' || *s == '\n') {
|
||||
msg_col = 0;
|
||||
} else {
|
||||
msg_col++;
|
||||
msg_col += cw;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
s += len;
|
||||
}
|
||||
msg_didout = true; // assume that line is not empty
|
||||
}
|
||||
@@ -2554,81 +2556,32 @@ static int do_more_prompt(int typed_char)
|
||||
return retval;
|
||||
}
|
||||
|
||||
#if defined(USE_MCH_ERRMSG)
|
||||
|
||||
#ifdef mch_errmsg
|
||||
# undef mch_errmsg
|
||||
#endif
|
||||
#ifdef mch_msg
|
||||
# undef mch_msg
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Give an error message. To be used when the screen hasn't been initialized
|
||||
* yet. When stderr can't be used, collect error messages until the GUI has
|
||||
* started and they can be displayed in a message box.
|
||||
*/
|
||||
void mch_errmsg(const char *const str)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
#if defined(WIN32)
|
||||
void mch_errmsg(char *str)
|
||||
{
|
||||
#ifdef UNIX
|
||||
/* On Unix use stderr if it's a tty.
|
||||
* When not going to start the GUI also use stderr.
|
||||
* On Mac, when started from Finder, stderr is the console. */
|
||||
if (os_isatty(2)) {
|
||||
fprintf(stderr, "%s", str);
|
||||
return;
|
||||
wchar_t *utf16str;
|
||||
int conversion_result = utf8_to_utf16((str), &utf16str);
|
||||
if (conversion_result != 0) {
|
||||
EMSG2("utf8_to_utf16 failed: %d", conversion_result);
|
||||
} else {
|
||||
fwprintf(stderr, L"%ls", utf16str);
|
||||
xfree(utf16str);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* avoid a delay for a message that isn't there */
|
||||
emsg_on_display = FALSE;
|
||||
|
||||
const size_t len = strlen(str) + 1;
|
||||
if (error_ga.ga_data == NULL) {
|
||||
ga_set_growsize(&error_ga, 80);
|
||||
error_ga.ga_itemsize = 1;
|
||||
}
|
||||
ga_grow(&error_ga, len);
|
||||
memmove(error_ga.ga_data + error_ga.ga_len, str, len);
|
||||
#ifdef UNIX
|
||||
/* remove CR characters, they are displayed */
|
||||
{
|
||||
char_u *p;
|
||||
|
||||
p = (char_u *)error_ga.ga_data + error_ga.ga_len;
|
||||
for (;; ) {
|
||||
p = vim_strchr(p, '\r');
|
||||
if (p == NULL)
|
||||
break;
|
||||
*p = ' ';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
--len; /* don't count the NUL at the end */
|
||||
error_ga.ga_len += len;
|
||||
}
|
||||
|
||||
/*
|
||||
* Give a message. To be used when the screen hasn't been initialized yet.
|
||||
* When there is no tty, collect messages until the GUI has started and they
|
||||
* can be displayed in a message box.
|
||||
*/
|
||||
// Give a message. To be used when the UI is not initialized yet.
|
||||
void mch_msg(char *str)
|
||||
{
|
||||
#ifdef UNIX
|
||||
/* On Unix use stdout if we have a tty. This allows "vim -h | more" and
|
||||
* uses mch_errmsg() when started from the desktop.
|
||||
* When not going to start the GUI also use stdout.
|
||||
* On Mac, when started from Finder, stderr is the console. */
|
||||
if (os_isatty(2)) {
|
||||
printf("%s", str);
|
||||
return;
|
||||
wchar_t *utf16str;
|
||||
int conversion_result = utf8_to_utf16((str), &utf16str);
|
||||
if (conversion_result != 0) {
|
||||
EMSG2("utf8_to_utf16 failed: %d", conversion_result);
|
||||
} else {
|
||||
wprintf(L"%ls", utf16str);
|
||||
xfree(utf16str);
|
||||
}
|
||||
# endif
|
||||
mch_errmsg(str);
|
||||
}
|
||||
#endif /* USE_MCH_ERRMSG */
|
||||
#endif // WIN32
|
||||
|
||||
/*
|
||||
* Put a character on the screen at the current message position and advance
|
||||
|
Reference in New Issue
Block a user