22---
33--- @brief [[
44---
5- --- rest.nvim result UI implmentation
5+ --- rest.nvim result UI implementation
66---
77--- @brief ]]
88
@@ -161,9 +161,23 @@ local panes = {
161161 set_lines (self .bufnr , { " No Statistics" })
162162 return
163163 end
164- syntax_highlight (self .bufnr , " jproperties" )
164+ vim .bo [self .bufnr ].syntax = " http_stat"
165+
166+ local ordered = {}
165167 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 )
167181 end
168182 set_lines (self .bufnr , lines )
169183 end ,
@@ -179,21 +193,33 @@ winbar = winbar .. "%#RestText#Press %#Keyword#?%#RestText# for help%#Normal# "
179193--- Winbar component showing response statistics
180194--- @return string
181195function ui .stat_winbar ()
182- local content = " "
183196 if not data .response then
184197 return " Loading...%#Normal#"
185198 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 " "
188202 if style .winbar then
189203 local title = type (style .winbar ) == " string" and style .winbar or (style .title or stat_name ):lower ()
190204 if title ~= " " then
191205 title = title .. " : "
192206 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+ })
195211 end
196212 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
197223 return content
198224end
199225
0 commit comments