2
2
---
3
3
--- @brief [[
4
4
---
5
- --- rest.nvim result UI implmentation
5
+ --- rest.nvim result UI implementation
6
6
---
7
7
--- @brief ]]
8
8
@@ -161,9 +161,23 @@ local panes = {
161
161
set_lines (self .bufnr , { " No Statistics" })
162
162
return
163
163
end
164
- syntax_highlight (self .bufnr , " jproperties" )
164
+ vim .bo [self .bufnr ].syntax = " http_stat"
165
+
166
+ local ordered = {}
165
167
for key , value in pairs (data .response .statistics ) do
166
- table.insert (lines , (" %s: %s" ):format (key , value ))
168
+ local style = config .clients .curl .statistics [key ] or {}
169
+ local title = style [" title" ] or key
170
+
171
+ table.insert (ordered , {
172
+ order = style .order or 0 ,
173
+ val = (" %s: %s" ):format (title , value ),
174
+ })
175
+ end
176
+ table.sort (ordered , function (a , b )
177
+ return a .order < b .order
178
+ end )
179
+ for _ , v in ipairs (ordered ) do
180
+ table.insert (lines , v .val )
167
181
end
168
182
set_lines (self .bufnr , lines )
169
183
end ,
@@ -179,21 +193,33 @@ winbar = winbar .. "%#RestText#Press %#Keyword#?%#RestText# for help%#Normal# "
179
193
--- Winbar component showing response statistics
180
194
--- @return string
181
195
function ui .stat_winbar ()
182
- local content = " "
183
196
if not data .response then
184
197
return " Loading...%#Normal#"
185
198
end
186
- for stat_name , stat_value in pairs (data .response .statistics ) do
187
- local style = config .clients .curl .statistics [stat_name ] or {}
199
+ local ordered = {}
200
+ for stat_name , style in pairs (config .clients .curl .statistics ) do
201
+ local stat_value = data .response .statistics [stat_name ] or " "
188
202
if style .winbar then
189
203
local title = type (style .winbar ) == " string" and style .winbar or (style .title or stat_name ):lower ()
190
204
if title ~= " " then
191
205
title = title .. " : "
192
206
end
193
- local value , representation = vim .split (stat_value , " " )[1 ], vim .split (stat_value , " " )[2 ]
194
- content = content .. " %#RestText#" .. title .. " %#Number#" .. value .. " %#Normal#" .. representation
207
+ table.insert (ordered , {
208
+ order = style .order or 0 ,
209
+ val = string.format (" %%#RestText#%s%%#Normal#%s" , title , stat_value ),
210
+ })
195
211
end
196
212
end
213
+ if # ordered == 0 then
214
+ return " "
215
+ end
216
+ table.sort (ordered , function (a , b )
217
+ return a .order < b .order
218
+ end )
219
+ local content = " "
220
+ for _ , v in ipairs (ordered ) do
221
+ content = content .. " " .. v .val
222
+ end
197
223
return content
198
224
end
199
225
0 commit comments