Skip to content

Commit 393715b

Browse files
committed
Add node "badge" support
The "badge" is an area to indicate the node status. It is mainly desigend for git status integration but not limited for that.
1 parent 6bc57d3 commit 393715b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

autoload/fern/internal/node.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ endfunction
207207
function! s:new(node, ...) abort
208208
let node = extend(a:node, {
209209
\ 'label': get(a:node, 'label', a:node.name),
210+
\ 'badge': get(a:node, 'badge', ''),
210211
\ 'hidden': get(a:node, 'hidden', 0),
211212
\ 'bufname': get(a:node, 'bufname', v:null),
212213
\ 'concealed': get(a:node, 'concealed', {}),

autoload/fern/renderer/default.vim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ function! s:syntax() abort
5151
\ escape(g:fern#renderer#default#collapsed_symbol, s:ESCAPE_PATTERN),
5252
\ escape(g:fern#renderer#default#expanded_symbol, s:ESCAPE_PATTERN),
5353
\)
54-
syntax match FernRootText /.*$/ contained
55-
syntax match FernLeafText /.*$/ contained
56-
syntax match FernBranchText /.*$/ contained
54+
syntax match FernRootText /.*\ze .*$/ contained nextgroup=FernBadge
55+
syntax match FernLeafText /.*\ze .*$/ contained nextgroup=FernBadge
56+
syntax match FernBranchText /.*\ze .*$/ contained nextgroup=FernBadge
57+
syntax match FernBadge /.*/ contained
5758
endfunction
5859

5960
function! s:highlight() abort
@@ -68,15 +69,15 @@ endfunction
6869
function! s:render_node(node, base, options) abort
6970
let level = len(a:node.__key) - a:base
7071
if level is# 0
71-
return prefix . a:options.root_symbol . a:node.label
72+
return a:options.root_symbol . a:node.label . ' ' . a:node.badge
7273
endif
7374
let leading = repeat(a:options.leading, level - 1)
7475
let symbol = a:node.status is# s:STATUS_NONE
7576
\ ? a:options.leaf_symbol
7677
\ : a:node.status is# s:STATUS_COLLAPSED
7778
\ ? a:options.collapsed_symbol
7879
\ : a:options.expanded_symbol
79-
return prefix . leading . symbol . a:node.label
80+
return leading . symbol . a:node.label . ' ' . a:node.badge
8081
endfunction
8182

8283
call s:Config.config(expand('<sfile>:p'), {

doc/fern-develop.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ A node instance is a tree item which has the following attributes:
110110

111111
"label" A |String| used to display the node in a tree view.
112112

113+
"badge" A |String| used to display the node badge in a tree view.
114+
Only first character is used in the default renderer.
115+
113116
"hidden" A 1/0 to indicate if the node should be hidden. All hidden
114117
nodes become visible once fern enter hidden mode.
115118

0 commit comments

Comments
 (0)