Repository navigation
Widget API
Plugins can display rich UI by returning widget requests from hooks. Three widget types are available: split views, tree views, and terminal views.
A two-pane panel for displaying diffs, comparisons, or side-by-side content.
return {
split_view = {
title = "Git Diff",
left = {
content = original_text,
label = "Original",
line_numbers = true,
read_only = true,
highlights = {
{ line = 5, color = "removed" },
{ line = 10, color = "modified", spans = { { start = 0, end = 12 } } }
}
},
right = {
content = modified_text,
label = "Modified",
line_numbers = true,
read_only = false, -- allow editing
highlights = {
{ line = 5, color = "added" },
{ line = 10, color = "modified", spans = { { start = 0, end = 15 } } }
}
},
actions = {
{ label = "Accept", action = "accept" },
{ label = "Revert", action = "revert" }
},
display_mode = "panel" -- "panel" (default) or "tab"
}
}-
"added"— green -
"removed"— red -
"modified"— yellow -
{r, g, b}— custom RGB color (e.g.,{255, 128, 0})
Within a highlighted line, spans marks specific character ranges. Each span has start (inclusive, 0-indexed) and end (exclusive, 0-indexed).
Action buttons appear below the split view. When clicked, on_widget_action is called with widget_type = "split_view" and the action name. For the "accept" action, data.right_content contains the (possibly edited) right pane content.
A hierarchical tree panel for file browsers, search results, or structured data.
return {
tree_view = {
title = "File Explorer",
root = {
label = "src",
data = "/project/src",
expanded = true,
icon = "folder",
children = {
{
label = "main.rs",
data = "/project/src/main.rs",
icon = "file",
label_color = "modified"
},
{
label = "lib.rs",
data = "/project/src/lib.rs",
icon = "file"
}
}
},
on_click = "open_file",
click_mode = "double", -- "single" or "double" (default)
expand_depth = 1, -- 0 = collapsed, -1 = expand all
persistent = true, -- keep visible across tab switches
context_path = "/project",
context_menu = {
{
label = "New File",
action = "new_file",
target = "folder", -- show only on folders
input_prompt = "File name:" -- show input dialog
},
{
label = "Delete",
action = "delete",
target = "all",
confirm_prompt = "Delete this item?"
},
{
label = "Copy Path",
target = "all",
clipboard = true -- copies node path, no action sent
}
}
}
}| Field | Type | Description |
|---|---|---|
label |
string | Display text |
data |
string | Payload (file path, URL, metadata) |
children |
array | Child nodes (makes this a folder) |
expanded |
boolean | Initial expand state |
icon |
string | Hint: "file", "folder", "error", etc. |
label_color |
string | Semantic color: "modified", "added", "untracked", "conflict", "ignored"
|
Instead of building a tree programmatically, you can pass YAML:
return {
tree_view = {
title = "Config Viewer",
yaml_content = api:get_text()
}
}| Target | Shows on |
|---|---|
"folder" |
Nodes with children |
"file" |
Leaf nodes |
"empty" |
Empty area (right-click on background) |
"all" |
Everything |
An embedded PTY-backed terminal panel.
return {
terminal_view = {
title = "Build",
command = "cargo",
args = { "build", "--release" },
working_dir = api:get_project_root(),
persistent = true
}
}| Field | Type | Default | Description |
|---|---|---|---|
title |
string | required | Panel title |
command |
string | $SHELL |
Command to run |
args |
array | {} |
Command arguments |
working_dir |
string | project root | Working directory |
persistent |
boolean | false | Keep alive across tab switches |
The terminal supports ANSI escape sequences (SGR colors, reverse video) and auto-resizes when the panel is resized.
When the user interacts with a widget (clicks a button, selects a tree node), the on_widget_action hook is called:
function M:on_widget_action(api, widget_type, action, session_id, data)
if widget_type == "tree_view" and action == "open_file" then
-- data.node_path contains the clicked node's path array
local file_path = data.content -- or construct from node_path
return { open_file = file_path }
end
if widget_type == "split_view" and action == "accept" then
local new_content = data.right_content
-- write the accepted content
end
if widget_type == "tree_view" and action == "new_file" then
local filename = data.input_text -- from input_prompt
-- create the file
end
end| Field | Available for | Description |
|---|---|---|
right_content |
split_view accept | Edited right pane content |
node_path |
tree_view click | Array of labels from root to clicked node |
input_text |
tree_view context menu | User input from input_prompt
|
content |
all | Current buffer content |
target_path |
tree_view drag-drop | Drop target node path |