2016-06-04 21:45:29 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public class NeoVim {
|
2016-06-05 10:49:14 +03:00
|
|
|
|
|
|
|
enum UiEvent {
|
|
|
|
case MoveCursor(position: Position)
|
|
|
|
case Put(string: String)
|
|
|
|
case Resize(size: Size)
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Size {
|
|
|
|
let rows: Int32
|
|
|
|
let columns: Int32
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Position {
|
|
|
|
let row: Int32
|
|
|
|
let column: Int32
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ColorKind {
|
|
|
|
case Foreground
|
|
|
|
case Background
|
|
|
|
case Special
|
|
|
|
}
|
2016-06-04 21:45:29 +03:00
|
|
|
|
|
|
|
private static let qXpcName = "com.qvacua.nvox.xpc"
|
|
|
|
|
|
|
|
private let xpcConnection: NSXPCConnection = NSXPCConnection(serviceName: NeoVim.qXpcName)
|
|
|
|
private let xpc: NeoVimXpc
|
2016-06-05 10:49:14 +03:00
|
|
|
|
|
|
|
private let neoVimUiBridge: NeoVimUiBridge
|
|
|
|
|
|
|
|
public let view: NeoVimView
|
2016-06-04 21:45:29 +03:00
|
|
|
|
|
|
|
public init() {
|
2016-06-05 10:49:14 +03:00
|
|
|
let neoVimUiBridge = NeoVimUiBridge()
|
|
|
|
self.neoVimUiBridge = neoVimUiBridge
|
|
|
|
|
2016-06-04 21:45:29 +03:00
|
|
|
self.xpcConnection.remoteObjectInterface = NSXPCInterface(withProtocol: NeoVimXpc.self)
|
|
|
|
|
2016-06-05 10:49:14 +03:00
|
|
|
self.xpcConnection.exportedInterface = NSXPCInterface(withProtocol: NeoVimUiBridgeProtocol.self)
|
|
|
|
self.xpcConnection.exportedObject = self.neoVimUiBridge
|
2016-06-04 21:45:29 +03:00
|
|
|
|
|
|
|
self.xpcConnection.resume()
|
|
|
|
|
|
|
|
self.xpc = self.xpcConnection.remoteObjectProxy as! NeoVimXpc
|
2016-06-06 19:25:03 +03:00
|
|
|
self.view = NeoVimView(uiEventObservable: neoVimUiBridge.observable, xpc: self.xpc)
|
2016-06-04 21:45:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
self.xpcConnection.invalidate()
|
|
|
|
}
|
|
|
|
|
2016-06-05 10:49:14 +03:00
|
|
|
public func vimInput(input: String) {
|
|
|
|
self.xpc.vimInput(input)
|
2016-06-04 21:45:29 +03:00
|
|
|
}
|
|
|
|
}
|