Skip to content

Commit

Permalink
Merge pull request #1059 from s-daveb/master
Browse files Browse the repository at this point in the history
Modify theming code: custom tab theme is now pulled from TablineSel highlight group
  • Loading branch information
qvacua authored May 17, 2024
2 parents e25a6b5 + 949022e commit 129173b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion NvimView/Sources/NvimView/NvimView+Resize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension NvimView {
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))
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
Expand Down
10 changes: 8 additions & 2 deletions NvimView/Sources/NvimView/NvimView+Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ public extension NvimView {
public var visualBackground = NSColor.selectedContentBackgroundColor

public var directoryForeground = NSColor.textColor


public var tabForeground = NSColor.textColor
public var tabBackground = NSColor.textBackgroundColor

public init() {}

public init(_ values: [Int]) {
if values.count < 5 { preconditionFailure("We need 5 colors!") }
if values.count < 7 { preconditionFailure("We need 7 colors!") }

let color = ColorUtils.colorIgnoringAlpha

Expand All @@ -118,12 +121,15 @@ 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])
}

public var description: String {
"NVV.Theme<" +
"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)" +
">"
}
}
Expand Down
2 changes: 1 addition & 1 deletion NvimView/Sources/NvimView/NvimView+UiBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ extension NvimView {

private func colorSchemeChanged(_ value: MessagePackValue) {
guard let values = MessagePackUtils.array(
from: value, ofSize: 5, conversion: { $0.intValue }
from: value, ofSize: 7, conversion: { $0.intValue }
) else {
self.bridgeLogger.error("Could not convert \(value)")
return
Expand Down
4 changes: 2 additions & 2 deletions Tabs/Sources/Tabs/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ extension Tab {

private func adjustColors(_ newIsSelected: Bool) {
if newIsSelected {
self.layer?.backgroundColor = self.theme.selectedBackgroundColor.cgColor
self.titleView.textColor = self.theme.selectedForegroundColor
self.layer?.backgroundColor = self.theme.tabBackgroundColor.cgColor
self.titleView.textColor = self.theme.tabForegroundColor
self.closeButton.image = self.theme.selectedCloseButtonImage
} else {
self.layer?.backgroundColor = self.theme.backgroundColor.cgColor
Expand Down
12 changes: 7 additions & 5 deletions Tabs/Sources/Tabs/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public struct Theme {
didSet {
self.selectedCloseButtonImage = Icon.close.asImage(
dimension: self.iconDimension.width,
color: self.selectedForegroundColor
color: self.tabForegroundColor
)
}
}

public var selectedBackgroundColor = NSColor.selectedTextBackgroundColor

public var tabSelectedIndicatorColor = NSColor.selectedTextColor

public var tabBackgroundColor = NSColor.selectedTextBackgroundColor
public var tabForegroundColor = NSColor.selectedTextColor

public var titleFont = NSFont.systemFont(ofSize: 11)
public var selectedTitleFont = NSFont.boldSystemFont(ofSize: 11)

Expand All @@ -58,12 +60,12 @@ public struct Theme {
public init() {
self.closeButtonImage = Icon.close.asImage(
dimension: self.iconDimension.width,
color: self.foregroundColor
color: self.tabForegroundColor

)

self.selectedCloseButtonImage = Icon.close.asImage(
dimension: self.iconDimension.width,
color: self.selectedForegroundColor
color: self.tabForegroundColor
)
}
}
3 changes: 3 additions & 0 deletions VimR/VimR/MainWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ final class MainWindow: NSObject,

tabsTheme.selectedForegroundColor = self.theme.highlightForeground
tabsTheme.selectedBackgroundColor = self.theme.highlightBackground

tabsTheme.tabBackgroundColor = self.theme.tabBackground;
tabsTheme.tabForegroundColor = self.theme.tabForeground;

tabsTheme.tabSelectedIndicatorColor = self.theme.highlightForeground

Expand Down
11 changes: 9 additions & 2 deletions VimR/VimR/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ struct Theme: CustomStringConvertible {
var highlightBackground = NSColor.selectedContentBackgroundColor

var directoryForeground = NSColor.textColor

var tabForeground = NSColor.selectedMenuItemTextColor
var tabBackground = NSColor.selectedContentBackgroundColor

var cssColor = NSColor(hex: "24292e")!
var cssBackgroundColor = NSColor.white
Expand All @@ -62,7 +65,8 @@ struct Theme: CustomStringConvertible {
"Theme<" +
"fg: \(self.foreground.hex), bg: \(self.background.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)" +
">"
}

Expand All @@ -76,7 +80,10 @@ struct Theme: CustomStringConvertible {
self.highlightBackground = nvimTheme.visualBackground

self.directoryForeground = nvimTheme.directoryForeground


self.tabBackground = nvimTheme.tabBackground
self.tabForeground = nvimTheme.tabForeground

self.updateCssColors(additionalColorDict)
}

Expand Down

0 comments on commit 129173b

Please sign in to comment.