ext_cmdline: use new highlight representation for cmdline_block

Make sure cmdline updates will receive highlight specifications the same
way as screen cells. This is controlled by the ext_newgrid option so
nothing is changed by default (as screen cells are also not changed by
default).  This was already done for the cmdline itself in #8221, this
extends it to cmdline_block. Which currently doesn't store highlights,
but the placeholder should be one that makes sense for future use.
This commit is contained in:
Björn Linse
2018-08-21 21:12:01 +02:00
parent a8b4d76a0a
commit 03978a0f29
2 changed files with 32 additions and 9 deletions

View File

@@ -501,10 +501,8 @@ static void remote_ui_flush(UI *ui)
}
}
static void remote_ui_cmdline_show(UI *ui, Array args)
static Array translate_contents(UI *ui, Array contents)
{
Array new_args = ARRAY_DICT_INIT;
Array contents = args.items[0].data.array;
Array new_contents = ARRAY_DICT_INIT;
for (size_t i = 0; i < contents.size; i++) {
Array item = contents.items[i].data.array;
@@ -519,23 +517,48 @@ static void remote_ui_cmdline_show(UI *ui, Array args)
ADD(new_item, copy_object(item.items[1]));
ADD(new_contents, ARRAY_OBJ(new_item));
}
ADD(new_args, ARRAY_OBJ(new_contents));
return new_contents;
}
static Array translate_firstarg(UI *ui, Array args)
{
Array new_args = ARRAY_DICT_INIT;
Array contents = args.items[0].data.array;
ADD(new_args, ARRAY_OBJ(translate_contents(ui, contents)));
for (size_t i = 1; i < args.size; i++) {
ADD(new_args, copy_object(args.items[i]));
}
push_call(ui, "cmdline_show", new_args);
return new_args;
}
static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
{
if (!ui->ui_ext[kUINewgrid]) {
// the representation of cmdline_show changed, translate back
// the representation of highlights in cmdline changed, translate back
// never consumes args
if (strequal(name, "cmdline_show")) {
remote_ui_cmdline_show(ui, args);
// never consumes args
Array new_args = translate_firstarg(ui, args);
push_call(ui, name, new_args);
return;
} else if (strequal(name, "cmdline_block_show")) {
Array new_args = ARRAY_DICT_INIT;
Array block = args.items[0].data.array;
Array new_block = ARRAY_DICT_INIT;
for (size_t i = 0; i < block.size; i++) {
ADD(new_block,
ARRAY_OBJ(translate_contents(ui, block.items[i].data.array)));
}
ADD(new_args, ARRAY_OBJ(new_block));
push_call(ui, name, new_args);
return;
} else if (strequal(name, "cmdline_block_append")) {
Array new_args = translate_firstarg(ui, args);
push_call(ui, name, new_args);
return;
}
}
Array my_args = ARRAY_DICT_INIT;
// Objects are currently single-reference
// make a copy, but only if necessary

View File

@@ -2990,7 +2990,7 @@ void ui_ext_cmdline_block_append(int indent, const char *line)
memcpy(buf + indent, line, strlen(line)); // -V575
Array item = ARRAY_DICT_INIT;
ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));
ADD(item, INTEGER_OBJ(0));
ADD(item, STRING_OBJ(cstr_as_string(buf)));
Array content = ARRAY_DICT_INIT;
ADD(content, ARRAY_OBJ(item));