diff options
author | notomo <notomo.motono@gmail.com> | 2021-01-11 15:18:51 +0900 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-01-20 16:41:39 +0100 |
commit | 8e86f5e460398962dd58ddf727a0586710ce6f95 (patch) | |
tree | e8a571174fc56f7ec5203558b6275bb5ce8b5298 /src/nvim/message.c | |
parent | 1785ac3e3787e84846d753ceb73a239f5575a691 (diff) | |
download | rneovim-8e86f5e460398962dd58ddf727a0586710ce6f95.tar.gz rneovim-8e86f5e460398962dd58ddf727a0586710ce6f95.tar.bz2 rneovim-8e86f5e460398962dd58ddf727a0586710ce6f95.zip |
api: nvim_echo
Diffstat (limited to 'src/nvim/message.c')
-rw-r--r-- | src/nvim/message.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c index f94529c687..ba7a667a60 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -890,6 +890,40 @@ char_u *msg_may_trunc(int force, char_u *s) return s; } +void clear_hl_msg(HlMessage *hl_msg) +{ + for (size_t i = 0; i < kv_size(*hl_msg); i++) { + xfree(kv_A(*hl_msg, i).text.data); + } + kv_destroy(*hl_msg); + *hl_msg = (HlMessage)KV_INITIAL_VALUE; +} + +#define LINE_BUFFER_SIZE 4096 + +void add_hl_msg_hist(HlMessage hl_msg) +{ + // TODO(notomo): support multi highlighted message history + size_t pos = 0; + char buf[LINE_BUFFER_SIZE]; + for (uint32_t i = 0; i < kv_size(hl_msg); i++) { + HlMessageChunk chunk = kv_A(hl_msg, i); + for (uint32_t j = 0; j < chunk.text.size; j++) { + if (pos == LINE_BUFFER_SIZE - 1) { + buf[pos] = NUL; + add_msg_hist((const char *)buf, -1, MSG_HIST, true); + pos = 0; + continue; + } + buf[pos++] = chunk.text.data[j]; + } + } + if (pos != 0) { + buf[pos] = NUL; + add_msg_hist((const char *)buf, -1, MSG_HIST, true); + } +} + /// @param[in] len Length of s or -1. static void add_msg_hist(const char *s, int len, int attr, bool multiline) { |