Beispiel #1
0
void remote_ui_init(void)
{
  connected_uis = pmap_new(uint64_t)();
  // Add handler for "attach_ui"
  String method = cstr_as_string("ui_attach");
  MsgpackRpcRequestHandler handler = {.fn = remote_ui_attach, .defer = false};
  msgpack_rpc_add_method_handler(method, handler);
  method = cstr_as_string("ui_detach");
  handler.fn = remote_ui_detach;
  msgpack_rpc_add_method_handler(method, handler);
  method = cstr_as_string("ui_try_resize");
  handler.fn = remote_ui_try_resize;
  msgpack_rpc_add_method_handler(method, handler);
}

void remote_ui_disconnect(uint64_t channel_id)
{
  UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
  if (!ui) {
    return;
  }
  UIData *data = ui->data;
  // destroy pending screen updates
  api_free_array(data->buffer);
  pmap_del(uint64_t)(connected_uis, channel_id);
  xfree(ui->data);
  ui_detach(ui);
  xfree(ui);
}
Beispiel #2
0
Object provider_call(char *method, Array args)
{
  Feature *f = pmap_get(cstr_t)(registered_providers, method);

  if (!f || !channel_exists(f->channel_id)) {
    char buf[256];
    snprintf(buf,
             sizeof(buf),
             "Provider for method \"%s\" is not available",
             method);
    vim_report_error(cstr_as_string(buf));
    api_free_array(args);
    return NIL;
  }

  Error err = ERROR_INIT;
  Object result = NIL = channel_send_call(f->channel_id, method, args, &err);

  if (err.set) {
    vim_report_error(cstr_as_string(err.msg));
    api_free_object(result);
    return NIL;
  }
  
  return result;
}
Beispiel #3
0
void list_lua_version(void)
{
  typval_T luaver_tv;
  typval_T arg = { .v_type = VAR_UNKNOWN };  // No args.
  char *luaver_expr = "((jit and jit.version) and jit.version or _VERSION)";
  executor_eval_lua(cstr_as_string(luaver_expr), &arg, &luaver_tv);
  assert(luaver_tv.v_type == VAR_STRING);
  MSG(luaver_tv.vval.v_string);
  xfree(luaver_tv.vval.v_string);
}
Beispiel #4
0
void ui_set_ext_option(UI *ui, UIExtension ext, bool active)
{
  if (ext < kUIGlobalCount) {
    ui_refresh();
    return;
  }
  if (ui->option_set) {
    ui->option_set(ui, cstr_as_string((char *)ui_ext_names[ext]),
                   BOOLEAN_OBJ(active));
  }
}
Beispiel #5
0
void ui_refresh(void)
{
  if (!ui_active()) {
    return;
  }

  if (updating_screen) {
    ui_schedule_refresh();
    return;
  }

  int width = INT_MAX, height = INT_MAX;
  bool ext_widgets[kUIExtCount];
  for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
    ext_widgets[i] = true;
  }

  for (size_t i = 0; i < ui_count; i++) {
    UI *ui = uis[i];
    width = MIN(ui->width, width);
    height = MIN(ui->height, height);
    for (UIExtension j = 0; (int)j < kUIExtCount; j++) {
      ext_widgets[j] &= ui->ui_ext[j];
    }
  }

  cursor_row = cursor_col = 0;
  pending_cursor_update = true;

  for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
    ui_ext[i] = ext_widgets[i];
    if (i < kUIGlobalCount) {
      ui_call_option_set(cstr_as_string((char *)ui_ext_names[i]),
                         BOOLEAN_OBJ(ext_widgets[i]));
    }
  }

  ui_default_colors_set();

  int save_p_lz = p_lz;
  p_lz = false;  // convince redrawing() to return true ...
  screen_resize(width, height);
  p_lz = save_p_lz;

  if (ext_widgets[kUIMessages]) {
    p_ch = 0;
    command_height();
  }
  ui_mode_info_set();
  pending_mode_update = true;
  ui_cursor_shape();
}
Beispiel #6
0
/// Replace any terminal codes with the internal representation
///
/// @see replace_termcodes
/// @see cpoptions
String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
                              Boolean special)
{
  if (str.size == 0) {
    // Empty string
    return str;
  }

  char *ptr = NULL;
  replace_termcodes((char_u *)str.data, (char_u **)&ptr,
                                            from_part, do_lt, special);
  return cstr_as_string(ptr);
}
Beispiel #7
0
void ui_set_ext_option(UI *ui, UIExtension ext, bool active)
{
  if (ext < kUIGlobalCount) {
    ui_refresh();
    return;
  }
  if (ui->option_set && (ui_ext_names[ext][0] != '_' || active)) {
    ui->option_set(ui, cstr_as_string((char *)ui_ext_names[ext]),
                   BOOLEAN_OBJ(active));
  }
  if (ext == kUITermColors) {
    ui_default_colors_set();
  }
}
Beispiel #8
0
/// Replaces any terminal codes with the internal representation
///
/// @see replace_termcodes
/// @see cpoptions
String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
                              Boolean special)
{
  if (str.size == 0) {
    // Empty string
    return str;
  }

  char *ptr = NULL;
  // Set 'cpoptions' the way we want it.
  //    FLAG_CPO_BSLASH  set - backslashes are *not* treated specially
  //    FLAG_CPO_KEYCODE set - keycodes are *not* reverse-engineered
  //    FLAG_CPO_SPECI unset - <Key> sequences *are* interpreted
  //  The third from end parameter of replace_termcodes() is true so that the
  //  <lt> sequence is recognised - needed for a real backslash.
  replace_termcodes((char_u *)str.data, str.size, (char_u **)&ptr,
                    from_part, do_lt, special, CPO_TO_CPO_FLAGS);
  return cstr_as_string(ptr);
}
Beispiel #9
0
Datei: ui.c Projekt: SLieng/nvm
void ui_refresh(void)
{
  if (!ui_active()) {
    return;
  }

  if (updating_screen) {
    ui_schedule_refresh();
    return;
  }

  int width = INT_MAX, height = INT_MAX;
  bool ext_widgets[kUIExtCount];
  for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
    ext_widgets[i] = true;
  }

  for (size_t i = 0; i < ui_count; i++) {
    UI *ui = uis[i];
    width = MIN(ui->width, width);
    height = MIN(ui->height, height);
    for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
      ext_widgets[i] &= ui->ui_ext[i];
    }
  }

  row = col = 0;

  int save_p_lz = p_lz;
  p_lz = false;  // convince redrawing() to return true ...
  screen_resize(width, height);
  p_lz = save_p_lz;

  for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
    ui_ext[i] = ext_widgets[i];
    ui_call_option_set(cstr_as_string((char *)ui_ext_names[i]),
                       BOOLEAN_OBJ(ext_widgets[i]));
  }
  ui_mode_info_set();
  old_mode_idx = -1;
  ui_cursor_shape();
  current_attr_code = -1;
}
Beispiel #10
0
void ui_flush(void)
{
  cmdline_ui_flush();
  if (pending_cursor_update) {
    ui_call_grid_cursor_goto(1, row, col);
    pending_cursor_update = false;
  }
  if (pending_mode_info_update) {
    Array style = mode_style_array();
    bool enabled = (*p_guicursor != NUL);
    ui_call_mode_info_set(enabled, style);
    api_free_array(style);
    pending_mode_info_update = false;
  }
  if (pending_mode_update) {
    char *full_name = shape_table[mode_idx].full_name;
    ui_call_mode_change(cstr_as_string(full_name), mode_idx);
    pending_mode_update = false;
  }
  ui_call_flush();
}