Skip to content

Commit edb2863

Browse files
authored
add Lualine component (#279)
1 parent 9bb8695 commit edb2863

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,35 @@ require("telescope").extensions.rest.select_env()
213213
- env_pattern: For env file pattern
214214
- env_edit_command: For env file edit command
215215

216+
## Lualine
217+
218+
We also have lualine component to get what env file you select!
219+
And dont't worry, it will only show up under http files.
220+
221+
```lua
222+
-- Juse add a component in your lualine config
223+
{
224+
sections = {
225+
lualine_x = {
226+
"rest"
227+
}
228+
}
229+
}
230+
231+
-- To custom icon and color
232+
{
233+
sections = {
234+
lualine_x = {
235+
{
236+
"rest",
237+
icon = "",
238+
fg = "#428890"
239+
}
240+
}
241+
}
242+
}
243+
```
244+
216245
## Contribute
217246

218247
1. Fork it (https://github.com/rest-nvim/rest.nvim/fork)

lua/lualine/components/rest.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
local lualine_require = require("lualine_require")
2+
local M = lualine_require.require("lualine.component"):extend()
3+
local config = require("rest-nvim.config")
4+
5+
local default_options = {
6+
fg = "#428890",
7+
icon = "",
8+
}
9+
10+
function M:init(options)
11+
M.super.init(self, options)
12+
self.options = vim.tbl_deep_extend("keep", self.options or {}, default_options)
13+
self.icon = self.options.icon
14+
15+
self.highlight_color = self:create_hl({ fg = self.options.fg }, "Rest")
16+
end
17+
18+
function M:apply_icon()
19+
local default_highlight = self:get_default_hl()
20+
self.status = self:format_hl(self.highlight_color) .. self.icon .. " " .. default_highlight .. self.status
21+
end
22+
23+
function M.update_status()
24+
local current_filetype = vim.bo.filetype
25+
if current_filetype == "http" then
26+
return config.get("env_file")
27+
end
28+
return ""
29+
end
30+
31+
return M

0 commit comments

Comments
 (0)