mirror of
https://github.com/neovim/neovim.git
synced 2025-10-16 14:56:08 +00:00
ext_cmdline: add support for highlighting
This commit is contained in:
@@ -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.
|
||||
///
|
||||
|
@@ -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)),
|
||||
|
Reference in New Issue
Block a user