1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-08-17 20:50:22 +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.")
}
// swiftformat:disable all
return self.api.nvimExec2(src: """
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', 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))
autocmd VimEnter * call rpcrequest(\(channel), 'vimenter')
""", opts: [:], errWhenBlocked: false)
// swiftformat:enable all
.asCompletable()
// swiftformat:disable all
let vimscript = """
function! GetHiColor(hlID, component)
let color = synIDattr(synIDtrans(hlID(a:hlID)), a:component)
if empty(color)
return -1
else
return str2nr(color[1:], 16)
endif
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(

View File

@ -94,7 +94,8 @@ public extension NvimView {
public var foreground = NSColor.textColor
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
// NSVisualEffectView.Material.selection should be used instead, but I don't know how to get
// an NSColor from it.
@ -102,13 +103,19 @@ public extension NvimView {
public var directoryForeground = NSColor.textColor
public var tabForeground = NSColor.textColor
public var tabBackground = NSColor.textBackgroundColor
public var tabForeground = NSColor.controlColor
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(_ values: [Int]) {
if values.count < 7 { preconditionFailure("We need 7 colors!") }
if values.count < 11 { preconditionFailure("We need 11 colors!") }
let color = ColorUtils.colorIgnoringAlpha
@ -121,8 +128,16 @@ public extension NvimView {
self.directoryForeground = values[4] < 0
? Theme.default.directoryForeground
: 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 {
@ -130,6 +145,8 @@ public extension NvimView {
"fg: \(self.foreground.hex), bg: \(self.background.hex), " +
"visual-fg: \(self.visualForeground.hex), visual-bg: \(self.visualBackground.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) {
guard let values = MessagePackUtils.array(
from: value, ofSize: 7, conversion: { $0.intValue }
from: value, ofSize: 11, conversion: { $0.intValue }
) else {
self.bridgeLogger.error("Could not convert \(value)")
return

View File

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

View File

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

View File

@ -9,6 +9,8 @@ import MaterialIcons
public struct Theme {
public static let `default` = Self()
public var separatorColor = NSColor.gridColor
public var backgroundColor = NSColor.textBackgroundColor
public var foregroundColor = NSColor.textColor {
didSet {
self.closeButtonImage = Icon.close.asImage(
@ -17,25 +19,21 @@ public struct Theme {
)
}
}
public var backgroundColor = NSColor.textBackgroundColor
public var separatorColor = NSColor.gridColor
public var selectedBackgroundColor = NSColor.selectedTextBackgroundColor
public var selectedForegroundColor = NSColor.selectedTextColor {
didSet {
self.selectedCloseButtonImage = Icon.close.asImage(
dimension: self.iconDimension.width,
color: self.tabForegroundColor
color: self.selectedForegroundColor
)
}
}
public var selectedBackgroundColor = NSColor.selectedTextBackgroundColor
public var tabSelectedIndicatorColor = NSColor.selectedTextColor
public var tabBackgroundColor = NSColor.selectedTextBackgroundColor
public var tabForegroundColor = NSColor.selectedTextColor
public var tabBarBackgroundColor = NSColor.windowBackgroundColor
public var tabBarForegroundColor = NSColor.textColor
public var titleFont = NSFont.systemFont(ofSize: 11)
public var selectedTitleFont = NSFont.boldSystemFont(ofSize: 11)
@ -60,12 +58,11 @@ public struct Theme {
public init() {
self.closeButtonImage = Icon.close.asImage(
dimension: self.iconDimension.width,
color: self.tabForegroundColor
color: self.foregroundColor
)
self.selectedCloseButtonImage = Icon.close.asImage(
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) {
var tabsTheme = Tabs.Theme.default
tabsTheme.foregroundColor = self.theme.foreground
tabsTheme.backgroundColor = self.theme.background
tabsTheme.foregroundColor = self.theme.tabForeground
tabsTheme.backgroundColor = self.theme.tabBackground
tabsTheme.separatorColor = self.theme.background.brightening(by: 0.75)
tabsTheme.selectedForegroundColor = self.theme.highlightForeground
tabsTheme.selectedBackgroundColor = self.theme.highlightBackground
tabsTheme.tabBarBackgroundColor = self.theme.tabBarBackground
tabsTheme.tabBarForegroundColor = self.theme.tabBarForeground
tabsTheme.tabBackgroundColor = self.theme.tabBackground
tabsTheme.tabForegroundColor = self.theme.tabForeground
tabsTheme.selectedForegroundColor = self.theme.selectedTabForeground
tabsTheme.selectedBackgroundColor = self.theme.selectedTabBackground
tabsTheme.tabSelectedIndicatorColor = self.theme.highlightForeground

View File

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