mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-27 14:14:19 +03:00
Send mode_info_set messages from nvim to UiBridge
This commit is contained in:
parent
e501e87063
commit
d8c6ad2b5a
@ -31,6 +31,7 @@ typedef CF_ENUM(NSInteger, NvimServerMsgId) {
|
|||||||
NvimServerMsgIdBusyStart,
|
NvimServerMsgIdBusyStart,
|
||||||
NvimServerMsgIdBusyStop,
|
NvimServerMsgIdBusyStop,
|
||||||
NvimServerMsgIdModeChange,
|
NvimServerMsgIdModeChange,
|
||||||
|
NvimServerMsgIdModeInfoSet,
|
||||||
NvimServerMsgIdBell,
|
NvimServerMsgIdBell,
|
||||||
NvimServerMsgIdVisualBell,
|
NvimServerMsgIdVisualBell,
|
||||||
NvimServerMsgIdFlush,
|
NvimServerMsgIdFlush,
|
||||||
|
@ -37,6 +37,7 @@ static msgpack_sbuffer flush_sbuffer;
|
|||||||
static msgpack_packer flush_packer;
|
static msgpack_packer flush_packer;
|
||||||
|
|
||||||
static void pack_flush_data(RenderDataType type, pack_block body);
|
static void pack_flush_data(RenderDataType type, pack_block body);
|
||||||
|
static void pack_mode_info_dictionary(msgpack_packer *packer, Dictionary dict);
|
||||||
static void send_cwd(void);
|
static void send_cwd(void);
|
||||||
static void send_dirty_status(void);
|
static void send_dirty_status(void);
|
||||||
static void send_colorscheme(void);
|
static void send_colorscheme(void);
|
||||||
@ -107,9 +108,24 @@ static void server_ui_busy_stop(UI *ui __unused) {
|
|||||||
|
|
||||||
static void server_ui_mode_info_set(
|
static void server_ui_mode_info_set(
|
||||||
UI *ui __unused,
|
UI *ui __unused,
|
||||||
Boolean enabled __unused,
|
Boolean enabled,
|
||||||
Array cursor_styles __unused
|
Array cursor_styles
|
||||||
) {}
|
) {
|
||||||
|
send_msg_packing(NvimServerMsgIdModeInfoSet, ^(msgpack_packer *packer) {
|
||||||
|
msgpack_pack_array(packer, 2);
|
||||||
|
msgpack_pack_bool(packer, enabled);
|
||||||
|
msgpack_pack_array(packer, cursor_styles.size);
|
||||||
|
for (size_t i = 0; i < cursor_styles.size; ++i) {
|
||||||
|
Object item = cursor_styles.items[i];
|
||||||
|
if (item.type == kObjectTypeDictionary) {
|
||||||
|
pack_mode_info_dictionary(packer, item.data.dictionary);
|
||||||
|
} else {
|
||||||
|
// this should never happen, but write nil to match the given array size
|
||||||
|
msgpack_pack_nil(packer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static void server_ui_mode_change(UI *ui __unused, String mode_str __unused, Integer mode) {
|
static void server_ui_mode_change(UI *ui __unused, String mode_str __unused, Integer mode) {
|
||||||
send_msg_packing(NvimServerMsgIdModeChange, ^(msgpack_packer *packer) {
|
send_msg_packing(NvimServerMsgIdModeChange, ^(msgpack_packer *packer) {
|
||||||
@ -368,6 +384,34 @@ static void pack_flush_data(RenderDataType type, pack_block body) {
|
|||||||
body(&flush_packer);
|
body(&flush_packer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Small utility to pack an nvim Dictionary into a msgpack_map for mode_info_set
|
||||||
|
// BEWARE: This is by no means a generic Dict -> map packer, as only String and
|
||||||
|
// Integer values are supported for now.
|
||||||
|
static void pack_mode_info_dictionary(
|
||||||
|
msgpack_packer *packer,
|
||||||
|
Dictionary dict
|
||||||
|
) {
|
||||||
|
msgpack_pack_map(packer, dict.size);
|
||||||
|
for (size_t i = 0; i < dict.size; ++i) {
|
||||||
|
String key = dict.items[i].key;
|
||||||
|
Object value = dict.items[i].value;
|
||||||
|
msgpack_pack_str(packer, key.size);
|
||||||
|
msgpack_pack_str_body(packer, key.data, key.size);
|
||||||
|
switch (value.type) {
|
||||||
|
case kObjectTypeInteger:
|
||||||
|
msgpack_pack_int64(packer, value.data.integer);
|
||||||
|
break;
|
||||||
|
case kObjectTypeString:
|
||||||
|
msgpack_pack_str(packer, value.data.string.size);
|
||||||
|
msgpack_pack_str_body(packer, value.data.string.data, value.data.string.size);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
msgpack_pack_nil(packer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void send_dirty_status() {
|
static void send_dirty_status() {
|
||||||
const bool new_dirty_status = has_dirty_docs();
|
const bool new_dirty_status = has_dirty_docs();
|
||||||
if (are_buffers_dirty == new_dirty_status) {return;}
|
if (are_buffers_dirty == new_dirty_status) {return;}
|
||||||
|
@ -62,6 +62,10 @@ extension NvimView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final func modeInfoSet(_ value: MessagePackValue) {
|
||||||
|
self.bridgeLogger.trace("modeInfoSet: \(value)")
|
||||||
|
}
|
||||||
|
|
||||||
final func flush(_ renderData: [MessagePackValue]) {
|
final func flush(_ renderData: [MessagePackValue]) {
|
||||||
self.bridgeLogger.trace("# of render data: \(renderData.count)")
|
self.bridgeLogger.trace("# of render data: \(renderData.count)")
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ typedef CF_ENUM(NSInteger, NvimServerMsgId) {
|
|||||||
NvimServerMsgIdBusyStart,
|
NvimServerMsgIdBusyStart,
|
||||||
NvimServerMsgIdBusyStop,
|
NvimServerMsgIdBusyStop,
|
||||||
NvimServerMsgIdModeChange,
|
NvimServerMsgIdModeChange,
|
||||||
|
NvimServerMsgIdModeInfoSet,
|
||||||
NvimServerMsgIdBell,
|
NvimServerMsgIdBell,
|
||||||
NvimServerMsgIdVisualBell,
|
NvimServerMsgIdVisualBell,
|
||||||
NvimServerMsgIdFlush,
|
NvimServerMsgIdFlush,
|
||||||
|
@ -14,6 +14,7 @@ protocol UiBridgeConsumer: class {
|
|||||||
func resize(_ value: MessagePackValue)
|
func resize(_ value: MessagePackValue)
|
||||||
func clear()
|
func clear()
|
||||||
func modeChange(_ value: MessagePackValue)
|
func modeChange(_ value: MessagePackValue)
|
||||||
|
func modeInfoSet(_ value: MessagePackValue)
|
||||||
func flush(_ renderData: [MessagePackValue])
|
func flush(_ renderData: [MessagePackValue])
|
||||||
func setTitle(with value: MessagePackValue)
|
func setTitle(with value: MessagePackValue)
|
||||||
func stop()
|
func stop()
|
||||||
@ -186,6 +187,10 @@ class UiBridge {
|
|||||||
guard let v = MessagePackUtils.value(from: data) else { return }
|
guard let v = MessagePackUtils.value(from: data) else { return }
|
||||||
self.consumer?.modeChange(v)
|
self.consumer?.modeChange(v)
|
||||||
|
|
||||||
|
case .modeInfoSet:
|
||||||
|
guard let v = MessagePackUtils.value(from: data) else { return }
|
||||||
|
self.consumer?.modeInfoSet(v)
|
||||||
|
|
||||||
case .bell:
|
case .bell:
|
||||||
self.consumer?.bell()
|
self.consumer?.bell()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user