mirror of
https://github.com/MunifTanjim/nui.nvim
synced 2024-09-16 21:04:02 +02:00
docs(table): add initial docs
This commit is contained in:
parent
bfd3806904
commit
4ef43af1ed
3 changed files with 151 additions and 2 deletions
|
@ -37,6 +37,14 @@ Quickly add line containing highlighted text chunks on the buffer.
|
|||
|
||||
**[Check Wiki Page for `nui.line`](https://github.com/MunifTanjim/nui.nvim/wiki/nui.line)**
|
||||
|
||||
### [NuiTable](lua/nui/table)
|
||||
|
||||
Quickly render table-like structured content on the buffer.
|
||||
|
||||
**[Check Detailed Documentation for `nui.table`](lua/nui/table)**
|
||||
|
||||
**[Check Wiki Page for `nui.table`](https://github.com/MunifTanjim/nui.nvim/wiki/nui.table)**
|
||||
|
||||
### [NuiTree](lua/nui/tree)
|
||||
|
||||
Quickly render tree-like structured content on the buffer.
|
||||
|
|
105
lua/nui/table/README.md
Normal file
105
lua/nui/table/README.md
Normal file
|
@ -0,0 +1,105 @@
|
|||
# NuiTable
|
||||
|
||||
NuiTable can render table-like structured content on the buffer.
|
||||
|
||||
**Examples**
|
||||
|
||||
```lua
|
||||
local NuiTable = require("nui.table")
|
||||
|
||||
local tbl = NuiTable({
|
||||
bufnr = bufnr,
|
||||
columns = {
|
||||
{
|
||||
align = "center",
|
||||
header = "Name",
|
||||
columns = {
|
||||
{ accessor_key = "firstName", header = "First" },
|
||||
{
|
||||
id = "lastName",
|
||||
accessor_fn = function(row)
|
||||
return row.lastName
|
||||
end,
|
||||
header = "Last",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
align = "right",
|
||||
accessor_key = "age",
|
||||
cell = function(cell)
|
||||
return Text(tostring(cell.get_value()), "DiagnosticInfo")
|
||||
end,
|
||||
header = "Age",
|
||||
},
|
||||
},
|
||||
data = {
|
||||
{ firstName = "John", lastName = "Doe", age = 42 },
|
||||
{ firstName = "Jane", lastName = "Doe", age = 27 },
|
||||
},
|
||||
})
|
||||
|
||||
tbl:render()
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### `bufnr`
|
||||
|
||||
**Type:** `number`
|
||||
|
||||
Id of the buffer where the table will be rendered.
|
||||
|
||||
---
|
||||
|
||||
### `ns_id`
|
||||
|
||||
**Type:** `number` or `string`
|
||||
|
||||
Namespace id (`number`) or name (`string`).
|
||||
|
||||
---
|
||||
|
||||
### `columns`
|
||||
|
||||
**Type:** `NuiTable.ColumnDef[]`
|
||||
|
||||
List of `NuiTable.ColumnDef` objects.
|
||||
|
||||
---
|
||||
|
||||
### `data`
|
||||
|
||||
**Type:** `any[]`
|
||||
|
||||
List of data items.
|
||||
|
||||
## Methods
|
||||
|
||||
### `tbl:get_cell`
|
||||
|
||||
_Signature:_ `tbl:get_cell() -> NuiTable.Cell | nil`
|
||||
|
||||
Returns the `cell` if found.
|
||||
|
||||
### `tbl:refresh_cell`
|
||||
|
||||
_Signature:_ `tbl:refresh_cell(cell: NuiTable.Cell) -> nil`
|
||||
|
||||
Refreshes the `cell` on buffer.
|
||||
|
||||
**Parameters**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------ | --------------- | ----------- |
|
||||
| `cell` | `NuiTable.Cell` | cell |
|
||||
|
||||
### `tbl:render`
|
||||
|
||||
_Signature:_ `tbl:render()`
|
||||
|
||||
Renders the table on buffer.
|
||||
|
||||
## Wiki Page
|
||||
|
||||
You can find additional documentation/examples/guides/tips-n-tricks in [nui.table wiki page](https://github.com/MunifTanjim/nui.nvim/wiki/nui.table).
|
|
@ -19,10 +19,10 @@ local u = {
|
|||
}
|
||||
|
||||
-- luacheck: push no max comment line length
|
||||
---@alias border_char_name 'down_right'|'hor'|'down_hor'|'down_left'|'ver'|'ver_left'|'ver_hor'|'ver_left'|'up_right'|'up_hor'|'up_left'
|
||||
---@alias nui_table_border_char_name 'down_right'|'hor'|'down_hor'|'down_left'|'ver'|'ver_left'|'ver_hor'|'ver_left'|'up_right'|'up_hor'|'up_left'
|
||||
-- luacheck: pop
|
||||
|
||||
---@type table<border_char_name,string>
|
||||
---@type table<nui_table_border_char_name,string>
|
||||
local default_border = {
|
||||
hor = "─",
|
||||
ver = "│",
|
||||
|
@ -91,9 +91,45 @@ local function prepare_columns(meta, columns, parent, depth)
|
|||
end
|
||||
end
|
||||
|
||||
---@class NuiTable.ColumnDef
|
||||
---@field accessor_fn? fun(original_row: any, index: integer): string|NuiText|NuiLine
|
||||
---@field accessor_key? string
|
||||
---@field cell? fun(info: NuiTable.Cell): string|NuiText|NuiLine
|
||||
---@field columns? NuiTable.ColumnDef[]
|
||||
---@field footer? string|NuiText|NuiLine|fun(info: { column: NuiTable.Column }): string|NuiText|NuiLine
|
||||
---@field header? string|NuiText|NuiLine|fun(info: { column: NuiTable.Column }): string|NuiText|NuiLine
|
||||
---@field id? string
|
||||
|
||||
---@class NuiTable.Column
|
||||
---@field accessor_fn? fun(original_row: any, index: integer): string|NuiText|NuiLine
|
||||
---@field accessor_key? string
|
||||
---@field columns? NuiTable.ColumnDef[]
|
||||
---@field depth integer
|
||||
---@field id string
|
||||
---@field parent? NuiTable.Column
|
||||
---@field width integer
|
||||
|
||||
---@class NuiTable.Row
|
||||
---@field id string
|
||||
---@field index integer
|
||||
---@field original any
|
||||
|
||||
---@class NuiTable.Cell
|
||||
---@field column NuiTable.Column
|
||||
---@field content NuiText|NuiLine
|
||||
---@field get_value fun(): string|NuiText|NuiLine
|
||||
---@field row NuiTable.Row
|
||||
|
||||
---@class NuiTable
|
||||
local Table = Object("NuiTable")
|
||||
|
||||
---@class nui_table_options
|
||||
---@field bufnr integer
|
||||
---@field ns_id integer|string
|
||||
---@field columns NuiTable.ColumnDef[]
|
||||
---@field data any[]
|
||||
|
||||
---@param options nui_table_options
|
||||
function Table:init(options)
|
||||
if options.bufnr then
|
||||
if not vim.api.nvim_buf_is_valid(options.bufnr) then
|
||||
|
|
Loading…
Reference in a new issue