File tree 3 files changed +107
-0
lines changed
lua/lualine/components/ex
3 files changed +107
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ for `lualine.nvim` with additional components.
11
11
- [ 🧩 Provided components] ( #provided-components )
12
12
- [ ex.spellcheck] ( #exspellcheck )
13
13
- [ ex.cwd] ( #excwd )
14
+ - [ ex.location] ( #exlocation )
14
15
- [ ex.relative_filename] ( #exrelative_filename )
15
16
- [ ex.git.branch] ( #exgitbranch )
16
17
- [ ex.lsp.single] ( #exlspsingle )
@@ -137,6 +138,34 @@ sections = {
137
138
The absolute value of the {depth} will be decreased until the length of the path becomes less then
138
139
{max_length}.
139
140
141
+ ### ex.location
142
+
143
+ This component shows the current cursor position in configurable format. Comparing to the default
144
+ ` location ` component, this component can show total number of lines, and may be flexibly configured.
145
+
146
+ | pattern | example |
147
+ | :---:| :---:|
148
+ | ` '%2C:%-3L/%T' ` | <img height =18 alt =" ex location " src =" https://github.com/dokwork/lualine-ex/assets/6939832/743ffc33-a5f4-4f95-9204-e217fa9cdbf7 " > |
149
+ | ` '%3L:%-2C' ` | <img height =18 alt =" ex location-2 " src =" https://github.com/dokwork/lualine-ex/assets/6939832/2e9dfa90-7363-4a99-a8d1-c1cc9033d5f7 " > |
150
+
151
+
152
+ ``` lua
153
+ sections = {
154
+ lualine_a = {
155
+ {
156
+ ' ex.location' ,
157
+
158
+ -- The pattern to show the cursor position. Here three possible specifiers:
159
+ -- 'L' means 'line' - the number of the line where is the cursor now;
160
+ -- 'C' means 'column' - the number of the virtual column where is the cursor now;
161
+ -- 'T' means 'total' - the total count of lines in the current buffer;
162
+ -- Every specifier can be used in similar maner to %d in the {string.format} function.
163
+ -- The pattern similar to the default 'location' component is '%3L:%-2C'
164
+ pattern = ' %2C:%-3L/%T'
165
+ }
166
+ }
167
+ }
168
+ ```
140
169
141
170
### ex.relative_filename
142
171
Original file line number Diff line number Diff line change
1
+ local log = require (' plenary.log' ).new ({ plugin = ' ex.location' })
2
+
3
+ local Location = require (' lualine.ex.component' ):extend ({
4
+ pattern = ' %2C:%-3L/%T' ,
5
+ })
6
+
7
+ function Location :post_init ()
8
+ self .__substitutions = {}
9
+ self .__pattern = string.gsub (self .options .pattern , ' (%%%-?%d*[LCT]+)' , function (template )
10
+ return string.gsub (template , ' ([LCT])' , function (value )
11
+ table.insert (self .__substitutions , value )
12
+ return ' d'
13
+ end )
14
+ end )
15
+ log .debug (self .__substitutions )
16
+ log .debug (self .__pattern )
17
+ end
18
+
19
+ function Location :update_status ()
20
+ local values = {
21
+ L = vim .fn .line (' .' ),
22
+ C = vim .fn .virtcol (' .' ),
23
+ T = vim .fn .line (' $' ),
24
+ }
25
+ local substitutions = vim .tbl_map (function (key )
26
+ return values [key ]
27
+ end , self .__substitutions )
28
+ return string.format (self .__pattern , unpack (substitutions ))
29
+ end
30
+
31
+ return Location
Original file line number Diff line number Diff line change
1
+ local l = require (' tests.ex.lualine' )
2
+ local t = require (' tests.ex.busted' ) -- :ignore_all_tests()
3
+
4
+ local eq = assert .are .equal
5
+
6
+ local orig = {
7
+ line = vim .fn .line ,
8
+ virtcol = vim .fn .virtcol ,
9
+ }
10
+ local mock = {
11
+ line = {},
12
+ virtcol = {},
13
+ }
14
+
15
+ local component_name = ' ex.location'
16
+ describe (component_name , function ()
17
+ before_each (function ()
18
+ vim .fn .line = function (arg )
19
+ return mock .line [arg ]
20
+ end
21
+ vim .fn .virtcol = function (arg )
22
+ return mock .virtcol [arg ]
23
+ end
24
+ end )
25
+
26
+ after_each (function ()
27
+ vim .fn .line = orig .line
28
+ vim .fn .virtcol = orig .virtcol
29
+ end )
30
+
31
+ describe (' default patter' , function ()
32
+ it (' should show {line}:{column}/{total}' , function ()
33
+ mock .virtcol [' .' ] = 11
34
+ mock .line [' .' ] = 222
35
+ mock .line [' $' ] = 3333
36
+ local component = l .render_component (component_name )
37
+ eq (' 11:222/3333' , component )
38
+ end )
39
+ it (' should fill numbers by space' , function ()
40
+ mock .virtcol [' .' ] = 1
41
+ mock .line [' .' ] = 2
42
+ mock .line [' $' ] = 3
43
+ local component = l .render_component (component_name )
44
+ eq (' 1:2 /3' , component )
45
+ end )
46
+ end )
47
+ end )
You can’t perform that action at this time.
0 commit comments