mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-28 08:13:17 +03:00
swiftformat NvimView
This commit is contained in:
parent
f9be41f220
commit
ed8aeee987
@ -39,7 +39,8 @@ final class KeyUtils {
|
||||
}
|
||||
|
||||
static func isHalfWidth(char: Character) -> Bool {
|
||||
// https://stackoverflow.com/questions/13505075/analyzing-full-width-or-half-width-character-in-java?noredirect=1&lq=1 // swiftlint:disable:this all
|
||||
// https://stackoverflow.com/questions/13505075/analyzing-full-width-or-half-width-character-in-java?noredirect=1&lq=1
|
||||
// // swiftlint:disable:this all
|
||||
switch char {
|
||||
case "\u{00}"..."\u{FF}", "\u{FF61}"..."\u{FFDC}", "\u{FFE8}"..."\u{FFEE}":
|
||||
return true
|
||||
|
@ -18,7 +18,7 @@ enum MessagePackUtils {
|
||||
static func value<T>(from data: Data?, conversion: (MessagePackValue) -> T?) -> T? {
|
||||
guard let d = data else { return nil }
|
||||
|
||||
do { return conversion(try unpack(d).value) }
|
||||
do { return try conversion(unpack(d).value) }
|
||||
catch { return nil }
|
||||
}
|
||||
|
||||
|
@ -39,17 +39,17 @@ public extension NvimView {
|
||||
|
||||
func hasDirtyBuffers() -> Single<Bool> {
|
||||
self.api
|
||||
.execLua(code: """
|
||||
return vim.fn.getbufinfo({"bufmodified": v:true})
|
||||
""", args: [])
|
||||
.map { result -> Bool in
|
||||
guard let info_array = result.arrayValue
|
||||
else {
|
||||
throw RxNeovimApi.Error
|
||||
.exception(message: "Could not convert values into info array.")
|
||||
.execLua(code: """
|
||||
return vim.fn.getbufinfo({"bufmodified": v:true})
|
||||
""", args: [])
|
||||
.map { result -> Bool in
|
||||
guard let info_array = result.arrayValue
|
||||
else {
|
||||
throw RxNeovimApi.Error
|
||||
.exception(message: "Could not convert values into info array.")
|
||||
}
|
||||
return info_array.count > 0
|
||||
}
|
||||
return info_array.count > 0
|
||||
}
|
||||
}
|
||||
|
||||
func waitTillNvimExits() {
|
||||
@ -207,8 +207,8 @@ public extension NvimView {
|
||||
|
||||
func vimOutput(of command: String) -> Single<String> {
|
||||
self.api
|
||||
.exec2(src: command, opts:["output": true])
|
||||
.map({
|
||||
.exec2(src: command, opts: ["output": true])
|
||||
.map {
|
||||
retval in
|
||||
guard let output_value = retval["output"] ?? retval["output"],
|
||||
let output = output_value.stringValue
|
||||
@ -217,7 +217,7 @@ public extension NvimView {
|
||||
.exception(message: "Could not convert values to output.")
|
||||
}
|
||||
return output
|
||||
})
|
||||
}
|
||||
.subscribe(on: self.scheduler)
|
||||
}
|
||||
|
||||
@ -244,32 +244,33 @@ public extension NvimView {
|
||||
) -> Single<NvimView.Buffer> {
|
||||
self.api
|
||||
.execLua(code: """
|
||||
local function map(tbl, f)
|
||||
local t = {}
|
||||
for k,v in pairs(tbl) do
|
||||
t[k] = f(v)
|
||||
end
|
||||
return t
|
||||
end
|
||||
return map(vim.fn.getbufinfo(...), function(i)
|
||||
i.buftype = vim.api.nvim_get_option_value("buftype",
|
||||
{buf=i.bufnr})
|
||||
return i
|
||||
end)
|
||||
""", args: [MessagePackValue(buf.handle)])
|
||||
local function map(tbl, f)
|
||||
local t = {}
|
||||
for k,v in pairs(tbl) do
|
||||
t[k] = f(v)
|
||||
end
|
||||
return t
|
||||
end
|
||||
return map(vim.fn.getbufinfo(...), function(i)
|
||||
i.buftype = vim.api.nvim_get_option_value("buftype",
|
||||
{buf=i.bufnr})
|
||||
return i
|
||||
end)
|
||||
""", args: [MessagePackValue(buf.handle)])
|
||||
.map { result -> NvimView.Buffer in
|
||||
guard let info_array = result.arrayValue,
|
||||
info_array.count == 1,
|
||||
info_array.count == 1,
|
||||
let raw_info = info_array[0].dictionaryValue
|
||||
else {
|
||||
throw RxNeovimApi.Error
|
||||
.exception(message: "Could not convert values into info array.")
|
||||
}
|
||||
let info : [String: MessagePackValue] = Dictionary<String, MessagePackValue>(
|
||||
uniqueKeysWithValues: raw_info.map({
|
||||
let info: [String: MessagePackValue] = .init(
|
||||
uniqueKeysWithValues: raw_info.map {
|
||||
(key: MessagePackValue, value: MessagePackValue) in
|
||||
(key.stringValue!, value)
|
||||
}))
|
||||
}
|
||||
)
|
||||
|
||||
let current = buf == currentBuffer
|
||||
guard let path = info["name"]?.stringValue,
|
||||
|
@ -58,7 +58,7 @@ public extension NvimView {
|
||||
default: return
|
||||
}
|
||||
|
||||
//try? self.api.feedkeys(keys: self.vimPlainString(text), mode:"m", escape_ks: false)
|
||||
// try? self.api.feedkeys(keys: self.vimPlainString(text), mode:"m", escape_ks: false)
|
||||
// .wait()
|
||||
_ = self.api.input(keys: self.vimPlainString(text), errWhenBlocked: false).syncValue()
|
||||
|
||||
@ -182,9 +182,9 @@ public extension NvimView {
|
||||
// after delete, cusor should be the location
|
||||
}
|
||||
if replacementRange.length > 0 {
|
||||
let text = String(repeating:"<BS>", count: replacementRange.length)
|
||||
try? self.api.feedkeys(keys: text, mode:"i", escape_ks: false)
|
||||
.wait()
|
||||
let text = String(repeating: "<BS>", count: replacementRange.length)
|
||||
try? self.api.feedkeys(keys: text, mode: "i", escape_ks: false)
|
||||
.wait()
|
||||
}
|
||||
|
||||
// delay to wait async gui update handled.
|
||||
|
@ -4,8 +4,8 @@
|
||||
*/
|
||||
|
||||
import Cocoa
|
||||
import RxSwift
|
||||
import RxNeovim
|
||||
import RxSwift
|
||||
|
||||
public extension NvimView {
|
||||
override func mouseDown(with event: NSEvent) {
|
||||
@ -91,22 +91,27 @@ public extension NvimView {
|
||||
if event.isDirectionInvertedFromDevice {
|
||||
vertSign = -vertSign
|
||||
}
|
||||
self.log.debug("# scroll: \(cellPosition.row + vertSign * absDeltaY) \(cellPosition.column + horizSign * absDeltaX)")
|
||||
self.log
|
||||
.debug(
|
||||
"# scroll: \(cellPosition.row + vertSign * absDeltaY) \(cellPosition.column + horizSign * absDeltaX)"
|
||||
)
|
||||
|
||||
self.api.winGetCursor(window: RxNeovimApi.Window(0))
|
||||
.map( {
|
||||
.map {
|
||||
guard $0.count == 2
|
||||
else {
|
||||
self.log.error("Error decoding \($0)")
|
||||
return
|
||||
}
|
||||
self.api.winSetCursor(window: RxNeovimApi.Window(0),
|
||||
pos: [$0[0] + vertSign * absDeltaY, $0[1] + horizSign * absDeltaX])
|
||||
self.api.winSetCursor(
|
||||
window: RxNeovimApi.Window(0),
|
||||
pos: [$0[0] + vertSign * absDeltaY, $0[1] + horizSign * absDeltaX]
|
||||
)
|
||||
.subscribe(onError: { [weak self] error in
|
||||
self?.log.error("Error in \(#function): \(error)")
|
||||
})
|
||||
.disposed(by: self.disposeBag)
|
||||
})
|
||||
}
|
||||
.subscribe(onError: { [weak self] error in
|
||||
self?.log.error("Error in \(#function): \(error)")
|
||||
})
|
||||
|
@ -4,9 +4,9 @@
|
||||
*/
|
||||
|
||||
import Cocoa
|
||||
import RxSwift
|
||||
import RxNeovim
|
||||
import MessagePack
|
||||
import RxNeovim
|
||||
import RxSwift
|
||||
|
||||
extension NvimView {
|
||||
override public func setFrameSize(_ newSize: NSSize) {
|
||||
@ -80,7 +80,8 @@ extension NvimView {
|
||||
usleep(1000)
|
||||
if ContinuousClock.now - start_time > timeout {
|
||||
self.eventsSubject.onNext(.ipcBecameInvalid(
|
||||
"Timeout waiting for neovim."))
|
||||
"Timeout waiting for neovim."
|
||||
))
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -89,9 +90,9 @@ extension NvimView {
|
||||
// on the Completable. We could demand that the user call launchNeoVim()
|
||||
// by themselves, but...
|
||||
try?
|
||||
self.api.run(at: sockPath)
|
||||
self.api.run(at: sockPath)
|
||||
.andThen(
|
||||
self.api.getApiInfo().map({
|
||||
self.api.getApiInfo().map {
|
||||
value in
|
||||
guard let info = value.arrayValue,
|
||||
info.count == 2,
|
||||
@ -107,50 +108,62 @@ extension NvimView {
|
||||
guard major >= 0 && minor >= 10 || major >= 1
|
||||
else {
|
||||
self.eventsSubject.onNext(.ipcBecameInvalid(
|
||||
"Incompatible neovim version \(major).\(minor)"))
|
||||
"Incompatible neovim version \(major).\(minor)"
|
||||
))
|
||||
throw RxNeovimApi.Error
|
||||
.exception(message: "Could not convert values to api info.")
|
||||
}
|
||||
|
||||
return channel
|
||||
}).flatMapCompletable({
|
||||
}.flatMapCompletable {
|
||||
// FIXME: make lua
|
||||
self.api.exec2(src: """
|
||||
":augroup vimr
|
||||
":augroup!
|
||||
:autocmd VimEnter * call rpcnotify(\($0), 'autocommand', 'vimenter')
|
||||
:autocmd BufWinEnter * call rpcnotify(\($0), 'autocommand', 'bufwinenter', str2nr(expand('<abuf>')))
|
||||
:autocmd BufWinEnter * call rpcnotify(\($0), 'autocommand', 'bufwinleave', str2nr(expand('<abuf>')))
|
||||
:autocmd TabEnter * call rpcnotify(\($0), 'autocommand', 'tabenter', str2nr(expand('<abuf>')))
|
||||
:autocmd BufWritePost * call rpcnotify(\($0), 'autocommand', 'bufwritepost', str2nr(expand('<abuf>')))
|
||||
:autocmd BufEnter * call rpcnotify(\($0), 'autocommand', 'bufenter', str2nr(expand('<abuf>')))
|
||||
:autocmd DirChanged * call rpcnotify(\($0), 'autocommand', 'dirchanged', expand('<afile>'))
|
||||
:autocmd ColorScheme * call rpcnotify(\($0), 'autocommand', 'colorscheme', \
|
||||
get(nvim_get_hl(0, {'id': hlID('Normal')}), 'fg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Normal')}), 'bg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Visual')}), 'fg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Visual')}), 'bg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Directory')}), 'fg', -1))
|
||||
:autocmd ExitPre * call rpcnotify(\($0), 'autocommand', 'exitpre')
|
||||
:autocmd BufModifiedSet * call rpcnotify(\($0), 'autocommand', 'bufmodifiedset', \
|
||||
str2nr(expand('<abuf>')), getbufinfo(str2nr(expand('<abuf>')))[0].changed)
|
||||
:let g:gui_vimr = 1
|
||||
":augroup END
|
||||
""", opts: [:]).asCompletable()
|
||||
|
||||
":augroup vimr
|
||||
":augroup!
|
||||
:autocmd VimEnter * call rpcnotify(\($0), 'autocommand', 'vimenter')
|
||||
:autocmd BufWinEnter * call rpcnotify(\(
|
||||
$0
|
||||
), 'autocommand', 'bufwinenter', str2nr(expand('<abuf>')))
|
||||
:autocmd BufWinEnter * call rpcnotify(\(
|
||||
$0
|
||||
), 'autocommand', 'bufwinleave', str2nr(expand('<abuf>')))
|
||||
:autocmd TabEnter * call rpcnotify(\(
|
||||
$0
|
||||
), 'autocommand', 'tabenter', str2nr(expand('<abuf>')))
|
||||
:autocmd BufWritePost * call rpcnotify(\(
|
||||
$0
|
||||
), 'autocommand', 'bufwritepost', str2nr(expand('<abuf>')))
|
||||
:autocmd BufEnter * call rpcnotify(\(
|
||||
$0
|
||||
), 'autocommand', 'bufenter', str2nr(expand('<abuf>')))
|
||||
:autocmd DirChanged * call rpcnotify(\(
|
||||
$0
|
||||
), 'autocommand', 'dirchanged', expand('<afile>'))
|
||||
:autocmd ColorScheme * call rpcnotify(\($0), 'autocommand', 'colorscheme', \
|
||||
get(nvim_get_hl(0, {'id': hlID('Normal')}), 'fg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Normal')}), 'bg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Visual')}), 'fg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Visual')}), 'bg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Directory')}), 'fg', -1))
|
||||
:autocmd ExitPre * call rpcnotify(\($0), 'autocommand', 'exitpre')
|
||||
:autocmd BufModifiedSet * call rpcnotify(\($0), 'autocommand', 'bufmodifiedset', \
|
||||
str2nr(expand('<abuf>')), getbufinfo(str2nr(expand('<abuf>')))[0].changed)
|
||||
:let g:gui_vimr = 1
|
||||
":augroup END
|
||||
""", opts: [:]).asCompletable()
|
||||
|
||||
.andThen(self.api.uiAttach(width: size.width, height: size.height, options: [
|
||||
"ext_linegrid": true,
|
||||
"ext_multigrid": false,
|
||||
"ext_tabline": MessagePackValue(self.usesCustomTabBar),
|
||||
"rgb": true
|
||||
"rgb": true,
|
||||
]))
|
||||
.andThen(
|
||||
self.sourceFileUrls.reduce(Completable.empty()) { prev, url in
|
||||
prev
|
||||
.andThen(
|
||||
self.api.exec2(src: "source \(url.shellEscapedPath)", opts:["output": true])
|
||||
.map({
|
||||
self.api.exec2(src: "source \(url.shellEscapedPath)", opts: ["output": true])
|
||||
.map {
|
||||
retval in
|
||||
guard let output_value = retval["output"] ?? retval["output"],
|
||||
let output = output_value.stringValue
|
||||
@ -159,12 +172,12 @@ extension NvimView {
|
||||
.exception(message: "Could not convert values to output.")
|
||||
}
|
||||
return output
|
||||
})
|
||||
}
|
||||
.asCompletable()
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
).wait()
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ extension NvimView {
|
||||
guard let grid = array[0].intValue,
|
||||
let width = array[1].intValue,
|
||||
let height = array[2].intValue
|
||||
else{
|
||||
else {
|
||||
self.bridgeLogger.error("Could not convert; wrong count: \(array)")
|
||||
return
|
||||
}
|
||||
@ -53,7 +53,7 @@ extension NvimView {
|
||||
}
|
||||
|
||||
final func optionSet(_ values: [MessagePackValue]) {
|
||||
var options : [MessagePackValue: MessagePackValue] = [:]
|
||||
var options: [MessagePackValue: MessagePackValue] = [:]
|
||||
for index in 1..<values.count {
|
||||
guard let option_pair = values[index].arrayValue,
|
||||
option_pair.count == 2
|
||||
@ -78,9 +78,9 @@ extension NvimView {
|
||||
|
||||
final func modeChange(_ value: MessagePackValue) {
|
||||
guard let mainTuple = value.arrayValue,
|
||||
mainTuple.count == 2,
|
||||
let modeName = mainTuple[0].stringValue,
|
||||
let modeIndex = mainTuple[1].uintValue
|
||||
mainTuple.count == 2,
|
||||
let modeName = mainTuple[0].stringValue,
|
||||
let modeIndex = mainTuple[1].uintValue
|
||||
else {
|
||||
self.bridgeLogger.error("Could not convert \(value)")
|
||||
return
|
||||
@ -110,15 +110,16 @@ extension NvimView {
|
||||
if let mainTuple = value.arrayValue,
|
||||
mainTuple.count == 2,
|
||||
let modeInfoArray = mainTuple[1].arrayValue?.map({
|
||||
let modeInfo = ModeInfo.init(withMsgPackDict:$0)
|
||||
let modeInfo = ModeInfo(withMsgPackDict: $0)
|
||||
return (modeInfo.name, modeInfo)
|
||||
})
|
||||
{
|
||||
self.modeInfos = Dictionary(
|
||||
uniqueKeysWithValues: modeInfoArray)
|
||||
uniqueKeysWithValues: modeInfoArray
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final func renderData(_ renderData: [MessagePackValue]) {
|
||||
self.bridgeLogger.trace("# of render data: \(renderData.count)")
|
||||
|
||||
@ -199,7 +200,7 @@ extension NvimView {
|
||||
self.visualBell()
|
||||
|
||||
case "set_icon":
|
||||
// FIXME
|
||||
// FIXME:
|
||||
break
|
||||
|
||||
case "grid_cursor_goto":
|
||||
@ -232,7 +233,7 @@ extension NvimView {
|
||||
|
||||
case "flush":
|
||||
// FIXME: buffer up all the prior data
|
||||
//self.markForRenderWholeView()
|
||||
// self.markForRenderWholeView()
|
||||
break
|
||||
|
||||
case "tabline_update":
|
||||
@ -244,7 +245,7 @@ extension NvimView {
|
||||
}
|
||||
|
||||
guard recompute else { return }
|
||||
if (rowStart < Int.max) {
|
||||
if rowStart < Int.max {
|
||||
self.ugrid.recomputeFlatIndices(rowStart: rowStart)
|
||||
}
|
||||
}
|
||||
@ -265,66 +266,66 @@ extension NvimView {
|
||||
self.quit()
|
||||
.andThen(self.api.stop())
|
||||
.andThen(Completable.create { completable in
|
||||
self.eventsSubject.onNext(.neoVimStopped)
|
||||
self.eventsSubject.onCompleted()
|
||||
self.eventsSubject.onNext(.neoVimStopped)
|
||||
self.eventsSubject.onCompleted()
|
||||
|
||||
completable(.completed)
|
||||
return Disposables.create()
|
||||
})
|
||||
.subscribe(onCompleted: { [weak self] in
|
||||
self?.bridgeLogger.info("Successfully stopped the bridge.")
|
||||
self?.nvimExitedCondition.broadcast()
|
||||
}, onError: {
|
||||
self.bridgeLogger.fault("There was an error stopping the bridge: \($0)")
|
||||
})
|
||||
completable(.completed)
|
||||
return Disposables.create()
|
||||
})
|
||||
.subscribe(onCompleted: { [weak self] in
|
||||
self?.bridgeLogger.info("Successfully stopped the bridge.")
|
||||
self?.nvimExitedCondition.broadcast()
|
||||
}, onError: {
|
||||
self.bridgeLogger.fault("There was an error stopping the bridge: \($0)")
|
||||
})
|
||||
.disposed(by: self.disposeBag)
|
||||
}
|
||||
|
||||
final func autoCommandEvent(_ array: [MessagePackValue]) {
|
||||
guard array.count > 0,
|
||||
let aucmd = array[0].stringValue?.lowercased(),
|
||||
let event = NvimAutoCommandEvent(rawValue: aucmd)
|
||||
else {
|
||||
self.bridgeLogger.error("Could not convert \(array)")
|
||||
return
|
||||
}
|
||||
let event = NvimAutoCommandEvent(rawValue: aucmd)
|
||||
else {
|
||||
self.bridgeLogger.error("Could not convert \(array)")
|
||||
return
|
||||
}
|
||||
|
||||
self.bridgeLogger.debug("\(event): \(array)")
|
||||
self.bridgeLogger.debug("\(event): \(array)")
|
||||
|
||||
if event == .vimenter {
|
||||
Completable
|
||||
.empty()
|
||||
.observe(on: SerialDispatchQueueScheduler(qos: .userInitiated))
|
||||
.andThen(
|
||||
Completable.create { completable in
|
||||
self.rpcEventSubscriptionCondition.wait(for: 5)
|
||||
self.bridgeLogger.debug("RPC events subscription done.")
|
||||
if event == .vimenter {
|
||||
Completable
|
||||
.empty()
|
||||
.observe(on: SerialDispatchQueueScheduler(qos: .userInitiated))
|
||||
.andThen(
|
||||
Completable.create { completable in
|
||||
self.rpcEventSubscriptionCondition.wait(for: 5)
|
||||
self.bridgeLogger.debug("RPC events subscription done.")
|
||||
|
||||
completable(.completed)
|
||||
return Disposables.create()
|
||||
}
|
||||
)
|
||||
.andThen(
|
||||
{
|
||||
let ginitPath = URL(fileURLWithPath: NSHomeDirectory())
|
||||
.appendingPathComponent(".config/nvim/ginit.vim").path
|
||||
let loadGinit = FileManager.default.fileExists(atPath: ginitPath)
|
||||
if loadGinit {
|
||||
self.bridgeLogger.debug("Source'ing ginit.vim")
|
||||
return self.api.command(command: "source \(ginitPath.shellEscapedPath)")
|
||||
} else {
|
||||
return .empty()
|
||||
}
|
||||
}()
|
||||
)
|
||||
//.andThen(self.bridge.notifyReadinessForRpcEvents())
|
||||
.subscribe(onCompleted: { [weak self] in
|
||||
self?.log.debug("Notified the NvimServer to fire GUIEnter")
|
||||
})
|
||||
.disposed(by: self.disposeBag)
|
||||
completable(.completed)
|
||||
return Disposables.create()
|
||||
}
|
||||
)
|
||||
.andThen(
|
||||
{
|
||||
let ginitPath = URL(fileURLWithPath: NSHomeDirectory())
|
||||
.appendingPathComponent(".config/nvim/ginit.vim").path
|
||||
let loadGinit = FileManager.default.fileExists(atPath: ginitPath)
|
||||
if loadGinit {
|
||||
self.bridgeLogger.debug("Source'ing ginit.vim")
|
||||
return self.api.command(command: "source \(ginitPath.shellEscapedPath)")
|
||||
} else {
|
||||
return .empty()
|
||||
}
|
||||
}()
|
||||
)
|
||||
// .andThen(self.bridge.notifyReadinessForRpcEvents())
|
||||
.subscribe(onCompleted: { [weak self] in
|
||||
self?.log.debug("Notified the NvimServer to fire GUIEnter")
|
||||
})
|
||||
.disposed(by: self.disposeBag)
|
||||
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if event == .exitpre {
|
||||
self.stop()
|
||||
@ -420,13 +421,13 @@ extension NvimView {
|
||||
var string = ""
|
||||
var attrId: Int? = nil
|
||||
var repeats: Int? = nil
|
||||
if (argArray.count > 0 && arg[0] != nil && arg[0]?.stringValue != nil) {
|
||||
if argArray.count > 0, arg[0] != nil, arg[0]?.stringValue != nil {
|
||||
string = arg[0]!.stringValue!
|
||||
}
|
||||
if (argArray.count > 1 && arg[1] != nil && arg[1]?.intValue != nil) {
|
||||
if argArray.count > 1, arg[1] != nil, arg[1]?.intValue != nil {
|
||||
attrId = arg[1]!.intValue!
|
||||
}
|
||||
if (argArray.count > 2 && arg[2] != nil && arg[2]?.intValue != nil) {
|
||||
if argArray.count > 2, arg[2] != nil, arg[2]?.intValue != nil {
|
||||
repeats = arg[2]!.intValue!
|
||||
}
|
||||
return UUpdate(string: string, attrId: attrId, repeats: repeats)
|
||||
@ -684,29 +685,36 @@ extension NvimView {
|
||||
else {
|
||||
self.bridgeLogger.error(
|
||||
"Could not get highlight attributes from " +
|
||||
"\(value)"
|
||||
"\(value)"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let mapped_rgb_dict = rgb_dict.map({
|
||||
let mapped_rgb_dict = rgb_dict.map {
|
||||
(key: MessagePackValue, value: MessagePackValue) in
|
||||
(key.stringValue!, value)
|
||||
})
|
||||
let rgb_attr = Dictionary<String, MessagePackValue>(
|
||||
uniqueKeysWithValues: mapped_rgb_dict)
|
||||
}
|
||||
let rgb_attr = [String: MessagePackValue](
|
||||
uniqueKeysWithValues: mapped_rgb_dict
|
||||
)
|
||||
let attrs = CellAttributes(
|
||||
withDict: rgb_attr,
|
||||
with: CellAttributes(fontTrait: FontTrait(), foreground: -1, background: -1, special:-1, reverse: false)
|
||||
//self.cellAttributesCollection.defaultAttributes
|
||||
with: CellAttributes(
|
||||
fontTrait: FontTrait(),
|
||||
foreground: -1,
|
||||
background: -1,
|
||||
special: -1,
|
||||
reverse: false
|
||||
)
|
||||
// self.cellAttributesCollection.defaultAttributes
|
||||
)
|
||||
|
||||
self.bridgeLogger.debug("AttrId: \(id): \(attrs)")
|
||||
|
||||
// FIXME: seems to not work well unless not async
|
||||
//gui.async {
|
||||
self.cellAttributesCollection.set(attributes: attrs, for: id)
|
||||
//}
|
||||
// gui.async {
|
||||
self.cellAttributesCollection.set(attributes: attrs, for: id)
|
||||
// }
|
||||
}
|
||||
|
||||
final func defaultColors(with value: MessagePackValue) {
|
||||
@ -727,23 +735,25 @@ extension NvimView {
|
||||
else {
|
||||
self.bridgeLogger.error(
|
||||
"Could not get default colors from " +
|
||||
"\(value)"
|
||||
"\(value)"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let attrs = CellAttributes(
|
||||
fontTrait: FontTrait(), foreground: rgb_fg, background: rgb_bg, special: rgb_sp, reverse: false)
|
||||
fontTrait: FontTrait(), foreground: rgb_fg, background: rgb_bg, special: rgb_sp,
|
||||
reverse: false
|
||||
)
|
||||
|
||||
//gui.async {
|
||||
self.cellAttributesCollection.set(
|
||||
attributes: attrs,
|
||||
for: CellAttributesCollection.defaultAttributesId
|
||||
)
|
||||
self.layer?.backgroundColor = ColorUtils.cgColorIgnoringAlpha(
|
||||
attrs.background
|
||||
)
|
||||
//}
|
||||
// gui.async {
|
||||
self.cellAttributesCollection.set(
|
||||
attributes: attrs,
|
||||
for: CellAttributesCollection.defaultAttributesId
|
||||
)
|
||||
self.layer?.backgroundColor = ColorUtils.cgColorIgnoringAlpha(
|
||||
attrs.background
|
||||
)
|
||||
// }
|
||||
}
|
||||
|
||||
final func updateMenu() {
|
||||
@ -817,30 +827,29 @@ extension NvimView {
|
||||
gui.async { self.tabBar?.update(tabRepresentatives: self.tabEntries) }
|
||||
}
|
||||
|
||||
|
||||
func winViewportUpdate(_ value: [MessagePackValue]) {
|
||||
// FIXME
|
||||
/*
|
||||
guard let array = value.arrayValue,
|
||||
array.count == 8
|
||||
else {
|
||||
self.bridgeLogger.error("Could not convert \(value)")
|
||||
return
|
||||
}
|
||||
guard let grid = array[0].intValue,
|
||||
let top = array[2].intValue,
|
||||
let bot = array[3].intValue,
|
||||
let curline = array[4].intValue,
|
||||
let curcol = array[5].intValue,
|
||||
let linecount = array[6].intValue,
|
||||
let scroll_delta = array[6].intValue
|
||||
else {
|
||||
self.bridgeLogger.error("Could not convert \(value)")
|
||||
return
|
||||
}
|
||||
// [top, bot, left, right, rows, cols]
|
||||
// FIXMEL self.doScroll([])
|
||||
*/
|
||||
func winViewportUpdate(_: [MessagePackValue]) {
|
||||
// FIXME:
|
||||
/*
|
||||
guard let array = value.arrayValue,
|
||||
array.count == 8
|
||||
else {
|
||||
self.bridgeLogger.error("Could not convert \(value)")
|
||||
return
|
||||
}
|
||||
guard let grid = array[0].intValue,
|
||||
let top = array[2].intValue,
|
||||
let bot = array[3].intValue,
|
||||
let curline = array[4].intValue,
|
||||
let curcol = array[5].intValue,
|
||||
let linecount = array[6].intValue,
|
||||
let scroll_delta = array[6].intValue
|
||||
else {
|
||||
self.bridgeLogger.error("Could not convert \(value)")
|
||||
return
|
||||
}
|
||||
// [top, bot, left, right, rows, cols]
|
||||
// FIXMEL self.doScroll([])
|
||||
*/
|
||||
}
|
||||
|
||||
private func bufferWritten(_ handle: Int) {
|
||||
@ -885,11 +894,11 @@ extension NvimView {
|
||||
}
|
||||
|
||||
func focusGained(_ gained: Bool) -> Completable {
|
||||
return self.api.uiSetFocus(gained: gained)
|
||||
self.api.uiSetFocus(gained: gained)
|
||||
}
|
||||
|
||||
func quit() -> Completable {
|
||||
return self.bridge.quit()
|
||||
self.bridge.quit()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
|
||||
public let api = RxNeovimApi()
|
||||
|
||||
public internal(set) var mode: CursorModeShape = .normal
|
||||
public internal(set) var modeInfos = [String : ModeInfo]()
|
||||
public internal(set) var modeInfos = [String: ModeInfo]()
|
||||
|
||||
public internal(set) var theme = Theme.default
|
||||
|
||||
@ -170,10 +170,10 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
|
||||
switch msg {
|
||||
case let .notification(method, params):
|
||||
self?.log.debug("NOTIFICATION: \(method): \(params)")
|
||||
|
||||
if (method == "redraw") {
|
||||
|
||||
if method == "redraw" {
|
||||
self?.renderData(params)
|
||||
} else if (method == "autocommand") {
|
||||
} else if method == "autocommand" {
|
||||
self?.autoCommandEvent(params)
|
||||
} else {
|
||||
self?.log.debug("MSG ERROR: \(msg)")
|
||||
|
@ -288,7 +288,7 @@ final class UGrid: CustomStringConvertible, Codable {
|
||||
updateMarkedInfo(newValue: oldMarkedInfo)
|
||||
}
|
||||
}
|
||||
var lastAttrId : Int = 0
|
||||
var lastAttrId = 0
|
||||
var column = startCol
|
||||
for cindex in 0..<chunk.count {
|
||||
let reps = chunk[cindex].repeats ?? 1
|
||||
|
@ -56,8 +56,8 @@ final class UiBridge {
|
||||
|
||||
func forceQuit() -> Completable {
|
||||
self.log.fault("Force-exiting NvimServer \(self.uuid).")
|
||||
|
||||
return Completable.create { completable in
|
||||
|
||||
return Completable.create { _ in
|
||||
self.forceExitNvimServer()
|
||||
self.log.fault("NvimServer \(self.uuid) was forcefully exited.")
|
||||
return Disposables.create()
|
||||
@ -75,7 +75,6 @@ final class UiBridge {
|
||||
|
||||
self.log.debug("Socket: \(self.listenAddress)")
|
||||
|
||||
|
||||
let inPipe = Pipe()
|
||||
let outPipe = Pipe()
|
||||
let errorPipe = Pipe()
|
||||
@ -85,8 +84,9 @@ final class UiBridge {
|
||||
process.standardOutput = outPipe
|
||||
process.currentDirectoryPath = self.cwd.path
|
||||
|
||||
if (self.nvimBinary != "" &&
|
||||
FileManager.default.fileExists(atPath: self.nvimBinary)) {
|
||||
if self.nvimBinary != "",
|
||||
FileManager.default.fileExists(atPath: self.nvimBinary)
|
||||
{
|
||||
process.launchPath = self.nvimBinary
|
||||
} else {
|
||||
// We know that NvimServer is there.
|
||||
@ -98,9 +98,9 @@ final class UiBridge {
|
||||
|
||||
process
|
||||
.arguments =
|
||||
["--embed",
|
||||
"--listen",
|
||||
self.listenAddress] + self.nvimArgs
|
||||
["--embed",
|
||||
"--listen",
|
||||
self.listenAddress] + self.nvimArgs
|
||||
|
||||
self.log.debug(
|
||||
"Launching NvimServer \(String(describing: process.launchPath)) with args: \(String(describing: process.arguments))"
|
||||
@ -149,7 +149,7 @@ final class UiBridge {
|
||||
private var remoteServerName: String { "com.qvacua.NvimView.NvimServer.\(self.uuid)" }
|
||||
|
||||
var listenAddress: String {
|
||||
return URL(fileURLWithPath: NSTemporaryDirectory())
|
||||
URL(fileURLWithPath: NSTemporaryDirectory())
|
||||
.appendingPathComponent("vimr_\(self.uuid).sock").path
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
@NSApplicationMain
|
||||
@main
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
@IBOutlet var window: NSWindow!
|
||||
|
||||
|
@ -7,7 +7,7 @@ import Cocoa
|
||||
import GameKit
|
||||
import os
|
||||
|
||||
@NSApplicationMain
|
||||
@main
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
@IBOutlet var window: NSWindow!
|
||||
var result = [[[FontGlyphRun]]](repeating: [], count: count)
|
||||
@ -24,7 +24,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
let indices = (0..<count).map { _ in rd.nextInt() % 3 }
|
||||
|
||||
let time = self.measure {
|
||||
for i in 0..<count { result[i] = self.perf.render(indices[i]) }
|
||||
for i in 0..<count { self.result[i] = self.perf.render(indices[i]) }
|
||||
}
|
||||
results.append(time)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class PerfTester {
|
||||
let decoder = JSONDecoder()
|
||||
do {
|
||||
let data = try Data(contentsOf: fileUrl)
|
||||
self.ugrids.append(try decoder.decode(UGrid.self, from: data))
|
||||
try self.ugrids.append(decoder.decode(UGrid.self, from: data))
|
||||
} catch {
|
||||
preconditionFailure("Couldn't decode UGrid from \(name).json: \(error)")
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
@NSApplicationMain
|
||||
@main
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationDidFinishLaunching(_: Notification) {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user