aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-01-02 15:43:07 +0100
committerJustin M. Keyes <justinkz@gmail.com>2023-01-05 17:10:02 +0100
commite8ab2187166801cdbc87cea57fa0b3aba8e75064 (patch)
tree7a5115e7e7ed3cd8cd457435c619e7eef20ed788
parentf43de742e881e54a3602e00c8c247cecca65a266 (diff)
downloadrneovim-e8ab2187166801cdbc87cea57fa0b3aba8e75064.tar.gz
rneovim-e8ab2187166801cdbc87cea57fa0b3aba8e75064.tar.bz2
rneovim-e8ab2187166801cdbc87cea57fa0b3aba8e75064.zip
feat(message): avoid spam on failed os_msg
also de-dupe the code
-rw-r--r--src/nvim/message.c33
-rw-r--r--src/nvim/vim.h6
2 files changed, 21 insertions, 18 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 041e5ed6c3..118d144617 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -3003,31 +3003,36 @@ static int do_more_prompt(int typed_char)
}
#if defined(MSWIN)
-void os_errmsg(char *str)
+/// Headless (no UI) error message handler.
+static void do_msg(char *str, bool errmsg)
{
+ static bool did_err = false;
assert(str != NULL);
wchar_t *utf16str;
int r = utf8_to_utf16(str, -1, &utf16str);
- if (r != 0) {
+ if (r != 0 && !did_err) {
+ did_err = true;
fprintf(stderr, "utf8_to_utf16 failed: %d", r);
- } else {
- fwprintf(stderr, L"%ls", utf16str);
+ ELOG("utf8_to_utf16 failed: %d", r);
+ } else if (r == 0) {
+ if (errmsg) {
+ fwprintf(stderr, L"%ls", utf16str);
+ } else {
+ wprintf(L"%ls", utf16str);
+ }
xfree(utf16str);
}
}
-/// Give a message. To be used when the UI is not initialized yet.
+void os_errmsg(char *str)
+{
+ do_msg(str, true);
+}
+
+/// Headless (no UI) message handler.
void os_msg(char *str)
{
- assert(str != NULL);
- wchar_t *utf16str;
- int r = utf8_to_utf16(str, -1, &utf16str);
- if (r != 0) {
- fprintf(stderr, "utf8_to_utf16 failed: %d", r);
- } else {
- wprintf(L"%ls", utf16str);
- xfree(utf16str);
- }
+ do_msg(str, false);
}
#endif // MSWIN
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index bfe75ef9f7..df24e423cf 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -245,12 +245,10 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext()
/// plus six following composing characters of three bytes each.
#define MB_MAXBYTES 21
-// This has to go after the include of proto.h, as proto/gui.pro declares
-// functions of these names. The declarations would break if the defines had
-// been seen at that stage. But it must be before globals.h, where error_ga
-// is declared.
#ifndef MSWIN
+/// Headless (no UI) error message handler.
# define os_errmsg(str) fprintf(stderr, "%s", (str))
+/// Headless (no UI) message handler.
# define os_msg(str) printf("%s", (str))
#endif