1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-09-11 17:15:34 +03:00

Merge pull request #1072 from s-daveb/master

Make VimR tab colors match 1:1 with colorscheme.
This commit is contained in:
Tae Won Ha 2024-06-16 08:49:13 +02:00 committed by GitHub
commit 82b6f33e53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 82 additions and 44 deletions

View File

@ -109,16 +109,26 @@ extension NvimView {
throw RxNeovimApi.Error.exception(message: "Incompatible neovim version.") throw RxNeovimApi.Error.exception(message: "Incompatible neovim version.")
} }
// swiftformat:disable all // swiftformat:disable all
return self.api.nvimExec2(src: """ let vimscript = """
let g:gui_vimr = 1 function! GetHiColor(hlID, component)
autocmd VimLeave * call rpcnotify(\(channel), 'autocommand', 'vimleave') let color = synIDattr(synIDtrans(hlID(a:hlID)), a:component)
autocmd VimEnter * call rpcnotify(\(channel), 'autocommand', 'vimenter') if empty(color)
autocmd ColorScheme * call rpcnotify(\(channel), '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), get(nvim_get_hl(0, {'id': hlID('TablineSel')}), 'bg', -1), get(nvim_get_hl(0, {'id': hlID('TablineSel')}), 'fg', -1)) return -1
autocmd VimEnter * call rpcrequest(\(channel), 'vimenter') else
""", opts: [:], errWhenBlocked: false) return str2nr(color[1:], 16)
// swiftformat:enable all endif
.asCompletable() endfunction
let g:gui_vimr = 1
autocmd VimLeave * call rpcnotify(\(channel), 'autocommand', 'vimleave')
autocmd VimEnter * call rpcnotify(\(channel), 'autocommand', 'vimenter')
autocmd ColorScheme * call rpcnotify(\(channel), 'autocommand', 'colorscheme', GetHiColor('Normal', 'fg'), GetHiColor('Normal', 'bg'), GetHiColor('Visual', 'fg'), GetHiColor('Visual', 'bg'), GetHiColor('Directory', 'fg'), GetHiColor('TablineFill', 'bg'), GetHiColor('TablineFill', 'fg'), GetHiColor('Tabline', 'bg'), GetHiColor('Tabline', 'fg'), GetHiColor('TablineSel', 'bg'), GetHiColor('TablineSel', 'fg'))
autocmd VimEnter * call rpcrequest(\(channel), 'vimenter')
"""
return self.api.nvimExec2(src: vimscript, opts: [:], errWhenBlocked: false)
.asCompletable()
// swiftformat:enable all
} }
) )
.andThen( .andThen(

View File

@ -94,7 +94,8 @@ public extension NvimView {
public var foreground = NSColor.textColor public var foreground = NSColor.textColor
public var background = NSColor.textBackgroundColor public var background = NSColor.textBackgroundColor
public var visualForeground = NSColor.selectedMenuItemTextColor public var visualForeground: NSColor = NSColor(named: NSColor.Name("controlAccentColor")) ?? .selectedMenuItemTextColor
// NSColor.selectedMenuItemTextColor
// NSColor.selectedMenuItemColor is deprecated. The doc says that // NSColor.selectedMenuItemColor is deprecated. The doc says that
// NSVisualEffectView.Material.selection should be used instead, but I don't know how to get // NSVisualEffectView.Material.selection should be used instead, but I don't know how to get
// an NSColor from it. // an NSColor from it.
@ -102,13 +103,19 @@ public extension NvimView {
public var directoryForeground = NSColor.textColor public var directoryForeground = NSColor.textColor
public var tabForeground = NSColor.textColor public var tabForeground = NSColor.controlColor
public var tabBackground = NSColor.textBackgroundColor public var tabBackground = NSColor.controlBackgroundColor
public var tabBarForeground = NSColor.textColor
public var tabBarBackground = NSColor.windowBackgroundColor
public var selectedTabForeground = NSColor.selectedTextColor
public var selectedTabBackground = NSColor.selectedTextBackgroundColor
public init() {} public init() {}
public init(_ values: [Int]) { public init(_ values: [Int]) {
if values.count < 7 { preconditionFailure("We need 7 colors!") } if values.count < 11 { preconditionFailure("We need 11 colors!") }
let color = ColorUtils.colorIgnoringAlpha let color = ColorUtils.colorIgnoringAlpha
@ -121,8 +128,16 @@ public extension NvimView {
self.directoryForeground = values[4] < 0 self.directoryForeground = values[4] < 0
? Theme.default.directoryForeground ? Theme.default.directoryForeground
: color(values[4]) : color(values[4])
self.tabBackground = values[5] < 0 ? Theme.default.background : color(values[5])
self.tabForeground = values[6] < 0 ? Theme.default.foreground : color(values[6]) self.tabBarBackground = values[5] < 0 ? Theme.default.tabBarBackground : color(values[5])
self.tabBarForeground = values[6] < 0 ? Theme.default.tabBarForeground : color(values[6])
self.tabBackground = values[7] < 0 ? Theme.default.tabBackground : color(values[7])
self.tabForeground = values[8] < 0 ? Theme.default.tabForeground : color(values[8])
self.selectedTabBackground = values[9] < 0 ? Theme.default.selectedTabBackground : color(values[9])
self.selectedTabForeground = values[10] < 0 ? Theme.default.selectedTabForeground : color(values[10])
} }
public var description: String { public var description: String {
@ -130,6 +145,8 @@ public extension NvimView {
"fg: \(self.foreground.hex), bg: \(self.background.hex), " + "fg: \(self.foreground.hex), bg: \(self.background.hex), " +
"visual-fg: \(self.visualForeground.hex), visual-bg: \(self.visualBackground.hex)" + "visual-fg: \(self.visualForeground.hex), visual-bg: \(self.visualBackground.hex)" +
"tab-fg: \(self.tabForeground.hex), tab-bg: \(self.tabBackground.hex)" + "tab-fg: \(self.tabForeground.hex), tab-bg: \(self.tabBackground.hex)" +
"tabfill-fg: \(self.tabBarForeground.hex), tabfill-bg: \(self.tabBarBackground.hex)" +
"tabsel-fg: \(self.selectedTabForeground.hex), tabsel-bg: \(self.selectedTabBackground.hex)" +
">" ">"
} }
} }

View File

@ -513,7 +513,7 @@ extension NvimView {
private func colorSchemeChanged(_ value: MessagePackValue) { private func colorSchemeChanged(_ value: MessagePackValue) {
guard let values = MessagePackUtils.array( guard let values = MessagePackUtils.array(
from: value, ofSize: 7, conversion: { $0.intValue } from: value, ofSize: 11, conversion: { $0.intValue }
) else { ) else {
self.bridgeLogger.error("Could not convert \(value)") self.bridgeLogger.error("Could not convert \(value)")
return return

View File

@ -107,8 +107,8 @@ extension Tab {
private func adjustColors(_ newIsSelected: Bool) { private func adjustColors(_ newIsSelected: Bool) {
if newIsSelected { if newIsSelected {
self.layer?.backgroundColor = self.theme.tabBackgroundColor.cgColor self.layer?.backgroundColor = self.theme.selectedBackgroundColor.cgColor
self.titleView.textColor = self.theme.tabForegroundColor self.titleView.textColor = self.theme.selectedForegroundColor
self.closeButton.image = self.theme.selectedCloseButtonImage self.closeButton.image = self.theme.selectedCloseButtonImage
} else { } else {
self.layer?.backgroundColor = self.theme.backgroundColor.cgColor self.layer?.backgroundColor = self.theme.backgroundColor.cgColor

View File

@ -31,14 +31,14 @@ public final class TabBar<Rep: TabRepresentative>: NSView {
super.init(frame: .zero) super.init(frame: .zero)
self.configureForAutoLayout() self.configureForAutoLayout()
self.wantsLayer = true self.wantsLayer = true
self.layer?.backgroundColor = theme.backgroundColor.cgColor self.layer?.backgroundColor = theme.tabBarBackgroundColor.cgColor
self.addViews() self.addViews()
} }
public func update(theme: Theme) { public func update(theme: Theme) {
self._theme = theme self._theme = theme
self.layer?.backgroundColor = theme.backgroundColor.cgColor self.layer?.backgroundColor = theme.tabBarBackgroundColor.cgColor
self.needsDisplay = true self.needsDisplay = true
self.tabs.forEach { $0.updateTheme() } self.tabs.forEach { $0.updateTheme() }

View File

@ -9,6 +9,8 @@ import MaterialIcons
public struct Theme { public struct Theme {
public static let `default` = Self() public static let `default` = Self()
public var separatorColor = NSColor.gridColor
public var backgroundColor = NSColor.textBackgroundColor
public var foregroundColor = NSColor.textColor { public var foregroundColor = NSColor.textColor {
didSet { didSet {
self.closeButtonImage = Icon.close.asImage( self.closeButtonImage = Icon.close.asImage(
@ -17,25 +19,21 @@ public struct Theme {
) )
} }
} }
public var backgroundColor = NSColor.textBackgroundColor public var selectedBackgroundColor = NSColor.selectedTextBackgroundColor
public var separatorColor = NSColor.gridColor
public var selectedForegroundColor = NSColor.selectedTextColor { public var selectedForegroundColor = NSColor.selectedTextColor {
didSet { didSet {
self.selectedCloseButtonImage = Icon.close.asImage( self.selectedCloseButtonImage = Icon.close.asImage(
dimension: self.iconDimension.width, dimension: self.iconDimension.width,
color: self.tabForegroundColor color: self.selectedForegroundColor
) )
} }
} }
public var selectedBackgroundColor = NSColor.selectedTextBackgroundColor
public var tabSelectedIndicatorColor = NSColor.selectedTextColor public var tabSelectedIndicatorColor = NSColor.selectedTextColor
public var tabBackgroundColor = NSColor.selectedTextBackgroundColor public var tabBarBackgroundColor = NSColor.windowBackgroundColor
public var tabForegroundColor = NSColor.selectedTextColor public var tabBarForegroundColor = NSColor.textColor
public var titleFont = NSFont.systemFont(ofSize: 11) public var titleFont = NSFont.systemFont(ofSize: 11)
public var selectedTitleFont = NSFont.boldSystemFont(ofSize: 11) public var selectedTitleFont = NSFont.boldSystemFont(ofSize: 11)
@ -60,12 +58,11 @@ public struct Theme {
public init() { public init() {
self.closeButtonImage = Icon.close.asImage( self.closeButtonImage = Icon.close.asImage(
dimension: self.iconDimension.width, dimension: self.iconDimension.width,
color: self.tabForegroundColor color: self.foregroundColor
) )
self.selectedCloseButtonImage = Icon.close.asImage( self.selectedCloseButtonImage = Icon.close.asImage(
dimension: self.iconDimension.width, dimension: self.iconDimension.width,
color: self.tabForegroundColor color: self.foregroundColor
) )
} }
} }

View File

@ -470,16 +470,16 @@ final class MainWindow: NSObject,
private func set(tabsThemeWith _: Theme) { private func set(tabsThemeWith _: Theme) {
var tabsTheme = Tabs.Theme.default var tabsTheme = Tabs.Theme.default
tabsTheme.foregroundColor = self.theme.foreground tabsTheme.foregroundColor = self.theme.tabForeground
tabsTheme.backgroundColor = self.theme.background tabsTheme.backgroundColor = self.theme.tabBackground
tabsTheme.separatorColor = self.theme.background.brightening(by: 0.75) tabsTheme.separatorColor = self.theme.background.brightening(by: 0.75)
tabsTheme.selectedForegroundColor = self.theme.highlightForeground tabsTheme.tabBarBackgroundColor = self.theme.tabBarBackground
tabsTheme.selectedBackgroundColor = self.theme.highlightBackground tabsTheme.tabBarForegroundColor = self.theme.tabBarForeground
tabsTheme.tabBackgroundColor = self.theme.tabBackground tabsTheme.selectedForegroundColor = self.theme.selectedTabForeground
tabsTheme.tabForegroundColor = self.theme.tabForeground tabsTheme.selectedBackgroundColor = self.theme.selectedTabBackground
tabsTheme.tabSelectedIndicatorColor = self.theme.highlightForeground tabsTheme.tabSelectedIndicatorColor = self.theme.highlightForeground

View File

@ -49,6 +49,12 @@ struct Theme: CustomStringConvertible {
var tabForeground = NSColor.selectedMenuItemTextColor var tabForeground = NSColor.selectedMenuItemTextColor
var tabBackground = NSColor.selectedContentBackgroundColor var tabBackground = NSColor.selectedContentBackgroundColor
var tabBarForeground = NSColor.selectedMenuItemTextColor
var tabBarBackground = NSColor.selectedContentBackgroundColor
var selectedTabForeground = NSColor.selectedMenuItemTextColor
var selectedTabBackground = NSColor.selectedContentBackgroundColor
var cssColor = NSColor(hex: "24292e")! var cssColor = NSColor(hex: "24292e")!
var cssBackgroundColor = NSColor.white var cssBackgroundColor = NSColor.white
var cssA = NSColor(hex: "0366d6")! var cssA = NSColor(hex: "0366d6")!
@ -61,12 +67,14 @@ struct Theme: CustomStringConvertible {
var cssCodeColor = NSColor(hex: "24292e")! var cssCodeColor = NSColor(hex: "24292e")!
var cssCodeBackgroundColor = NSColor(hex: "1b1f23")! var cssCodeBackgroundColor = NSColor(hex: "1b1f23")!
public var description: String { public var description: String {
"Theme<" + "Theme<" +
"fg: \(self.foreground.hex), bg: \(self.background.hex), " + "fg: \(self.foreground.hex), bg: \(self.background.hex), " +
"hl-fg: \(self.highlightForeground.hex), hl-bg: \(self.highlightBackground.hex)" + "hl-fg: \(self.highlightForeground.hex), hl-bg: \(self.highlightBackground.hex), " +
"dir-fg: \(self.directoryForeground.hex)," + "dir-fg: \(self.directoryForeground.hex), " +
"tab-bg: \(self.tabBackground.hex), tab-fg: \(self.tabForeground.hex)" + "tab-fg: \(self.tabForeground.hex), tab-bg: \(self.tabBackground.hex), " +
"tabfill-fg: \(self.tabBarForeground.hex), tabfill-bg: \(self.tabBarBackground.hex), " +
"tabsel-bg: \(self.selectedTabBackground.hex), tabsel-fg: \(self.selectedTabForeground.hex)" +
">" ">"
} }
@ -84,6 +92,12 @@ struct Theme: CustomStringConvertible {
self.tabBackground = nvimTheme.tabBackground self.tabBackground = nvimTheme.tabBackground
self.tabForeground = nvimTheme.tabForeground self.tabForeground = nvimTheme.tabForeground
self.tabBarBackground = nvimTheme.tabBarBackground
self.tabBarForeground = nvimTheme.tabBarForeground
self.selectedTabBackground = nvimTheme.selectedTabBackground
self.selectedTabForeground = nvimTheme.selectedTabForeground
self.updateCssColors(additionalColorDict) self.updateCssColors(additionalColorDict)
} }