aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/private/helpers.c17
-rw-r--r--src/nvim/ex_getln.c31
2 files changed, 43 insertions, 5 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index f00fbf69ea..2944925a9c 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -703,6 +703,23 @@ String cstr_to_string(const char *str)
};
}
+/// Copies buffer to an allocated String.
+/// The resulting string is also NUL-terminated, to facilitate interoperating
+/// with code using C strings.
+///
+/// @param buf the buffer to copy
+/// @param size length of the buffer
+/// @return the resulting String, if the input string was NULL, an
+/// empty String is returned
+String cbuf_to_string(const char *buf, size_t size)
+ FUNC_ATTR_NONNULL_ALL
+{
+ return (String) {
+ .data = xmemdupz(buf, size),
+ .size = size
+ };
+}
+
/// Creates a String using the given C string. Unlike
/// cstr_to_string this function DOES NOT copy the C string.
///
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 93c060b4b7..624a108bd4 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -2372,6 +2372,7 @@ static bool color_cmdline(const CmdlineInfo *const colored_ccline,
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
bool printed_errmsg = false;
+
#define PRINT_ERRMSG(...) \
do { \
msg_putchar('\n'); \
@@ -2405,7 +2406,7 @@ static bool color_cmdline(const CmdlineInfo *const colored_ccline,
static unsigned prev_prompt_id = UINT_MAX;
static int prev_prompt_errors = 0;
- Callback color_cb = { .type = kCallbackNone };
+ Callback color_cb = CALLBACK_NONE;
bool can_free_cb = false;
TryState tstate;
Error err = ERROR_INIT;
@@ -2722,10 +2723,30 @@ draw_cmdline_no_arabicshape:
void ui_ext_cmdline_show(void)
{
Array content = ARRAY_DICT_INIT;
- Array text = ARRAY_DICT_INIT;
- ADD(text, STRING_OBJ(cstr_to_string("Normal")));
- ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
- ADD(content, ARRAY_OBJ(text));
+ if (kv_size(last_ccline_colors.colors)) {
+ for (size_t i = 0; i < kv_size(last_ccline_colors.colors); i++) {
+ CmdlineColorChunk chunk = kv_A(last_ccline_colors.colors, i);
+ Array item = ARRAY_DICT_INIT;
+
+ if (chunk.attr) {
+ attrentry_T *aep = syn_cterm_attr2entry(chunk.attr);
+ // TODO(bfredl): this desicion could be delayed by making attr_code a
+ // recognized type
+ HlAttrs rgb_attrs = attrentry2hlattrs(aep, true);
+ ADD(item, DICTIONARY_OBJ(hlattrs2dict(rgb_attrs)));
+ } else {
+ ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));
+ }
+ ADD(item, STRING_OBJ(cbuf_to_string((char *)ccline.cmdbuff + chunk.start,
+ chunk.end-chunk.start)));
+ ADD(content, ARRAY_OBJ(item));
+ }
+ } else {
+ Array item = ARRAY_DICT_INIT;
+ ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));
+ ADD(item, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
+ ADD(content, ARRAY_OBJ(item));
+ }
ui_call_cmdline_show(content, ccline.cmdpos,
cchar_to_string((char)ccline.cmdfirstc),
cstr_to_string((char *)(ccline.cmdprompt)),