File tree 3 files changed +73
-3
lines changed
3 files changed +73
-3
lines changed Original file line number Diff line number Diff line change @@ -670,6 +670,20 @@ sections = {
670
670
}
671
671
```
672
672
673
+ #### encoding component options
674
+
675
+ ``` lua
676
+ sections = {
677
+ lualine_a = {
678
+ {
679
+ ' encoding' ,
680
+ -- Show '[BOM]' when the file has a byte-order mark
681
+ show_bomb = false ,
682
+ }
683
+ }
684
+ }
685
+ ```
686
+
673
687
#### searchcount component options
674
688
675
689
``` lua
Original file line number Diff line number Diff line change 1
1
-- Copyright (c) 2020-2021 hoob3rt
2
2
-- MIT license, see LICENSE for more details.
3
- local function encoding ()
4
- return vim .opt .fileencoding :get ()
3
+ local lualine_require = require (' lualine_require' )
4
+ local M = lualine_require .require (' lualine.component' ):extend ()
5
+
6
+ local default_options = {
7
+ -- Show '[BOM]' when the file has a byte-order mark
8
+ show_bomb = false ,
9
+ }
10
+
11
+ function M :init (options )
12
+ M .super .init (self , options )
13
+ self .options = vim .tbl_deep_extend (' keep' , self .options or {}, default_options )
14
+ end
15
+
16
+ function M :update_status ()
17
+ local show_bomb = self .options .show_bomb
18
+
19
+ local result = vim .opt .fileencoding :get ()
20
+
21
+ if not show_bomb then
22
+ return result
23
+ end
24
+
25
+ if vim .opt .bomb :get () then
26
+ result = result .. ' [BOM]'
27
+ end
28
+
29
+ return result
5
30
end
6
31
7
- return encoding
32
+ return M
Original file line number Diff line number Diff line change @@ -242,6 +242,37 @@ describe('Encoding component', function()
242
242
vim .cmd (' bd!' )
243
243
os.remove (tmp_path )
244
244
end )
245
+ it (' works with BOM and default config' , function ()
246
+ local opts = build_component_opts {
247
+ component_separators = { left = ' ' , right = ' ' },
248
+ padding = 0 ,
249
+ }
250
+ local tmp_path = ' tmp.txt'
251
+ local tmp_fp = io.open (tmp_path , ' w' )
252
+ tmp_fp :write (' test file' )
253
+ tmp_fp :close ()
254
+ vim .cmd (' e ' .. tmp_path )
255
+ vim .cmd (' set bomb' )
256
+ assert_component (' encoding' , opts , ' utf-8' )
257
+ vim .cmd (' bd!' )
258
+ os.remove (tmp_path )
259
+ end )
260
+ it (' works with BOM and option enabled' , function ()
261
+ local opts = build_component_opts {
262
+ component_separators = { left = ' ' , right = ' ' },
263
+ padding = 0 ,
264
+ show_bomb = true
265
+ }
266
+ local tmp_path = ' tmp.txt'
267
+ local tmp_fp = io.open (tmp_path , ' w' )
268
+ tmp_fp :write (' test file' )
269
+ tmp_fp :close ()
270
+ vim .cmd (' e ' .. tmp_path )
271
+ vim .cmd (' set bomb' )
272
+ assert_component (' encoding' , opts , ' utf-8 [BOM]' )
273
+ vim .cmd (' bd!' )
274
+ os.remove (tmp_path )
275
+ end )
245
276
end )
246
277
247
278
describe (' Fileformat component' , function ()
You can’t perform that action at this time.
0 commit comments