Skip to content

Commit

Permalink
Add extended branch character support
Browse files Browse the repository at this point in the history
  • Loading branch information
rbong committed Jul 31, 2024
1 parent a02510a commit e3d47e0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 12 deletions.
1 change: 1 addition & 0 deletions autoload/flog/graph/nvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function! flog#graph#nvim#Get(git_cmd) abort
\ v:true,
\ v:true,
\ g:flog_commit_start_token,
\ g:flog_enable_extended_chars ? v:true : v:false,
\ state.opts.graph ? v:true : v:false,
\ state.opts.default_collapsed ? v:true : v:false,
\ a:git_cmd,
Expand Down
10 changes: 10 additions & 0 deletions doc/flog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,16 @@ g:flog_get_author_args *g:flog_get_author_args*

See also "git shortlog --help".

g:flog_enable_extended_chars *g:flog_enable_extended_chars*

Whether to enable experimental extra characters in the commit graph.

These are special Unicode characters U+F5D0 through U+F5FB made specifically
for drawing Git branches.

For best results, requires terminal support. Currently supported by the Kitty
terminal.

g:flog_commit_start_token *g:flog_commit_start_token*

The internal token to use to find commit start. Provided as an option in
Expand Down
28 changes: 28 additions & 0 deletions lua/flog/graph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ local function flog_get_graph(
enable_nvim,
enable_porcelain,
start_token,
enable_extended_chars,
enable_graph,
default_collapsed,
cmd,
collapsed_commits)
-- Resolve Vim values
enable_graph = enable_graph and enable_graph ~= 0
default_collapsed = default_collapsed and default_collapsed ~= 0
enable_extended_chars = enable_extended_chars and enable_extended_chars ~= 0

-- Init graph characters
local branch_ch = ''
Expand All @@ -42,6 +44,32 @@ local function flog_get_graph(
local merge_fork_branch_ch = ''
local empty_ch = ' '

-- Init extended graph characters
if enable_extended_chars then
branch_ch = ''
horizontal_line_ch = ''
branch_fade_ch = ''
upper_left_corner_ch = ''
upper_right_corner_ch = ''
lower_left_corner_ch = ''
lower_right_corner_ch = ''
disconnected_commit_ch = ''
initial_commit_ch = ''
branch_commit_ch = ''
branch_merge_commit_ch = ''
branch_tip_commit_ch = ''
branch_tip_merge_commit_ch = ''
merge_left_ch = ''
merge_right_ch = ''
merge_up_ch = ''
merge_branch_left_ch = ''
fork_branch_left_ch = ''
merge_branch_right_ch = ''
fork_branch_right_ch = ''
merge_up_branch_ch = ''
merge_fork_branch_ch = ''
end

-- Init padded strings
local branch_str = branch_ch .. ' '
local branch_fade_str = branch_fade_ch .. ' '
Expand Down
8 changes: 5 additions & 3 deletions lua/flog/graph_bin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ flog_get_graph(
true,
-- start_token
arg[1],
-- enable_extended_chars
arg[2],
-- enable_graph
arg[2] == 'true',
-- default_collapsed
arg[3] == 'true',
-- default_collapsed
arg[4] == 'true',
-- cmd
arg[4],
arg[5],
-- collapsed_commits
{})
2 changes: 2 additions & 0 deletions plugin/flog.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let g:flog_write_commit_graph_args = '--reachable --progress'

let g:flog_enable_status = v:false

let g:flog_enable_extended_chars = v:false

let g:flog_check_lua_version = v:true

let g:flog_get_author_args = '--all --no-merges --max-count=100000'
Expand Down
5 changes: 5 additions & 0 deletions plugin/flog_graph_vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def g:FlogGetVimBinGraph(git_cmd: string): dict<any>
# start_token
cmd ..= shellescape(g:flog_commit_start_token)
cmd ..= ' '
# enable_extended_chars
cmd ..= g:flog_enable_extended_chars ? 'true' : 'false'
cmd ..= ' '
# enable_graph
cmd ..= state.opts.graph ? 'true' : 'false'
cmd ..= ' '
Expand Down Expand Up @@ -283,6 +286,8 @@ def g:FlogGetVimInternalGraph(git_cmd: string): dict<any>
cmd ..= 'true, '
# start_token
cmd ..= 'vim.eval("g:flog_commit_start_token"), '
# enable_extended_chars
cmd ..= 'vim.eval("g:flog_enable_extended_chars"), '
# enable_graph
cmd ..= 'vim.eval("g:flog_tmp_enable_graph"), '
# default_collapsed
Expand Down
22 changes: 13 additions & 9 deletions syntax/floggraph.vim
Original file line number Diff line number Diff line change
Expand Up @@ -131,34 +131,38 @@ for branch_idx in range(1, 9)
exec 'highlight link flogGraphBranch' . branch_idx . ' ' . branch

" Branches at the start of the line - leads into other groups
exec 'syntax match ' . branch . ' contained nextgroup=' . next_branch . ',' . next_branch . 'Commit,' . next_branch . 'MergeStart,' . next_branch . 'MissingParentsStart,flogCollapsedCommit,@flogDiff /\v%( |%u2502 |%u2502$)/'
exec 'syntax match ' . branch . ' contained nextgroup=' . next_branch . ',' . next_branch . 'Commit,' . next_branch . 'MergeStart,' . next_branch . 'MissingParentsStart,flogCollapsedCommit,@flogDiff /\v |%u2502 |%u2502$|%uf5d1 |%uf5d1$/'

" Commit indicators
exec 'syntax match ' . branch . 'Commit contained nextgroup=' . next_branch . 'AfterCommit,@flogCommitInfo /\%u2022 /'
exec 'highlight link ' . branch . 'Commit flogCommit'
exec 'syntax match ' . branch . 'Commit contained nextgroup=' . next_branch . 'AfterCommit,@flogCommitInfo /\v(%u2022|%uf5ef|%uf5f6|%uf5f7|%uf5f9|%uf5fa|%uf5fb) /'
if g:flog_enable_extended_chars
exec 'highlight link ' . branch . 'Commit ' . branch
else
exec 'highlight link ' . branch . 'Commit flogCommit'
endif

" Branches to the right of the commit indicator
exec 'syntax match ' . branch . 'AfterCommit contained nextgroup=' . next_branch . 'AfterCommit,@flogCommitInfo /\v%( |%u2502 |%u2502$)/'
exec 'syntax match ' . branch . 'AfterCommit contained nextgroup=' . next_branch . 'AfterCommit,@flogCommitInfo /\v |%u2502 |%u2502$|%uf5d1 |%uf5d1$/'
exec 'highlight link ' . branch . 'AfterCommit ' . branch

" Start of a merge - saves the branch that the merge starts on (see below)
exec 'syntax match ' . branch . 'MergeStart contained nextgroup=' . next_merge_branch . ' /\v%(%u251c|%u256d|%u2570)/'
exec 'syntax match ' . branch . 'MergeStart contained nextgroup=' . next_merge_branch . ' /\v%u251c|%u256d|%u2570|%uf5da|%uf5db|%uf5d6|%uf5d8/'
exec 'highlight link ' . branch . 'MergeStart ' . branch

" Horizontal line inside of a merge
exec 'syntax match ' . merge . 'Horizontal contained /\%u2500/'
exec 'syntax match ' . merge . 'Horizontal contained /\v%u2500|%uf5d0/'
exec 'highlight link ' . merge . 'Horizontal ' . branch

" Branches to the right of a merge
exec 'syntax match ' . branch . 'AfterMerge contained nextgroup=' . next_branch . 'AfterMerge / ./'
exec 'highlight link ' . branch . 'AfterMerge ' . branch

" Start of missing parents line
exec 'syntax match ' . branch . 'MissingParentsStart contained nextgroup=' . next_branch . 'MissingParents /\v%u250a /'
exec 'syntax match ' . branch . 'MissingParentsStart contained nextgroup=' . next_branch . 'MissingParents /\v%u250a |%uf5d4 /'
exec 'highlight link ' . branch . 'MissingParentsStart ' . branch

" Branches to right of missing parents start
exec 'syntax match ' . branch . 'MissingParents contained nextgroup=' . next_branch . 'MissingParents /\v%(..|.$)/'
exec 'syntax match ' . branch . 'MissingParents contained nextgroup=' . next_branch . 'MissingParents /\v..|.$/'
exec 'highlight link ' . branch . 'MissingParents ' . branch
endfor

Expand All @@ -174,7 +178,7 @@ for merge_idx in range(1, 9)
let next_merge_branch = merge . 'Branch' . next_branch_idx

" Merge branches
exec 'syntax match ' . merge_branch . ' contained contains=' . merge . 'Horizontal nextgroup=' . next_merge_branch . ',' . next_branch . 'AfterMerge /\v%u2500./'
exec 'syntax match ' . merge_branch . ' contained contains=' . merge . 'Horizontal nextgroup=' . next_merge_branch . ',' . next_branch . 'AfterMerge /\v%u2500.|%uf5d0./'
exec 'highlight link ' . merge_branch . ' ' . branch
endfor
endfor
Expand Down

0 comments on commit e3d47e0

Please sign in to comment.