Skip to content

Commit

Permalink
feat: use setup function
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Setup and configuration now requires using the `setup` function
  • Loading branch information
monsonjeremy committed Jul 28, 2021
1 parent 53713a9 commit cc6964d
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 77 deletions.
63 changes: 35 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ Enable the colorscheme:

```vim
" Vim Script
colorscheme onedark
lua require('onedark').setup()
```

```lua
-- Lua
vim.cmd[[colorscheme onedark]]
require('onedark').setup()
```

To enable the `onedark` theme for `Lualine`, simply specify it in your lualine settings:
Expand All @@ -89,39 +89,40 @@ let g:lightline = {'colorscheme': 'onedark'}

> ❗️ configuration needs to be set **BEFORE** loading the color scheme with `colorscheme onedark`
| Option | Default | Description |
| -------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| onedark_italic_comments | `true` | Make comments italic |
| onedark_italic_keywords | `true` | Make keywords italic |
| onedark_italic_functions | `false` | Make functions italic |
| onedark_italic_variables | `false` | Make variables and identifiers italic |
| onedark_transparent | `false` | Enable this to disable setting the background color |
| onedark_hide_inactive_statusline | `false` | Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine** and **LuaLine**. |
| onedark_hide_nontext | `false` | Enabling this option, will hide filler lines (~) after the end of the buffer |
| onedark_sidebars | `{}` | Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]` |
| onedark_dark_sidebar | `true` | Sidebar like windows like `NvimTree` get a darker background |
| onedark_dark_float | `true` | Float windows like the lsp diagnostics windows get a darker background. |
| onedark_colors | `{}` | You can override specific color groups to use other groups or a hex color |
| Option | Default | Description |
| ---------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| commentStyle | `italic` | Highlight style for comments (check `:help highlight-args` for options) |
| keywordStyle | `italic` | Highlight style for keywords (check `:help highlight-args` for options) |
| functionStyle | `NONE` | Highlight style for functions (check `:help highlight-args` for options) |
| variableStyle | `NONE` | Highlight style for variables and identifiers (check `:help highlight-args` for options) |
| transparent | `false` | Enable this to disable setting the background color |
| hideInactiveStatusline | `false` | Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine** and **LuaLine**. |
| sidebars | `{}` | Set a darker background on sidebar-like windows. For example: `{"qf", "vista_kind", "terminal", "packer"}` |
| darkSidebar | `true` | Sidebar like windows like `NvimTree` get a darker background |
| darkFloat | `true` | Float windows like the lsp diagnostics windows get a darker background. |
| colors | `{}` | You can override specific color groups to use other groups or a hex color |

```lua
-- Example config in Lua
vim.g.onedark_italic_functions = true
vim.g.onedark_sidebars = { "qf", "vista_kind", "terminal", "packer" }
require("onedark").setup({
functionStyle = "italic",
sidebars = {"qf", "vista_kind", "terminal", "packer"},

-- Change the "hint" color to the "orange" color, and make the "error" color bright red
vim.g.onedark_colors = { hint = "orange", error = "#ff0000" }

-- Load the colorscheme
vim.cmd[[colorscheme onedark]]
-- Change the "hint" color to the "orange" color, and make the "error" color bright red
colors = {hint = "orange", error = "#ff0000"}
})
```

```vim
" Example config in VimScript
let g:onedark_italic_functions = 1
let g:onedark_sidebars = [ "qf", "vista_kind", "terminal", "packer" ]
" Load the colorscheme
colorscheme onedark
" Example config in vimscript
lua << EOF
require("onedark").setup({
functionStyle = "italic",
sidebars = {"qf", "vista_kind", "terminal", "packer"},
-- Change the "hint" color to the "orange" color, and make the "error" color bright red
colors = {hint = "orange", error = "#ff0000"}
})
```

### Making `undercurls` work properly in **Tmux**
Expand All @@ -140,3 +141,9 @@ set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{25
Extra color configs for **Kitty**, and **Alacritty** can be found in [extras](extras/). To use them, refer to their respective documentation.

<img width="825" alt="Screen Shot 2021-05-23 at 2 49 57 PM" src="https://user-images.githubusercontent.com/8846086/119279221-23f08b00-bbdf-11eb-885e-c2c238aa1c04.png">

## Support

<a href="https://www.buymeacoffee.com/monsonjeremy" target="_blank">
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-violet.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" >
</a>
2 changes: 1 addition & 1 deletion colors/onedark.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
" lua package.loaded['onedark.util'] = nil
lua package.loaded['onedark.config'] = nil

lua require('onedark').colorscheme()
lua require('onedark').setup()
4 changes: 2 additions & 2 deletions lua/lualine/themes/onedark.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local config = require("onedark.config")
local colors = require("onedark.colors").setup(config)
local configModule = require("onedark.config")
local colors = require("onedark.colors").setup(configModule.config)

local onedark = {}

Expand Down
6 changes: 4 additions & 2 deletions lua/onedark/colors.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local util = require("onedark.util")
local configModule = require("onedark.config")

local M = {}

---@param config Config
---@return ColorScheme
function M.setup(config)
config = config or require("onedark.config")
config = config or configModule.config

-- Color Palette
---@class ColorScheme
Expand Down Expand Up @@ -35,6 +36,7 @@ function M.setup(config)
red1 = "#f65866",
git = { change = "#e0af68", add = "#109868", delete = "#9A353D", conflict = "#bb7a61" },
gitSigns = { change = "#e0af68", add = "#109868", delete = "#9A353D" },
diagnostics = { error = '#db4b4b', hint = "#1abc9c", info = "#0db9d7", warn = "#e0af68" }
}

util.bg = colors.bg
Expand Down Expand Up @@ -79,4 +81,4 @@ function M.setup(config)
return colors
end

return M
return M
73 changes: 53 additions & 20 deletions lua/onedark/config.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,67 @@
---@class Config
local config

local vimConfig = false

-- shim vim for kitty and other generators
vim = vim or { g = {}, o = {} }
vim = vim or {g = {}, o = {}}

local function opt(key, default)
key = "onedark_" .. key
if vim.g[key] == nil then
return default
else
vimConfig = true
if vim.g[key] == 0 then
return false
else
return vim.g[key]
end
end
if vim.g[key] == 0 then
return false
end
return vim.g[key]
end

local g = {
transparent = "onedark_transparent",
commentStyle = "onedark_italic_comments",
keywordStyle = "onedark_italic_keywords",
functionStyle = "onedark_italic_functions",
variableStyle = "onedark_italic_variables",
hideInactiveStatusline = "onedark_hide_inactive_statusline",
sidebars = "onedark_sidebars",
colors = "onedark_colors",
dev = "onedark_dev",
hideNonText = "onedark_hide_nontext",
darkFloat = "onedark_dark_float",
darkSidebar = "onedark_dark_sidebar"
}

config = {
transparent = opt("transparent", false),
commentStyle = opt("italic_comments", true) and "italic" or "NONE",
keywordStyle = opt("italic_keywords", true) and "italic" or "NONE",
functionStyle = opt("italic_functions", false) and "italic" or "NONE",
variableStyle = opt("italic_variables", false) and "italic" or "NONE",
hideInactiveStatusline = opt("hide_inactive_statusline", false),
hideNonText = opt("hide_nontext", true),
sidebars = opt("sidebars", {}),
colors = opt("colors", {}),
dev = opt("dev", false),
darkFloat = opt("dark_float", true),
darkSidebar = opt("dark_sidebar", true),
transform_colors = false,
transparent = opt(g.transparent, false),
commentStyle = opt(g.commentStyle, true) and "italic" or "NONE",
keywordStyle = opt(g.keywordStyle, true) and "italic" or "NONE",
functionStyle = opt(g.functionStyle, false) and "italic" or "NONE",
variableStyle = opt(g.variableStyle, false) and "italic" or "NONE",
hideInactiveStatusline = opt(g.hideInactiveStatusline, false),
sidebars = opt(g.sidebars, {}),
colors = opt(g.colors, {}),
dev = opt(g.dev, false),
hideNonText = opt(g.hideNonText, true),
darkFloat = opt(g.darkFloat, true),
darkSidebar = opt(g.darkSidebar, true),
transform_colors = false
}

return config
---@param userConfig Config
local function applyConfiguration(userConfig)
for key, value in pairs(userConfig) do
if value ~= nil then
if config[key] ~= nil then
config[key] = value
else
error("monsonjeremy/onedark: Option " .. key .. " does not exist") -- luacheck: ignore
end
end
end
end

return {config = config, vimConfig = vimConfig, applyConfiguration = applyConfiguration}

5 changes: 3 additions & 2 deletions lua/onedark/extra/alacritty.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local util = require("onedark.util")
local configModule = require("onedark.config")

local M = {}

function M.alacritty(config)
config = config or require("onedark.config")
config = config or configModule.config
config.transform_colors = true
local colors = require("onedark.colors").setup(config)

Expand Down Expand Up @@ -48,7 +49,7 @@ colors:
indexed_colors:
- { index: 16, color: '${orange}' }
- { index: 17, color: '${red1}' }
]],
alacrittyColors
)
Expand Down
4 changes: 2 additions & 2 deletions lua/onedark/extra/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package.path = "./lua/?/init.lua;./lua/?.lua"

local config = require("onedark.config")
local configModule = require("onedark.config")

local function write(str, fileName)
print("[write] extra/" .. fileName)
Expand All @@ -12,5 +12,5 @@ end
local extras = { kitty = "conf", alacritty = "yml" }
for extra, ext in pairs(extras) do
local plugin = require("onedark.extra." .. extra)
write(plugin[extra](config), extra .. "_onedark_" .. "." .. ext)
write(plugin[extra](configModule.config), extra .. "_onedark_" .. "." .. ext)
end
13 changes: 7 additions & 6 deletions lua/onedark/extra/kitty.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
local util = require("onedark.util")
local configModule = require("onedark.config")

local M = {}

function M.kitty(config)
config = config or require("onedark.config")
config = config or configModule.config
config.transform_colors = true
local colors = require("onedark.colors").setup(config)

local kitty = util.template(
[[
# onedark colors for Kitty
background ${bg}
foreground ${fg}
selection_background ${bg_visual}
selection_foreground ${fg}
url_color ${green}
cursor ${fg}
# Tabs
active_tab_background ${bg}
active_tab_foreground ${fg}
inactive_tab_background ${bg_highlight}
inactive_tab_foreground ${fg_gutter}
#tab_bar_background ${black}
# normal
color0 ${black}
color1 ${red}
Expand All @@ -34,7 +35,7 @@ function M.kitty(config)
color5 ${purple}
color6 ${cyan}
color7 ${fg_dark}
# bright
color8 ${fg_gutter}
color9 ${red}
Expand All @@ -44,7 +45,7 @@ function M.kitty(config)
color13 ${purple}
color14 ${cyan}
color15 ${fg}
# extended colors
color16 ${orange}
color17 ${red1}
Expand Down
11 changes: 7 additions & 4 deletions lua/onedark/init.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
local util = require("onedark.util")
local theme = require("onedark.theme")
local configModule = require("onedark.config")

local M = {}
local function setup(userConfig)
-- Applying user configuration
if userConfig then configModule.applyConfiguration(userConfig) end

function M.colorscheme()
util.load(theme.setup())
-- Load colorscheme
util.load(theme.setup(configModule.config))
end

return M
return {setup = setup}
21 changes: 11 additions & 10 deletions lua/onedark/theme.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
local util = require("onedark.util")
local colors = require("onedark.colors")
local configModule = require("onedark.config")

local M = {}

---@param config Config
---@return Theme
function M.setup(config)
config = config or require("onedark.config")
config = config or configModule.config

---@class Theme
local theme = {}
Expand Down Expand Up @@ -162,15 +163,15 @@ function M.setup(config)
LspDiagnosticsDefaultInformation = { fg = c.info }, -- Used as the base highlight group. Other LspDiagnostic highlights link to this by default (except Underline)
LspDiagnosticsDefaultHint = { fg = c.hint }, -- Used as the base highlight group. Other LspDiagnostic highlights link to this by default (except Underline)

LspDiagnosticsVirtualTextError = { bg = util.darken(c.error, 0.1), fg = c.error }, -- Used for "Error" diagnostic virtual text
LspDiagnosticsVirtualTextWarning = { bg = util.darken(c.warning, 0.1), fg = c.warning }, -- Used for "Warning" diagnostic virtual text
LspDiagnosticsVirtualTextInformation = { bg = util.darken(c.info, 0.1), fg = c.info }, -- Used for "Information" diagnostic virtual text
LspDiagnosticsVirtualTextHint = { bg = util.darken(c.hint, 0.1), fg = c.hint }, -- Used for "Hint" diagnostic virtual text
LspDiagnosticsVirtualTextError = { bg = c.none, fg = c.diagnostics.error }, -- Used for "Error" diagnostic virtual text
LspDiagnosticsVirtualTextWarning = { bg = c.none, fg = c.diagnostics.warning }, -- Used for "Warning" diagnostic virtual text
LspDiagnosticsVirtualTextInformation = { bg = c.none, fg = c.diagnostics.info }, -- Used for "Information" diagnostic virtual text
LspDiagnosticsVirtualTextHint = { bg = c.none, fg = c.diagnostics.hint }, -- Used for "Hint" diagnostic virtual text

LspDiagnosticsUnderlineError = { style = "undercurl", sp = c.error }, -- Used to underline "Error" diagnostics
LspDiagnosticsUnderlineWarning = { style = "undercurl", sp = c.warning }, -- Used to underline "Warning" diagnostics
LspDiagnosticsUnderlineInformation = { style = "undercurl", sp = c.info }, -- Used to underline "Information" diagnostics
LspDiagnosticsUnderlineHint = { style = "undercurl", sp = c.hint }, -- Used to underline "Hint" diagnostics
LspDiagnosticsUnderlineError = { style = "undercurl", sp = c.diagnostics.error }, -- Used to underline "Error" diagnostics
LspDiagnosticsUnderlineWarning = { style = "undercurl", sp = c.diagnostics.warning }, -- Used to underline "Warning" diagnostics
LspDiagnosticsUnderlineInformation = { style = "undercurl", sp = c.diagnostics.info }, -- Used to underline "Information" diagnostics
LspDiagnosticsUnderlineHint = { style = c.none, sp = c.diagnostics.hint }, -- Used to underline "Hint" diagnostics

LspSignatureActiveParameter = { fg = c.orange },

Expand Down Expand Up @@ -353,7 +354,7 @@ function M.setup(config)
}

if config.hideInactiveStatusline then
local inactive = { style = "underline", bg = c.bg, fg = c.bg, sp = c.border }
local inactive = {style = "underline", bg = c.bg, fg = c.bg, sp = c.bg_visual}

-- StatusLine
theme.base.StatusLineNC = inactive
Expand Down

0 comments on commit cc6964d

Please sign in to comment.