diff --git a/SwiftNeoVim/NeoVimView+UiBridge.swift b/SwiftNeoVim/NeoVimView+UiBridge.swift index 8f2f1829..3986add5 100644 --- a/SwiftNeoVim/NeoVimView+UiBridge.swift +++ b/SwiftNeoVim/NeoVimView+UiBridge.swift @@ -152,6 +152,8 @@ extension NeoVimView { self.bridgeLogger.debug(ColorUtils.colorIgnoringAlpha(fg)) self.grid.foreground = fg + + self.delegate?.foregroundChanged(to: ColorUtils.colorIgnoringAlpha(fg)) } } @@ -161,6 +163,8 @@ extension NeoVimView { self.grid.background = bg self.layer?.backgroundColor = ColorUtils.colorIgnoringAlpha(self.grid.background).cgColor + + self.delegate?.backgroundChanged(to: ColorUtils.colorIgnoringAlpha(bg)) } } @@ -169,6 +173,8 @@ extension NeoVimView { self.bridgeLogger.debug(ColorUtils.colorIgnoringAlpha(sp)) self.grid.special = sp + + self.delegate?.specialChanged(to: ColorUtils.colorIgnoringAlpha(sp)) } } @@ -198,6 +204,10 @@ extension NeoVimView { gui.async { // self.bridgeLogger.debug("\(neoVimAutoCommandEventName(event)) -> \(bufferHandle)") + if event == .COLORSCHEME { + NSLog(self.agent.vimCommandOutput("hi")!) + } + if event == .BUFWINENTER || event == .BUFWINLEAVE { self.bufferListChanged() } @@ -206,6 +216,15 @@ extension NeoVimView { self.tabChanged() } + let output = "SpecialComment xxx links to Special\n" + + "Debug xxx links to Special\n" + + "FoldColmun xxx ctermfg=246 ctermbg=235 guifg=#909194 guibg=#44475a\n" + + "Normal xxx guifg=#f8f8f2 guibg=#282a36\n" + + "rubyClass xxx ctermfg=212 guifg=#ff79c6\n" + + "rubyFunction xxx ctermfg=84 guifg=#50fa7b\n" + + "rubyInterpolationDelimiter xxx cleared\n" + + "rubySymbol xxx ctermfg=141 guifg=#bd93f9" + if event == .BUFREADPOST || event == .BUFWRITEPOST { self.currentBufferChanged(bufferHandle) } diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index 8cd91357..4ab94dc0 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -136,7 +136,7 @@ public class NeoVimView: NSView, @IBAction public func debug1(_ sender: Any?) { self.logger.debug("DEBUG 1 - Start") - NSApp.hide(self) + NSLog(self.agent.vimCommandOutput("hi")!) self.logger.debug("DEBUG 1 - End") } diff --git a/SwiftNeoVim/NeoVimViewDelegate.swift b/SwiftNeoVim/NeoVimViewDelegate.swift index 59d4bc18..17417bf9 100644 --- a/SwiftNeoVim/NeoVimViewDelegate.swift +++ b/SwiftNeoVim/NeoVimViewDelegate.swift @@ -16,6 +16,10 @@ public protocol NeoVimViewDelegate: class { func tabChanged() func currentBufferChanged(_ currentBuffer: NeoVimBuffer) + func foregroundChanged(to: NSColor) + func backgroundChanged(to: NSColor) + func specialChanged(to: NSColor) + func ipcBecameInvalid(reason: String) func scroll() diff --git a/VimR/MainWindow.swift b/VimR/MainWindow.swift index fd078862..b1ce2d69 100644 --- a/VimR/MainWindow.swift +++ b/VimR/MainWindow.swift @@ -39,6 +39,8 @@ class MainWindow: NSObject, case setState(for: Tools, with: WorkspaceTool) case setToolsState([(Tools, WorkspaceTool)]) + case setTheme(Theme) + case close } @@ -68,6 +70,14 @@ class MainWindow: NSObject, case verticalSplit } + struct Theme { + + static let `default` = Theme() + + var foreground = NSColor.black + var background = NSColor.white + } + required init(source: Observable, emitter: ActionEmitter, state: StateType) { self.emit = emitter.typedEmit() self.uuid = state.uuid @@ -270,6 +280,8 @@ class MainWindow: NSObject, fileprivate var linespacing: CGFloat fileprivate var usesLigatures: Bool + fileprivate var theme = Theme.default + fileprivate let fontManager = NSFontManager.shared() fileprivate let workspace: Workspace @@ -394,6 +406,20 @@ extension MainWindow { self.currentBufferChanged(currentBuffer) } + func foregroundChanged(to color: NSColor) { + self.theme.foreground = color + self.emit(uuidAction(for: .setTheme(self.theme))) + } + + func backgroundChanged(to color: NSColor) { + self.theme.background = color + self.emit(uuidAction(for: .setTheme(self.theme))) + } + + func specialChanged(to color: NSColor) { + // noop + } + func ipcBecameInvalid(reason: String) { let alert = NSAlert() alert.addButton(withTitle: "Close") diff --git a/VimR/MainWindowReducer.swift b/VimR/MainWindowReducer.swift index 4090ea03..35b3b903 100644 --- a/VimR/MainWindowReducer.swift +++ b/VimR/MainWindowReducer.swift @@ -82,6 +82,9 @@ class MainWindowReducer { case let .toggleToolButtons(value): state.isToolButtonsVisible = value + case let .setTheme(theme): + state.theme = Marked(theme) + default: return pair diff --git a/VimR/States.swift b/VimR/States.swift index 57b536bd..d4294ce5 100644 --- a/VimR/States.swift +++ b/VimR/States.swift @@ -208,6 +208,8 @@ extension MainWindow { Tools.htmlPreview: true, ] + var theme = Marked(Theme.default) + ////// transient var lastFileSystemUpdate = Marked(FileUtils.userHomeUrl)