Skip to content

Commit

Permalink
Revert "Re-do some of the internal config to pass config table into i…
Browse files Browse the repository at this point in the history
…nternal"

This reverts commit 8e2a1bb.
  • Loading branch information
CKolkey committed Oct 14, 2024
1 parent df4d61d commit eda716c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 105 deletions.
6 changes: 3 additions & 3 deletions lua/neogit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ function M.setup(opts)
M.notification = require("neogit.lib.notification")

config.setup(opts)
hl.setup(config.values)
signs.setup(config.values)
state.setup(config.values)
hl.setup()
signs.setup()
state.setup()
autocmds.setup()
end

Expand Down
54 changes: 8 additions & 46 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,9 @@ end
---@field bisect NeogitConfigSection|nil

---@class HighlightOptions
---@field italic? boolean
---@field bold? boolean
---@field underline? boolean
---@field bg0? string Darkest background color
---@field bg1? string Second darkest background color
---@field bg2? string Second lightest background color
---@field bg3? string Lightest background color
---@field grey? string middle grey shade for foreground
---@field white? string Foreground white (main text)
---@field red? string Foreground red
---@field bg_red? string Background red
---@field line_red? string Cursor line highlight for red regions, like deleted hunks
---@field orange? string Foreground orange
---@field bg_orange? string background orange
---@field yellow? string Foreground yellow
---@field bg_yellow? string background yellow
---@field green? string Foreground green
---@field bg_green? string Background green
---@field line_green? string Cursor line highlight for green regions, like added hunks
---@field cyan? string Foreground cyan
---@field bg_cyan? string Background cyan
---@field blue? string Foreground blue
---@field bg_blue? string Background blue
---@field purple? string Foreground purple
---@field bg_purple? string Background purple
---@field md_purple? string Background _medium_ purple. Lighter than bg_purple. Used for hunk headers.
---@field italic? boolean
---@field bold? boolean
---@field underline? boolean

---@class NeogitFilewatcherConfig
---@field enabled boolean
Expand Down Expand Up @@ -351,7 +328,11 @@ function M.get_default_values()
["gitlab.com"] = "https://gitlab.com/${owner}/${repository}/merge_requests/new?merge_request[source_branch]=${branch_name}",
["azure.com"] = "https://dev.azure.com/${owner}/_git/${repository}/pullrequestcreate?sourceRef=${branch_name}&targetRef=${target}",
},
highlight = {},
highlight = {
italic = true,
bold = true,
underline = true,
},
disable_insert_on_commit = "auto",
use_per_project_settings = true,
remember_settings = true,
Expand Down Expand Up @@ -774,24 +755,6 @@ function M.validate_config()
end
end

local function validate_highlights()
if not validate_type(config.highlight, "highlight", "table") then
return
end

for field, value in ipairs(config.highlight) do
if field == "bold" or field == "italic" or field == "underline" then
validate_type(value, string.format("highlight.%s", field), "boolean")
else
validate_type(value, string.format("highlight.%s", field), "string")

if not string.match(value, "#%x%x%x%x%x%x") then
err("highlight", string.format("Color value is not valid CSS: %s", value))
end
end
end
end

local function validate_ignored_settings()
if not validate_type(config.ignored_settings, "ignored_settings", "table") then
return
Expand Down Expand Up @@ -1148,7 +1111,6 @@ function M.validate_config()
validate_sections()
validate_ignored_settings()
validate_mappings()
validate_highlights()
end

return errors
Expand Down
48 changes: 9 additions & 39 deletions lua/neogit/lib/hl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,9 @@ local function get_bg(name)
end
end

---@class NeogitColorPalette
---@field bg0 string Darkest background color
---@field bg1 string Second darkest background color
---@field bg2 string Second lightest background color
---@field bg3 string Lightest background color
---@field grey string middle grey shade for foreground
---@field white string Foreground white (main text)
---@field red string Foreground red
---@field bg_red string Background red
---@field line_red string Cursor line highlight for red regions, like deleted hunks
---@field orange string Foreground orange
---@field bg_orange string background orange
---@field yellow string Foreground yellow
---@field bg_yellow string background yellow
---@field green string Foreground green
---@field bg_green string Background green
---@field line_green string Cursor line highlight for green regions, like added hunks
---@field cyan string Foreground cyan
---@field bg_cyan string Background cyan
---@field blue string Foreground blue
---@field bg_blue string Background blue
---@field purple string Foreground purple
---@field bg_purple string Background purple
---@field md_purple string Background _medium_ purple. Lighter than bg_purple.
---@field italic boolean enable italics?
---@field bold boolean enable bold?
---@field underline boolean enable underline?

-- stylua: ignore start
---@param config NeogitConfig
---@return NeogitColorPalette
local function make_palette(config)
local function make_palette()
local bg = Color.from_hex(get_bg("Normal") or (vim.o.bg == "dark" and "#22252A" or "#eeeeee"))
local fg = Color.from_hex((vim.o.bg == "dark" and "#fcfcfc" or "#22252A"))
local red = Color.from_hex(get_fg("Error") or "#E06C75")
Expand All @@ -97,9 +68,11 @@ local function make_palette(config)
local blue = Color.from_hex(get_fg("Macro") or "#82AAFF")
local purple = Color.from_hex(get_fg("Include") or "#C792EA")

local config = require("neogit.config")

local bg_factor = vim.o.bg == "dark" and 1 or -1

local default = {
return {
bg0 = bg:to_css(),
bg1 = bg:shade(bg_factor * 0.019):to_css(),
bg2 = bg:shade(bg_factor * 0.065):to_css(),
Expand All @@ -123,12 +96,10 @@ local function make_palette(config)
purple = purple:to_css(),
bg_purple = purple:shade(bg_factor * -0.18):to_css(),
md_purple = purple:shade(0.18):to_css(),
italic = true,
bold = true,
underline = true,
italic = config.values.highlight.italic,
bold = config.values.highlight.bold,
underline = config.values.highlight.underline
}

return vim.tbl_extend("keep", config.highlight, default)
end
-- stylua: ignore end

Expand All @@ -144,9 +115,8 @@ local function is_set(hl_name)
return not vim.tbl_isempty(hl)
end

---@param config NeogitConfig
function M.setup(config)
local palette = make_palette(config)
function M.setup()
local palette = make_palette()

-- stylua: ignore
hl_store = {
Expand Down
7 changes: 4 additions & 3 deletions lua/neogit/lib/signs.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local config = require("neogit.config")
local M = {}

local signs = { NeogitBlank = " " }
Expand All @@ -11,9 +12,9 @@ function M.get(name)
end
end

function M.setup(config)
if not config.disable_signs then
for key, val in pairs(config.signs) do
function M.setup()
if not config.values.disable_signs then
for key, val in pairs(config.values.signs) do
if key == "hunk" or key == "item" or key == "section" then
signs["NeogitClosed" .. key] = val[1]
signs["NeogitOpen" .. key] = val[2]
Expand Down
21 changes: 7 additions & 14 deletions lua/neogit/lib/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ local logger = require("neogit.logger")
local config = require("neogit.config")
local Path = require("plenary.path")

---@class NeogitState
---@field loaded boolean
---@field _enabled boolean
---@field state table
---@field path Path
local M = {}

M.loaded = false
Expand All @@ -16,40 +11,38 @@ local function log(message)
end

---@return Path
function M.filepath(config)
function M.filepath()
local state_path = Path.new(vim.fn.stdpath("state")):joinpath("neogit")
local filename = "state"

if config.use_per_project_settings then
if config.values.use_per_project_settings then
filename = vim.uv.cwd():gsub("^(%a):", "/%1"):gsub("/", "%%"):gsub(Path.path.sep, "%%")
end

return state_path:joinpath(filename)
end

---Initializes state
---@param config NeogitConfig
function M.setup(config)
function M.setup()
if M.loaded then
return
end

M.path = M.filepath(config)
M._enabled = config.remember_settings
M.state = M.read()
M.path = M.filepath()
M.loaded = true
M.state = M.read()
log("Loaded")
end

---@return boolean
function M.enabled()
return M.loaded and M._enabled
return M.loaded and config.values.remember_settings
end

---Reads state from disk
---@return table
function M.read()
if not M.enabled then
if not M.enabled() then
return {}
end

Expand Down

0 comments on commit eda716c

Please sign in to comment.