Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify theming code: custom tab theme is now pulled from TablineSel highlight group #1059

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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