1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 08:43:26 +03:00

GH-605 First collect puts and flush them in one go.

This commit is contained in:
Tae Won Ha 2018-01-20 18:18:12 +01:00
parent 2d6073c466
commit 44772b42c3
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
10 changed files with 226 additions and 185 deletions

View File

@ -3,7 +3,7 @@
* See LICENSE
*/
@import Foundation;
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, NeoVimServerMsgId) {
@ -12,7 +12,6 @@ typedef NS_ENUM(NSInteger, NeoVimServerMsgId) {
NeoVimServerMsgIdResize,
NeoVimServerMsgIdClear,
NeoVimServerMsgIdEolClear,
NeoVimServerMsgIdSetPosition,
NeoVimServerMsgIdSetMenu,
NeoVimServerMsgIdBusyStart,
NeoVimServerMsgIdBusyStop,
@ -21,9 +20,6 @@ typedef NS_ENUM(NSInteger, NeoVimServerMsgId) {
NeoVimServerMsgIdModeChange,
NeoVimServerMsgIdSetScrollRegion,
NeoVimServerMsgIdScroll,
NeoVimServerMsgIdSetHighlightAttributes,
NeoVimServerMsgIdPut,
NeoVimServerMsgIdPutMarked,
NeoVimServerMsgIdUnmark,
NeoVimServerMsgIdBell,
NeoVimServerMsgIdVisualBell,

View File

@ -14,7 +14,6 @@
#define FileInfo CarbonFileInfo
#define Boolean CarbonBoolean
#import <nvim/vim.h>
#import <nvim/main.h>

View File

@ -10,6 +10,7 @@
#import "NvimServer.h"
#import "CocoaCategories.h"
#import "DataWrapper.h"
#import "SharedTypes.h"
// FileInfo and Boolean are #defined by Carbon and NeoVim:
// Since we don't need the Carbon versions of them, we rename
@ -28,29 +29,11 @@
#import <nvim/screen.h>
#import <nvim/edit.h>
#import <nvim/syntax.h>
#import <nvim/api/window.h>
#import <nvim/aucmd.h>
#import <nvim/quickfix.h>
#define pun_type(t, x) (*((t *) (&(x))))
// From NeoVimUiBridgeProtocol.h
typedef NS_ENUM(NSUInteger, FontTrait) {
FontTraitNone = 0,
FontTraitItalic = (1 << 0),
FontTraitBold = (1 << 1),
FontTraitUnderline = (1 << 2),
FontTraitUndercurl = (1 << 3)
};
typedef struct {
FontTrait fontTrait;
NSInteger foreground;
NSInteger background;
NSInteger special;
} CellAttributes;
static NSInteger _default_foreground = 0xFF000000;
static NSInteger _default_background = 0xFFFFFFFF;
@ -98,6 +81,8 @@ static bool _dirty = false;
static NSInteger _initialWidth = 30;
static NSInteger _initialHeight = 15;
static NSMutableArray <NSData *> *render_data;
#pragma mark Helper functions
static inline String vim_string_from(NSString *str) {
return (String) { .data = (char *) str.cstr, .size = str.clength };
@ -159,6 +144,16 @@ static HlAttrs HlAttrsFromAttrCode(int attr_code) {
return rgb_attrs;
}
static void add_to_render_data(RenderDataType type, NSData *data) {
NSMutableData *rData = [NSMutableData new];
[rData appendBytes:&type length:sizeof(RenderDataType)];
[rData appendData:data];
[render_data addObject:rData];
[rData release];
}
static int foreground_for(HlAttrs attrs) {
return attrs.reverse ? attrs.background: attrs.foreground;
}
@ -242,6 +237,8 @@ static void server_ui_scheduler(Event event, void *d) {
}
static void server_ui_main(UIBridgeData *bridge, UI *ui) {
render_data = [NSMutableArray new];
Loop loop;
loop_init(&loop, NULL);
@ -269,12 +266,28 @@ static void server_ui_main(UIBridgeData *bridge, UI *ui) {
xfree(_server_ui_data);
xfree(ui);
[render_data release];
}
#pragma mark NeoVim's UI callbacks
static void server_ui_flush(UI *ui __unused) {
@autoreleasepool {
if (render_data.count == 0) {
return;
}
[_neovim_server sendMessageWithId:NeoVimServerMsgIdFlush
data:[NSKeyedArchiver archivedDataWithRootObject:render_data]];
[render_data removeAllObjects];
}
}
static void server_ui_resize(UI *ui __unused, Integer width, Integer height) {
@autoreleasepool {
server_ui_flush(NULL);
NSInteger values[] = {width, height};
NSData *data = [[NSData alloc] initWithBytes:values length:(2 * sizeof(NSInteger))];
[_neovim_server sendMessageWithId:NeoVimServerMsgIdResize data:data];
@ -283,10 +296,18 @@ static void server_ui_resize(UI *ui __unused, Integer width, Integer height) {
}
static void server_ui_clear(UI *ui __unused) {
@autoreleasepool {
server_ui_flush(NULL);
}
[_neovim_server sendMessageWithId:NeoVimServerMsgIdClear];
}
static void server_ui_eol_clear(UI *ui __unused) {
@autoreleasepool {
server_ui_flush(NULL);
}
[_neovim_server sendMessageWithId:NeoVimServerMsgIdEolClear];
}
@ -303,7 +324,7 @@ static void server_ui_cursor_goto(UI *ui __unused, Integer row, Integer col) {
DLOG("%d:%d - %d:%d - %d:%d", values[0], values[1], values[2], values[3]);
NSData *data = [[NSData alloc] initWithBytes:values length:(4 * sizeof(NSInteger))];
[_neovim_server sendMessageWithId:NeoVimServerMsgIdSetPosition data:data];
add_to_render_data(RenderDataTypeGoto, data);
[data release];
}
}
@ -346,6 +367,8 @@ static void server_ui_set_scroll_region(UI *ui __unused, Integer top, Integer bo
Integer left, Integer right) {
@autoreleasepool {
server_ui_flush(NULL);
NSInteger values[] = {top, bot, left, right};
NSData *data = [[NSData alloc] initWithBytes:values length:(4 * sizeof(NSInteger))];
[_neovim_server sendMessageWithId:NeoVimServerMsgIdSetScrollRegion data:data];
@ -389,7 +412,7 @@ static void server_ui_highlight_set(UI *ui __unused, HlAttrs attrs) {
@autoreleasepool {
NSData *data = [[NSData alloc] initWithBytes:&cellAttrs length:sizeof(CellAttributes)];
[_neovim_server sendMessageWithId:NeoVimServerMsgIdSetHighlightAttributes data:data];
add_to_render_data(RenderDataTypeHighlight, data);
[data release];
}
}
@ -405,7 +428,7 @@ static void server_ui_put(UI *ui __unused, String str) {
if (_marked_text != nil && _marked_row == _put_row && _marked_column == _put_column) {
DLOG("putting marked text: '%s'", string.cstr);
[_neovim_server sendMessageWithId:NeoVimServerMsgIdPutMarked data:data];
add_to_render_data(RenderDataTypePutMarked, data);
} else if (_marked_text != nil
&& str.size == 0
@ -413,12 +436,12 @@ static void server_ui_put(UI *ui __unused, String str) {
&& _marked_column == _put_column - 1) {
DLOG("putting marked text cuz zero");
[_neovim_server sendMessageWithId:NeoVimServerMsgIdPutMarked data:data];
add_to_render_data(RenderDataTypePutMarked, data);
} else {
DLOG("putting non-marked text: '%s'", string.cstr);
[_neovim_server sendMessageWithId:NeoVimServerMsgIdPut data:data];
add_to_render_data(RenderDataTypePut, data);
}
@ -436,10 +459,6 @@ static void server_ui_visual_bell(UI *ui __unused) {
[_neovim_server sendMessageWithId:NeoVimServerMsgIdVisualBell];
}
static void server_ui_flush(UI *ui __unused) {
[_neovim_server sendMessageWithId:NeoVimServerMsgIdFlush];
}
static void server_ui_update_fg(UI *ui __unused, Integer fg) {
@autoreleasepool {
NSInteger value[1];

View File

@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1929B40A751BDA2882D4FC94 /* NvimViewObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B22A0CAD417EC3790F02 /* NvimViewObjects.swift */; };
1929B86897DAEFDBABAB1C14 /* NvimApiExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BBD7F88AE4F01E626691 /* NvimApiExtension.swift */; };
4B177886201220F300E32FF0 /* SharedTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 1929B4F32708E99C40A57020 /* SharedTypes.h */; settings = {ATTRIBUTES = (Public, ); }; };
4B2016EE1FD45EED0038528A /* NvimAutoCommandEvent.generated.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B2016EC1FD45EED0038528A /* NvimAutoCommandEvent.generated.m */; };
4B2016EF1FD45EED0038528A /* NvimAutoCommandEvent.generated.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B2016ED1FD45EED0038528A /* NvimAutoCommandEvent.generated.h */; settings = {ATTRIBUTES = (Public, ); }; };
4B8662E81FDC3F9F007F490D /* vimr.vim in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B8662E41FDC3D4F007F490D /* vimr.vim */; };
@ -34,7 +35,6 @@
4B90F0441FD2AFAE008A39E0 /* MMCoreTextView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90F0261FD2AFAD008A39E0 /* MMCoreTextView.h */; settings = {ATTRIBUTES = (Private, ); }; };
4B90F0451FD2AFAE008A39E0 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B90F0271FD2AFAD008A39E0 /* Logger.swift */; };
4B90F0461FD2AFAE008A39E0 /* Grid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B90F0281FD2AFAD008A39E0 /* Grid.swift */; };
4B90F0481FD2AFAE008A39E0 /* NvimUiBridgeProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90F02A1FD2AFAD008A39E0 /* NvimUiBridgeProtocol.m */; };
4B90F0491FD2AFAE008A39E0 /* CellAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B90F02B1FD2AFAD008A39E0 /* CellAttributes.swift */; };
4B90F04A1FD2AFAE008A39E0 /* UiClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90F02C1FD2AFAE008A39E0 /* UiClient.m */; };
4B90F0521FD2AFD3008A39E0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90F0511FD2AFD3008A39E0 /* main.m */; };
@ -96,6 +96,7 @@
/* Begin PBXFileReference section */
1929B22A0CAD417EC3790F02 /* NvimViewObjects.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NvimViewObjects.swift; sourceTree = "<group>"; };
1929B4F32708E99C40A57020 /* SharedTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedTypes.h; sourceTree = "<group>"; };
1929BBD7F88AE4F01E626691 /* NvimApiExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NvimApiExtension.swift; sourceTree = "<group>"; };
4B2016EC1FD45EED0038528A /* NvimAutoCommandEvent.generated.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NvimAutoCommandEvent.generated.m; sourceTree = "<group>"; };
4B2016ED1FD45EED0038528A /* NvimAutoCommandEvent.generated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NvimAutoCommandEvent.generated.h; sourceTree = "<group>"; };
@ -125,7 +126,6 @@
4B90F0261FD2AFAD008A39E0 /* MMCoreTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMCoreTextView.h; sourceTree = "<group>"; };
4B90F0271FD2AFAD008A39E0 /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
4B90F0281FD2AFAD008A39E0 /* Grid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Grid.swift; sourceTree = "<group>"; };
4B90F02A1FD2AFAD008A39E0 /* NvimUiBridgeProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NvimUiBridgeProtocol.m; sourceTree = "<group>"; };
4B90F02B1FD2AFAD008A39E0 /* CellAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellAttributes.swift; sourceTree = "<group>"; };
4B90F02C1FD2AFAE008A39E0 /* UiClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UiClient.m; sourceTree = "<group>"; };
4B90F04F1FD2AFD3008A39E0 /* NvimServer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = NvimServer; sourceTree = BUILT_PRODUCTS_DIR; };
@ -182,6 +182,7 @@
4B90F0501FD2AFD3008A39E0 /* NvimServer */,
4B90F0051FD2AF59008A39E0 /* Products */,
4B90F06F1FD2B9F1008A39E0 /* Frameworks */,
1929B4F32708E99C40A57020 /* SharedTypes.h */,
);
sourceTree = "<group>";
};
@ -215,7 +216,6 @@
4B2016EC1FD45EED0038528A /* NvimAutoCommandEvent.generated.m */,
4B90F01D1FD2AFAC008A39E0 /* NvimObjectsExtensions.swift */,
4B90F00F1FD2AFAC008A39E0 /* NvimUiBridgeProtocol.h */,
4B90F02A1FD2AFAD008A39E0 /* NvimUiBridgeProtocol.m */,
4B90F0101FD2AFAC008A39E0 /* NvimView.swift */,
4B90F01B1FD2AFAC008A39E0 /* NvimView+Api.swift */,
4B90F0141FD2AFAC008A39E0 /* NvimView+Dragging.swift */,
@ -273,6 +273,7 @@
4B90F0411FD2AFAE008A39E0 /* TextDrawer.h in Headers */,
4B90F0371FD2AFAE008A39E0 /* UiClient.h in Headers */,
4B90F02D1FD2AFAE008A39E0 /* NvimUiBridgeProtocol.h in Headers */,
4B177886201220F300E32FF0 /* SharedTypes.h in Headers */,
4B2016EF1FD45EED0038528A /* NvimAutoCommandEvent.generated.h in Headers */,
4B90F0441FD2AFAE008A39E0 /* MMCoreTextView.h in Headers */,
4B90F0781FD2BA7B008A39E0 /* Logger.h in Headers */,
@ -406,7 +407,6 @@
files = (
4B90F0381FD2AFAE008A39E0 /* ColorUtils.swift in Sources */,
4B90F03E1FD2AFAE008A39E0 /* MMCoreTextView.m in Sources */,
4B90F0481FD2AFAE008A39E0 /* NvimUiBridgeProtocol.m in Sources */,
4B90F03F1FD2AFAE008A39E0 /* NvimView+Draw.swift in Sources */,
4B90F02F1FD2AFAE008A39E0 /* NvimView+Resize.swift in Sources */,
4B90F0341FD2AFAE008A39E0 /* CocoaExtensions.swift in Sources */,

View File

@ -5,55 +5,10 @@
@import Foundation;
#import "SharedTypes.h"
#import "NvimAutoCommandEvent.generated.h"
// Keep in sync with ModeShape enum in cursor_shape.h.
typedef NS_ENUM(NSUInteger, CursorModeShape) {
CursorModeShapeNormal = 0,
CursorModeShapeVisual = 1,
CursorModeShapeInsert = 2,
CursorModeShapeReplace = 3,
CursorModeShapeCmdline = 4,
CursorModeShapeCmdlineInsert = 5,
CursorModeShapeCmdlineReplace = 6,
CursorModeShapeOperatorPending = 7,
CursorModeShapeVisualExclusive = 8,
CursorModeShapeOnCmdline = 9,
CursorModeShapeOnStatusLine = 10,
CursorModeShapeDraggingStatusLine = 11,
CursorModeShapeOnVerticalSepLine = 12,
CursorModeShapeDraggingVerticalSepLine = 13,
CursorModeShapeMore = 14,
CursorModeShapeMoreLastLine = 15,
CursorModeShapeShowingMatchingParen = 16,
CursorModeShapeTermFocus = 17,
CursorModeShapeCount = 18,
};
extern NSString * __nonnull cursorModeShapeName(CursorModeShape mode);
typedef NS_ENUM(NSUInteger, FontTrait) {
FontTraitNone = 0,
FontTraitItalic = (1 << 0),
FontTraitBold = (1 << 1),
FontTraitUnderline = (1 << 2),
FontTraitUndercurl = (1 << 3)
};
typedef struct {
FontTrait fontTrait;
NSInteger foreground;
NSInteger background;
NSInteger special;
} CellAttributes;
typedef struct {
NSInteger row;
NSInteger column;
} Position;
NS_ASSUME_NONNULL_BEGIN
@protocol NvimUiBridgeProtocol <NSObject>
@ -74,14 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)eolClear;
/**
* Move the current cursor to (row, column). This can mean two things:
* 1. NeoVim wants to put, ie draw, at (row, column) or
* 2. NeoVim wants to put the cursor at (row, column).
* In case of 1. NeoVim will put in subsequent call. In case of 2. NeoVim seems to flush twice in a row.
*/
- (void)gotoPosition:(Position)position textPosition:(Position)textPosition;
- (void)updateMenu;
- (void)busyStart;
- (void)busyStop;
@ -95,19 +42,12 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setScrollRegionToTop:(NSInteger)top bottom:(NSInteger)bottom left:(NSInteger)left right:(NSInteger)right;
- (void)scroll:(NSInteger)count;
- (void)highlightSet:(CellAttributes)attrs;
/**
* Draw string at the current cursor which was set by a previous cursorGotoRow:column callback.
*/
- (void)put:(NSString *)string;
- (void)putMarkedText:(NSString *)markedText;
- (void)unmarkRow:(NSInteger)row column:(NSInteger)column;
- (void)bell;
- (void)visualBell;
- (void)flush;
- (void)flush:(NSArray <NSData *> *)renderData;
/**
* Set the default foreground color.

View File

@ -42,20 +42,9 @@ extension NvimView {
}
}
public func gotoPosition(_ position: Position, textPosition: Position) {
gui.async {
self.bridgeLogger.debug(position)
self.markForRender(cellPosition: self.grid.position)
self.grid.goto(position)
self.eventsSubject.onNext(.cursor(textPosition))
}
}
public func modeChange(_ mode: CursorModeShape) {
gui.async {
self.bridgeLogger.debug(cursorModeShapeName(mode))
self.bridgeLogger.debug(self.cursorModeShapeName(mode))
self.mode = mode
}
}
@ -81,49 +70,6 @@ extension NvimView {
}
}
public func highlightSet(_ attrs: CellAttributes) {
gui.async {
self.bridgeLogger.debug(attrs)
self.grid.attrs = attrs
}
}
public func put(_ string: String) {
gui.async {
let curPos = self.grid.position
// self.bridgeLogger.debug("\(curPos) -> \(string)")
self.grid.put(string.precomposedStringWithCanonicalMapping)
if self.usesLigatures {
if string == " " {
self.markForRender(cellPosition: curPos)
} else {
self.markForRender(region: self.grid.regionOfWord(at: curPos))
}
} else {
self.markForRender(cellPosition: curPos)
}
}
}
public func putMarkedText(_ markedText: String) {
gui.async {
let curPos = self.grid.position
// self.bridgeLogger.debug("\(curPos) -> '\(markedText)'")
self.grid.putMarkedText(markedText)
self.markForRender(position: curPos)
// When the cursor is in the command line, then we need this...
self.markForRender(cellPosition: self.grid.nextCellPosition(curPos))
if markedText.count == 0 {
self.markForRender(position: self.grid.previousCellPosition(curPos))
}
}
}
public func unmarkRow(_ row: Int, column: Int) {
gui.async {
self.bridgeLogger.debug("\(row):\(column)")
@ -135,10 +81,49 @@ extension NvimView {
}
}
public func flush() {
public func flush(_ renderData: [Data]) {
gui.async {
self.bridgeLogger.hr()
renderData.forEach { data in
data.withUnsafeBytes { (pointer: UnsafePointer<RenderDataType>) in
let sizeOfType = MemoryLayout<RenderDataType>.size
let rawPointer = UnsafeRawPointer(pointer).advanced(by: sizeOfType);
let renderType = pointer[0]
switch renderType {
case .put:
guard let str = String(data: Data(bytes: rawPointer, count: data.count - sizeOfType),
encoding: .utf8)
else {
break
}
self.doPut(string: str)
case .putMarked:
guard let str = String(data: Data(bytes: rawPointer, count: data.count - sizeOfType),
encoding: .utf8)
else {
break
}
self.doPutMarked(markedText: str)
case .highlight:
let attr = rawPointer.load(as: CellAttributes.self)
self.doHighlightSet(attr)
case .goto:
let values = rawPointer.bindMemory(to: Int.self, capacity: 4)
self.doGotoPosition(Position(row: values[0], column: values[1]),
textPosition: Position(row: values[2], column: values[3]))
}
}
}
self.shouldDrawCursor = true
if self.usesLigatures {
@ -226,6 +211,51 @@ extension NvimView {
self.uiClient.forceQuit()
}
}
private func doPut(string: String) {
let curPos = self.grid.position
// self.bridgeLogger.debug("\(curPos) -> \(string)")
self.grid.put(string.precomposedStringWithCanonicalMapping)
if self.usesLigatures {
if string == " " {
self.markForRender(cellPosition: curPos)
} else {
self.markForRender(region: self.grid.regionOfWord(at: curPos))
}
} else {
self.markForRender(cellPosition: curPos)
}
}
private func doPutMarked(markedText: String) {
let curPos = self.grid.position
// self.bridgeLogger.debug("\(curPos) -> '\(markedText)'")
self.grid.putMarkedText(markedText)
self.markForRender(position: curPos)
// When the cursor is in the command line, then we need this...
self.markForRender(cellPosition: self.grid.nextCellPosition(curPos))
if markedText.count == 0 {
self.markForRender(position: self.grid.previousCellPosition(curPos))
}
}
private func doHighlightSet(_ attrs: CellAttributes) {
self.bridgeLogger.debug(attrs)
self.grid.attrs = attrs
}
private func doGotoPosition(_ position: Position, textPosition: Position) {
self.bridgeLogger.debug(position)
self.markForRender(cellPosition: self.grid.position)
self.grid.goto(position)
self.eventsSubject.onNext(.cursor(textPosition))
}
}
// MARK: - Simple
@ -368,6 +398,30 @@ extension NvimView {
self.updateTouchBarCurrentBuffer()
}
}
private func cursorModeShapeName(_ mode: CursorModeShape) -> String {
switch mode {
case .normal: return "Normal"
case .visual: return "Visual"
case .insert: return "Insert"
case .replace: return "Replace"
case .cmdline: return "Cmdline"
case .cmdlineInsert: return "CmdlineInsert"
case .cmdlineReplace: return "CmdlineReplace"
case .operatorPending: return "OperatorPending"
case .visualExclusive: return "VisualExclusive"
case .onCmdline: return "OnCmdline"
case .onStatusLine: return "OnStatusLine"
case .draggingStatusLine: return "DraggingStatusLine"
case .onVerticalSepLine: return "OnVerticalSepLine"
case .draggingVerticalSepLine: return "DraggingVerticalSepLine"
case .more: return "More"
case .moreLastLine: return "MoreLastLine"
case .showingMatchingParen: return "ShowingMatchingParen"
case .termFocus: return "TermFocus"
case .count: return "Count"
}
}
}
private let gui = DispatchQueue.main

View File

@ -21,3 +21,4 @@ FOUNDATION_EXPORT const unsigned char NvimViewVersionString[];
#import <NvimView/TextDrawer.h>
#import <NvimView/UiClient.h>
#import <NvimView/NvimAutoCommandEvent.generated.h>
#import <NvimView/SharedTypes.h>

View File

@ -14,8 +14,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface UiClient : NSObject
@property (nonatomic) bool useInteractiveZsh;
@property (nonatomic) NSURL *cwd;
@property (nonatomic, nullable) NSArray<NSString *> *nvimArgs;
@property (nonatomic, copy) NSURL *cwd;
@property (nonatomic, nullable, retain) NSArray<NSString *> *nvimArgs;
@property (readonly) bool neoVimIsQuitting;
@property (nonatomic, weak) id <NvimUiBridgeProtocol> bridge;

View File

@ -23,7 +23,6 @@ static type *data_to_ ## type ## _array(NSData *data, NSUInteger count) { \
data_to_array(NSInteger)
data_to_array(bool)
data_to_array(CellAttributes)
static void log_cfmachport_error(SInt32 err, NeoVimAgentMsgId msgid, NSData *inputData) {
switch (err) {
@ -444,13 +443,6 @@ static CFDataRef local_server_callback(CFMessagePortRef local __unused, SInt32 m
[_bridge eolClear];
return;
case NeoVimServerMsgIdSetPosition: {
NSInteger *values = data_to_NSInteger_array(data, 4);
[_bridge gotoPosition:(Position) {.row = values[0], .column = values[1]}
textPosition:(Position) {.row = values[2], .column = values[3]}];
return;
}
case NeoVimServerMsgIdSetMenu:
[_bridge updateMenu];
return;
@ -489,25 +481,6 @@ static CFDataRef local_server_callback(CFMessagePortRef local __unused, SInt32 m
return;
}
case NeoVimServerMsgIdSetHighlightAttributes: {
CellAttributes *values = data_to_CellAttributes_array(data, 1);
[_bridge highlightSet:values[0]];
return;
}
case NeoVimServerMsgIdPut:
case NeoVimServerMsgIdPutMarked: {
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (msgid == NeoVimServerMsgIdPut) {
[_bridge put:string];
} else {
[_bridge putMarkedText:string];
}
return;
}
case NeoVimServerMsgIdUnmark: {
NSInteger *values = data_to_NSInteger_array(data, 2);
[_bridge unmarkRow:values[0] column:values[1]];
@ -523,7 +496,9 @@ static CFDataRef local_server_callback(CFMessagePortRef local __unused, SInt32 m
return;
case NeoVimServerMsgIdFlush: {
[_bridge flush];
NSArray <NSData *> *renderData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
[_bridge flush:renderData];
return;
}

57
NvimView/SharedTypes.h Normal file
View File

@ -0,0 +1,57 @@
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, FontTrait) {
FontTraitNone = 0,
FontTraitItalic = (1 << 0),
FontTraitBold = (1 << 1),
FontTraitUnderline = (1 << 2),
FontTraitUndercurl = (1 << 3)
};
typedef struct {
FontTrait fontTrait;
NSInteger foreground;
NSInteger background;
NSInteger special;
} CellAttributes;
// Keep in sync with ModeShape enum in cursor_shape.h.
typedef NS_ENUM(NSUInteger, CursorModeShape) {
CursorModeShapeNormal = 0,
CursorModeShapeVisual = 1,
CursorModeShapeInsert = 2,
CursorModeShapeReplace = 3,
CursorModeShapeCmdline = 4,
CursorModeShapeCmdlineInsert = 5,
CursorModeShapeCmdlineReplace = 6,
CursorModeShapeOperatorPending = 7,
CursorModeShapeVisualExclusive = 8,
CursorModeShapeOnCmdline = 9,
CursorModeShapeOnStatusLine = 10,
CursorModeShapeDraggingStatusLine = 11,
CursorModeShapeOnVerticalSepLine = 12,
CursorModeShapeDraggingVerticalSepLine = 13,
CursorModeShapeMore = 14,
CursorModeShapeMoreLastLine = 15,
CursorModeShapeShowingMatchingParen = 16,
CursorModeShapeTermFocus = 17,
CursorModeShapeCount = 18,
};
typedef struct {
NSInteger row;
NSInteger column;
} Position;
typedef NS_ENUM(NSInteger, RenderDataType) {
RenderDataTypePut,
RenderDataTypePutMarked,
RenderDataTypeGoto,
RenderDataTypeHighlight
};