aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-05-09 14:10:25 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-05-13 09:33:41 -0300
commitc1d3539fb4eeee6090d2b31aed45df06a37a6ae3 (patch)
treef69418ce4f9f3f2c9e87090e12e944b2a0695f12 /src
parentd2b715bf1de31fc784b399d6aafb5f7e41aef6cc (diff)
downloadrneovim-c1d3539fb4eeee6090d2b31aed45df06a37a6ae3.tar.gz
rneovim-c1d3539fb4eeee6090d2b31aed45df06a37a6ae3.tar.bz2
rneovim-c1d3539fb4eeee6090d2b31aed45df06a37a6ae3.zip
API: Implement vim_{out,err}_write
Diffstat (limited to 'src')
-rw-r--r--src/api/vim.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/api/vim.c b/src/api/vim.c
index 7eaa27d580..b3fef535d6 100644
--- a/src/api/vim.c
+++ b/src/api/vim.c
@@ -13,9 +13,21 @@
#include "ex_docmd.h"
#include "screen.h"
#include "memory.h"
+#include "message.h"
#include "eval.h"
#include "misc2.h"
+#define LINE_BUFFER_SIZE 4096
+
+/// Writes a message to vim output or error buffer. The string is split
+/// and flushed after each newline. Incomplete lines are kept for writing
+/// later.
+///
+/// @param message The message to write
+/// @param to_err True if it should be treated as an error message(use
+/// `emsg` instead of `msg` to print each line)
+static void write_msg(String message, bool to_err);
+
void vim_push_keys(String str)
{
abort();
@@ -151,12 +163,12 @@ void vim_set_option(String name, Object value, Error *err)
void vim_out_write(String str)
{
- abort();
+ write_msg(str, false);
}
void vim_err_write(String str)
{
- abort();
+ write_msg(str, true);
}
int64_t vim_get_buffer_count(void)
@@ -218,3 +230,26 @@ void vim_set_current_tabpage(Tabpage tabpage)
{
abort();
}
+
+static void write_msg(String message, bool to_err)
+{
+ static int pos = 0;
+ static char line_buf[LINE_BUFFER_SIZE];
+
+ for (uint32_t i = 0; i < message.size; i++) {
+ if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) {
+ // Flush line
+ line_buf[pos] = NUL;
+ if (to_err) {
+ emsg((uint8_t *)line_buf);
+ } else {
+ msg((uint8_t *)line_buf);
+ }
+
+ pos = 0;
+ continue;
+ }
+
+ line_buf[pos++] = message.data[i];
+ }
+}