Skip to content

Commit 8a94bf6

Browse files
committed
doc: Added examples to architectures
1 parent 39e5c7b commit 8a94bf6

1 file changed

Lines changed: 61 additions & 1 deletion

File tree

guides/Architecture.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,69 @@ For example, the `statusline` module uses the following files,
1414
- [../lua/bars/statusline.lua](https://github.com/OXY2DEV/bars.nvim/blob/main/lua/bars/statusline.lua)
1515
- [../lua/bars/components/statusline.lua](https://github.com/OXY2DEV/bars.nvim/blob/main/lua/bars/components/statusline.lua)
1616

17-
# `<module>.lua`
17+
## `<module>.lua`
1818

1919
This file holds,
2020

2121
+ A configuration table(`module.config`).
22+
Typically it would have the following structure,
23+
24+
```lua $TYP: ../lua/bars/types/statusline.lua, from: $TYP, class: statusline.config
25+
--- Statusline configuration table.
26+
---@class statusline.config
27+
---
28+
---@field force_attach? string[] List of `statusline` values to ignore when attaching.
29+
---
30+
---@field ignore_filetypes string[] Filetypes to ignore when attaching.
31+
---@field ignore_buftypes string[] Buffer types to ignore when attaching.
32+
---
33+
---@field condition? fun(buffer: integer, window: integer): boolean Additional condition for attaching to windows.
34+
---
35+
---@field default statusline.style Default style.
36+
---@field [string] statusline.style Named style.
37+
```
38+
2239
+ Module state(`module.state`).
40+
```lua $SRC: ../lua/bars/statusline.lua, from: $SRC, field: statusline.state
41+
statusline.state = {
42+
enable = true,
43+
attached_windows = {}
44+
};
45+
```
46+
2347
+ A renderer(`module.render`). This will be used as the content of the specific bar/line.
48+
```lua $SRC: ../lua/bars/statusline.lua, from: $SRC, field: statusline.render
49+
--- Renders the statusline for a window.
50+
---@return string
51+
statusline.render = function ()
52+
---|fS
53+
54+
local components = require("bars.components.statusline");
55+
56+
local window = vim.g.statusline_winid;
57+
local buffer = vim.api.nvim_win_get_buf(window);
58+
59+
statusline.update_style(window);
60+
61+
local style = vim.w[window].bars_statusline_style or vim.w[window]._bars_statusline_style or "default";
62+
local config = statusline.config[style];
63+
64+
if type(config) ~= "table" then
65+
return "";
66+
end
67+
68+
local _o = "";
69+
70+
for _, component in ipairs(config.components or {}) do
71+
_o = _o .. components.get(component.kind, buffer, window, component, _o);
72+
end
73+
74+
return _o;
75+
76+
---|fE
77+
end
78+
```
79+
2480
+ Helper functions such as,
2581
+ A start function(`module.start()`). Usually called during `VimEnter` or via commands.
2682
+ A window attach function(`module.attach(win: integer)`) for attaching to windows.
@@ -30,3 +86,7 @@ This file holds,
3086

3187
And optionally some commands(e.g. `module.Enable()`, the function name should start with a **capital letter**).
3288

89+
## `components/<module>.lua`
90+
91+
This will hold various components
92+

0 commit comments

Comments
 (0)