1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-23 19:21:53 +03:00

Add HlAttrs counterpart in the main app

This commit is contained in:
Tae Won Ha 2016-06-04 19:49:39 +02:00
parent fd90f4be0b
commit 3a9d6908c3
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 24 additions and 11 deletions

View File

@ -3,10 +3,11 @@
* See LICENSE
*/
#import <objc/message.h>
#import "NeoVimXpcImpl.h"
#import "NeoVimUi.h"
#import <objc/message.h>
/**
* FileInfo and Boolean are #defined by Carbon and NeoVim: Since we don't need the Carbon versions of them, we rename
@ -27,6 +28,7 @@ void (*objc_msgSend_string)(id, SEL, NSString *) = (void *) objc_msgSend;
void (*objc_msgSend_int)(id, SEL, int) = (void *) objc_msgSend;
void (*objc_msgSend_2_int)(id, SEL, int, int) = (void *) objc_msgSend;
void (*objc_msgSend_4_int)(id, SEL, int, int, int, int) = (void *) objc_msgSend;
void (*objc_msgSend_hlattrs)(id, SEL, HighlightAttributes) = (void *) objc_msgSend;
// we declare nvim_main because it's not declared in any header files of neovim
extern int nvim_main(int argc, char **argv);
@ -36,14 +38,18 @@ static NSCondition *uiLaunchCondition;
static id <NeoVimUi> neoVimOsxUi;
static NSString *string_from_bytes(uint8_t *str, size_t len) {
static inline NSString *string_from_bytes(uint8_t *str, size_t len) {
return [[NSString alloc] initWithBytes:str length:len encoding:NSUTF8StringEncoding];
}
static NSString *string_from_cstr(char *cstr) {
static inline NSString *string_from_cstr(char *cstr) {
return [[NSString alloc] initWithCString:cstr encoding:NSUTF8StringEncoding];
}
static inline String nvim_string_from_string(NSString *str) {
return (String) {.data=(char *) str.UTF8String, .size=[str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]};
}
typedef struct {
UIBridgeData *bridge;
Loop *loop;
@ -52,7 +58,7 @@ typedef struct {
bool stop;
bool cont_received;
// dunno whether we need this: copied from tui.c
// FIXME: dunno whether we need this: copied from tui.c
SignalWatcher cont_handle;
} OsxXpcUiData;
@ -165,7 +171,7 @@ static void xpc_ui_scroll(UI *ui, int count) {
}
static void xpc_ui_highlight_set(UI *ui, HlAttrs attrs) {
objc_msgSend_no_arg(neoVimOsxUi, @selector(highlightSet));
objc_msgSend_hlattrs(neoVimOsxUi, @selector(highlightSet:), (*(HighlightAttributes *)(&attrs)));
}
static void xpc_ui_put(UI *ui, uint8_t *str, size_t len) {
@ -298,16 +304,16 @@ void custom_ui_start(void) {
- (void)doSth {
NSString *str = @"i";
NSLog(@"entering input");
vim_input((String) {.data=(char *) str.UTF8String, .size=[str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]});
vim_input(nvim_string_from_string(str));
str = @"test input";
NSLog(@"entering some text");
vim_input((String) {.data=(char *) str.UTF8String, .size=[str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]});
vim_input(nvim_string_from_string(str));
unichar esc = 27; // = 001B
str = [NSString stringWithCharacters:&esc length:1];
NSLog(@"entering normal");
vim_input((String) {.data=(char *) str.UTF8String, .size=[str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]});
vim_input(nvim_string_from_string(str));
}
@end

View File

@ -4,6 +4,7 @@
*/
#import <Foundation/Foundation.h>
#import "NeoVimXpcImpl.h"
#import "NeoVimUi.h"

View File

@ -5,6 +5,12 @@
#import <Foundation/Foundation.h>
// TODO: keep in sync with HlAttrs struct in ui.h
typedef struct {
bool bold, underline, undercurl, italic, reverse;
int foreground, background, special;
} HighlightAttributes;
@protocol NeoVimUi
- (void)resize:(int)rows columns:(int)columns;
@ -19,7 +25,7 @@
- (void)modeChange:(int)mode;
- (void)setScrollRegion:(int)top bottom:(int)bottom left:(int)left right:(int)right;
- (void)scroll:(int)count;
- (void)highlightSet;
- (void)highlightSet:(HighlightAttributes)attrs;
- (void)put:(NSString *)string;
- (void)bell;
- (void)visualBell;

View File

@ -55,8 +55,8 @@ class NeoVimUiImpl: NSObject, NeoVimUi {
print("### count: \(count)")
}
func highlightSet() {
print("### highlight set");
func highlightSet(attrs: HighlightAttributes) {
print("### highlight set: \(attrs)");
}
func put(str: String) {