Repository: neovim/neovim
File: src/nvim/message.c (C)

Code before:
  msg_outtrans_len(chunk, (int)(str.size - (size_t)(chunk - str.data)), hl_id, hist);
}

// Avoid starting a new message for each chunk and adding message to history in msg_keep().
static bool is_multihl = false;

/// Format a progress message, adding title and percent if given.
///
/// @param hl_msg Message chunks
/// @param msg_data Additional data for progress messages
static HlMessage fomrat_progress_message(HlMessage hl_msg, MessageData *msg_data)
{
  HlMessage updated_msg = KV_INITIAL_VALUE;
  // progress message are special displayed as "title: percent% msg"
  if (msg_data->title.size != 0) {
    // this block draws the "title:" before the progress-message
    String title = cstr_as_string(concat_str(msg_data->title.data, ": "));
    int hl_id = 0;
    if (msg_data->status.data == NULL) {
      hl_id = 0;
    } else if (strequal(msg_data->status.data, "success")) {
      hl_id = syn_check_group("MoreMsg", STRLEN_LITERAL("MoreMsg"));
    } else if (strequal(msg_data->status.data, "failed")) {
      hl_id = syn_check_group("ErrorMsg", STRLEN_LITERAL("ErrorMsg"));
    } else if (strequal(msg_data->status.data, "running")) {
      hl_id = 0;
    } else if (strequal(msg_data->status.data, "cancel")) {
      hl_id = syn_check_group("WarningMsg", STRLEN_LITERAL("WarningMsg"));
    }
    kv_push(updated_msg, ((HlMessageChunk){ .text = title, .hl_id = hl_id }));
  }
  if (msg_data->percent > 0) {
    char percent_buf[10];
    vim_snprintf(percent_buf, sizeof(percent_buf), "%3ld%% ", (long)msg_data->percent);
    String percent = cstr_to_string(percent_buf);
    int hl_id = syn_check_group("WarningMsg", STRLEN_LITERAL("WarningMsg"));
    kv_push(updated_msg, ((HlMessageChunk){ .text = percent, .hl_id = hl_id }));
  }

  if (kv_size(updated_msg) != 0) {
    for (uint32_t i = 0; i < kv_size(hl_msg); i++) {
      kv_push(updated_msg,
              ((HlMessageChunk){ .text = copy_string(kv_A(hl_msg, i).text, NULL),
                                 .hl_id = kv_A(hl_msg, i).hl_id }));
    }
    return updated_msg;
  } else {
    return hl_msg;
  }
}


Review comment (suggestion):
Maybe using `ModeMsg` when running is better? It more or less fits the highlight group name (default "mode") and adds green stand-out highlighting with default color scheme.

Code after:
  msg_outtrans_len(chunk, (int)(str.size - (size_t)(chunk - str.data)), hl_id, hist);
}

// Avoid starting a new message for each chunk and adding message to history in msg_keep().
static bool is_multihl = false;

/// Format a progress message, adding title and percent if given.
///
/// @param hl_msg Message chunks
/// @param msg_data Additional data for progress messages
static HlMessage format_progress_message(HlMessage hl_msg, MessageData *msg_data)
{
  HlMessage updated_msg = KV_INITIAL_VALUE;
  // progress messages are special. displayed as "title: percent% msg"
  if (msg_data->title.size != 0) {
    // this block draws the "title:" before the progress-message
    int hl_id = 0;
    if (msg_data->status.data == NULL) {
      hl_id = 0;
    } else if (strequal(msg_data->status.data, "success")) {
      hl_id = syn_check_group("OkMsg", STRLEN_LITERAL("OkMsg"));
    } else if (strequal(msg_data->status.data, "failed")) {
      hl_id = syn_check_group("ErrorMsg", STRLEN_LITERAL("ErrorMsg"));
    } else if (strequal(msg_data->status.data, "running")) {
      hl_id = syn_check_group("MoreMsg", STRLEN_LITERAL("MoreMsg"));
    } else if (strequal(msg_data->status.data, "cancel")) {
      hl_id = syn_check_group("WarningMsg", STRLEN_LITERAL("WarningMsg"));
    }
    kv_push(updated_msg,
            ((HlMessageChunk){ .text = copy_string(msg_data->title, NULL), .hl_id = hl_id }));
    kv_push(updated_msg, ((HlMessageChunk){ .text = cstr_to_string(": "), .hl_id = 0 }));
  }
  if (msg_data->percent > 0) {
    char percent_buf[10];
    vim_snprintf(percent_buf, sizeof(percent_buf), "%3ld%% ", (long)msg_data->percent);
    String percent = cstr_to_string(percent_buf);
    int hl_id = syn_check_group("WarningMsg", STRLEN_LITERAL("WarningMsg"));
    kv_push(updated_msg, ((HlMessageChunk){ .text = percent, .hl_id = hl_id }));
  }

  if (kv_size(updated_msg) != 0) {
    for (uint32_t i = 0; i < kv_size(hl_msg); i++) {
      kv_push(updated_msg,
              ((HlMessageChunk){ .text = copy_string(kv_A(hl_msg, i).text, NULL),
                                 .hl_id = kv_A(hl_msg, i).hl_id }));
    }
    return updated_msg;
  } else {
    return hl_msg;
  }
}