Skip to content

Commit

Permalink
feat: new borderless minimalistic profile (#760)
Browse files Browse the repository at this point in the history
other changes includes:
- 2 new border styles `thiccc` and `thicccc`
- refactored acquiring hexcolor from hl group
- fixed fzf_colors hls that link to default colormaps
- commit command formatting in defaults.lua
  • Loading branch information
ibhagwan committed Jun 25, 2023
1 parent 7aff4a3 commit ca37576
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ require'fzf-lua'.setup {
-- border argument passthrough to nvim_open_win(), also used
-- to manually draw the border characters around the preview
-- window, can be set to 'false' to remove all borders or to
-- 'none', 'single', 'double', 'thicc' or 'rounded' (default)
-- 'none', 'single', 'double', 'thicc' (+cc) or 'rounded' (default)
border = { '', '', '', '', '', '', '', '' },
-- requires neovim > v0.9.0, passed as is to `nvim_open_win`
-- can be sent individually to any provider to set the win title
Expand Down
8 changes: 4 additions & 4 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,13 @@ M.create_fzf_colors = function(opts)
end
if not colors then return end

local colormap = vim.api.nvim_get_color_map()
local tbl = {}
for highlight, list in pairs(colors) do
if type(list) == "table" then
local value = M.get_color(list[2], list[1])
local col = value:match("#[%x]+") or value:match("^[0-9]+")
if col then
table.insert(tbl, ("%s:%s"):format(highlight, col))
local hexcol = utils.hexcol_from_hl(list[2], list[1], colormap)
if hexcol and #hexcol > 0 then
table.insert(tbl, ("%s:%s"):format(highlight, hexcol))
end
-- arguments in the 3rd slot onward are passed raw, this can
-- be used to pass styling arguments, for more info see #413
Expand Down
35 changes: 20 additions & 15 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ M.defaults = {
["double"] = { "", "", "", "", "", "", "", "" },
["rounded"] = { "", "", "", "", "", "", "", "" },
["thicc"] = { "", "", "", "", "", "", "", "" },
["thiccc"] = { "", "", "", "", "", "", "", "" },
["thicccc"] = { "", "", "", "", "", "", "", "" },
},
on_create = function()
-- vim.cmd("set winhl=Normal:Normal,FloatBorder:Normal")
Expand Down Expand Up @@ -256,22 +258,23 @@ M.defaults.git = {
},
},
commits = {
prompt = "Commits> ",
cmd = "git log --color --pretty=format:'%C(yellow)%h%Creset %Cgreen(%><(12)%cr%><|(12))" ..
"%Creset %s %C(blue)<%an>%Creset'",
preview = "git show --pretty='%Cred%H%n%Cblue%an <%ae>%n%C(yellow)%cD%n%Cgreen%s' --color {1}",
actions = {
prompt = "Commits> ",
cmd = "git log --color --pretty=format:'%C(yellow)%h%Creset "
.. "%Cgreen(%><(12)%cr%><|(12))%Creset %s %C(blue)<%an>%Creset'",
preview = "git show --pretty='%Cred%H%n%Cblue%an <%ae>%n%C(yellow)%cD%n%Cgreen%s'"
.. " --color {1}",
actions = {
["default"] = actions.git_checkout,
["ctrl-y"] = { fn = actions.git_yank_commit, exec_silent = true },
},
fzf_opts = { ["--no-multi"] = "" },
},
bcommits = {
prompt = "BCommits> ",
cmd = "git log --color --pretty=format:'%C(yellow)%h%Creset %Cgreen(%><(12)%cr%><|(12))" ..
"%Creset %s %C(blue)<%an>%Creset' <file>",
preview = "git diff --color {1}~1 {1} -- <file>",
actions = {
prompt = "BCommits> ",
cmd = "git log --color --pretty=format:'%C(yellow)%h%Creset "
.. "%Cgreen(%><(12)%cr%><|(12))%Creset %s %C(blue)<%an>%Creset' <file>",
preview = "git diff --color {1}~1 {1} -- <file>",
actions = {
["default"] = actions.git_buf_edit,
["ctrl-s"] = actions.git_buf_split,
["ctrl-v"] = actions.git_buf_vsplit,
Expand Down Expand Up @@ -326,10 +329,12 @@ M.defaults.grep = {
git_icons = true,
fzf_opts = { ["--info"] = "default", },
grep_opts = utils.is_darwin()
and "--binary-files=without-match --line-number --recursive --color=always --extended-regexp -e"
or "--binary-files=without-match --line-number --recursive --color=always --perl-regexp -e",
rg_opts = "--column --line-number --no-heading --color=always --smart-case " ..
"--max-columns=4096 -e",
and "--binary-files=without-match --line-number --recursive --color=always "
.. "--extended-regexp -e"
or "--binary-files=without-match --line-number --recursive --color=always "
.. "--perl-regexp -e",
rg_opts = "--column --line-number --no-heading --color=always --smart-case "
.. "--max-columns=4096 -e",
_actions = function() return M.globals.actions.files end,
actions = { ["ctrl-g"] = { actions.grep_lgrep } },
-- live_grep_glob options
Expand Down Expand Up @@ -613,7 +618,7 @@ M.defaults.lsp.finder = {
git_icons = false,
async = true,
silent = true,
separator = "| ",
separator = "|" .. utils.nbsp,
_actions = function() return M.globals.actions.files end,
-- currently supported providers, defined as map so we can query easily
_providers = {
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/profiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ telescope defaults with `bat` previewer:
| `max-perf` | similar to `fzf-native` and disables icons globally for max performance |
| `telescope` | closest match to telescope defaults in look and feel and keybinds |
| `skim` | uses [`skim`](https://github.com/lotabout/skim) as an fzf alternative, (requires the `sk` binary) |
| `borderless` | borderless and minimalistic seamless look &amp; feel |


**Custom user settings which make sense and aren't mere duplications with minimal modifications
Expand Down
36 changes: 36 additions & 0 deletions lua/fzf-lua/profiles/borderless.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local hls = {
bg = "PmenuSbar",
sel = "PmenuSel",
}
return {
desc = "borderless and minimalistic",
global_git_icons = false,
global_file_icons = false,
fzf_opts = {},
winopts = {
-- border = "none",
-- border = "thicccc",
border = { " ", " ", " ", " ", " ", " ", " ", " " },
preview = {
scrollbar = "float",
scrolloff = "-2",
title_align = "center",
},
hl = {
title = hls.sel,
border = hls.bg,
preview_border = hls.bg,
scrollfloat_e = hls.bg,
scrollfloat_f = hls.sel,
-- TODO: not working with `scrollbar = "border"` when `border = "none"
-- scrollborder_f = "@function",
},
},
fzf_colors = {
["gutter"] = { "bg", hls.bg },
["bg"] = { "bg", hls.bg },
["bg+"] = { "bg", hls.sel },
["fg+"] = { "fg", hls.sel },
-- ["fg+"] = { "fg", "", "reverse:-1" },
},
}
26 changes: 16 additions & 10 deletions lua/fzf-lua/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,21 @@ function M.is_hl_cleared(hl)
end
end

function M.hexcol_from_hl(hlgroup, what, colormap)
if not hlgroup or not what then return end
local hexcol = synIDattr(hlgroup, what)
if hexcol and not hexcol:match("^#") and colormap then
-- try to acquire the color from the map
-- some schemes don't capitalize first letter?
local col = colormap[hexcol:sub(1, 1):upper() .. hexcol:sub(2)]
if col then
-- format as 6 digit hex for hex2rgb()
hexcol = ("#%06x"):format(col)
end
end
return hexcol
end

function M.ansi_from_hl(hl, s, colormap)
if vim.fn.hlexists(hl) == 1 then
-- https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#rgb-colors
Expand All @@ -405,16 +420,7 @@ function M.ansi_from_hl(hl, s, colormap)
for w, p in pairs(what) do
local escseq = nil
if p.rgb then
local hexcol = synIDattr(hl, w)
if hexcol and not hexcol:match("^#") and colormap then
-- try to acquire the color from the map
-- some schemes don't capitalize first letter?
local col = colormap[hexcol:sub(1, 1):upper() .. hexcol:sub(2)]
if col then
-- format as 6 digit hex for hex2rgb()
hexcol = ("#%06x"):format(col)
end
end
local hexcol = M.hexcol_from_hl(hl, w, colormap)
local r, g, b = hex2rgb(hexcol)
if r and g and b then
escseq = ("[%d;2;%d;%d;%dm"):format(p.code, r, g, b)
Expand Down

0 comments on commit ca37576

Please sign in to comment.