|
| 1 | +#include <assert.h> |
| 2 | +#include <inttypes.h> |
| 3 | +#include <stdbool.h> |
| 4 | +#include <stddef.h> |
| 5 | +#include <stdint.h> |
| 6 | +#include <stdlib.h> |
| 7 | +#include <string.h> |
| 8 | + |
| 9 | +#include "klib/kvec.h" |
| 10 | +#include "nvim/api/events.h" |
| 11 | +#include "nvim/api/private/converter.h" |
| 12 | +#include "nvim/api/private/defs.h" |
| 13 | +#include "nvim/api/private/helpers.h" |
| 14 | +#include "nvim/api/private/validate.h" |
| 15 | +#include "nvim/api/ui.h" |
| 16 | +#include "nvim/assert_defs.h" |
| 17 | +#include "nvim/autocmd.h" |
| 18 | +#include "nvim/autocmd_defs.h" |
| 19 | +#include "nvim/channel.h" |
| 20 | +#include "nvim/channel_defs.h" |
| 21 | +#include "nvim/eval.h" |
| 22 | +#include "nvim/globals.h" |
| 23 | +#include "nvim/main.h" |
| 24 | +#include "nvim/map_defs.h" |
| 25 | +#include "nvim/memory.h" |
| 26 | +#include "nvim/memory_defs.h" |
| 27 | +#include "nvim/msgpack_rpc/channel.h" |
| 28 | +#include "nvim/msgpack_rpc/channel_defs.h" |
| 29 | +#include "nvim/msgpack_rpc/packer.h" |
| 30 | +#include "nvim/msgpack_rpc/packer_defs.h" |
| 31 | +#include "nvim/types_defs.h" |
| 32 | +#include "nvim/ui.h" |
| 33 | + |
| 34 | +/// Emitted on the client channel if an async API request responds with an error. |
| 35 | +/// |
| 36 | +/// @param channel_id |
| 37 | +/// @param type Error type id as defined by `api_info().error_types`. |
| 38 | +/// @param msg Error message. |
| 39 | +void nvim_error_event(uint64_t channel_id, Integer type, String msg) |
| 40 | + FUNC_API_REMOTE_ONLY |
| 41 | +{ |
| 42 | + // TODO(bfredl): consider printing message to user, as will be relevant |
| 43 | + // if we fork nvim processes as async workers |
| 44 | + ELOG("async error on channel %" PRId64 ": %s", channel_id, msg.size ? msg.data : ""); |
| 45 | +} |
| 46 | + |
| 47 | +/// Emitted by the TUI client to signal when a host-terminal event occurred. |
| 48 | +/// |
| 49 | +/// Supports these events: |
| 50 | +/// |
| 51 | +/// - "termresponse": The host-terminal sent a DA1, OSC, DCS, or APC response sequence to Nvim. |
| 52 | +/// The payload is the received response. Sets |v:termresponse| and fires |
| 53 | +/// |TermResponse|. |
| 54 | +/// |
| 55 | +/// @param channel_id |
| 56 | +/// @param event Event name |
| 57 | +/// @param value Event payload |
| 58 | +/// @param[out] err Error details, if any. |
| 59 | +void nvim_ui_term_event(uint64_t channel_id, String event, Object value, Error *err) |
| 60 | + FUNC_API_SINCE(12) FUNC_API_REMOTE_ONLY |
| 61 | +{ |
| 62 | + if (strequal("termresponse", event.data)) { |
| 63 | + if (value.type != kObjectTypeString) { |
| 64 | + api_set_error(err, kErrorTypeValidation, "termresponse must be a string"); |
| 65 | + return; |
| 66 | + } |
| 67 | + |
| 68 | + const String termresponse = value.data.string; |
| 69 | + set_vim_var_string(VV_TERMRESPONSE, termresponse.data, (ptrdiff_t)termresponse.size); |
| 70 | + |
| 71 | + MAXSIZE_TEMP_DICT(data, 1); |
| 72 | + PUT_C(data, "sequence", value); |
| 73 | + apply_autocmds_group(EVENT_TERMRESPONSE, NULL, NULL, true, AUGROUP_ALL, NULL, NULL, |
| 74 | + &DICT_OBJ(data)); |
| 75 | + } |
| 76 | +} |
0 commit comments