Context API (cx)
The cx object is the primary interface for reading Yazi's UI state. It is available in sync entry points (entry_sync) and in any callback that receives a job parameter.
Top-Level Fields
| Field | Type | Description |
|---|---|---|
cx.active | Tab | The currently focused tab |
cx.tabs | [Tab] | All open tabs |
cx.tasks | Tasks | Task manager state |
cx.yanked | [File] | Currently yanked (copied) files |
cx.selected | [File] | Currently selected files |
cx.mode | Mode | Current manager mode |
cx.visual | Visual | Visual selection state (if active) |
Tab Struct
Each Tab provides:
| Field | Type | Description |
|---|---|---|
current | Folder | The currently viewed folder |
parent | Folder | The parent folder |
preview | Folder | The preview folder |
windows | integer | Number of windows split |
mode | string | Tab mode (normal, select, etc.) |
name | string | Tab name (customizable) |
cwd | Url | Current working directory URL |
Folder
A Folder contains:
| Field | Type | Description |
|---|---|---|
files | [File] | List of files in the folder |
hovered | File | The currently hovered file |
offset | integer | Scroll offset |
cwd | Url | This folder's working directory |
-- Access currently hovered file
local file = cx.active.current.hovered
if file then
ya.err("Hovered: " .. file.name)
end
-- List all files in current directory
for _, f in ipairs(cx.active.current.files) do
ya.err(f.name)
end
Mode Struct
| Field | Type | Description |
|---|---|---|
mode | string | Mode name: "normal", "select", "unset" |
style | string | Display style name |
Visual Mode
When visual mode is active (cx.visual):
| Field | Type | Description |
|---|---|---|
start | integer | Starting index of selection |
end | integer | Ending index of selection |
mode | string | Visual mode direction |
if cx.visual then
local count = math.abs(cx.visual.end - cx.visual.start) + 1
ya.err("Visual selection: " .. count .. " files")
end
Tasks
The cx.tasks object provides access to the task manager:
| Field/Method | Description |
|---|---|
cx.tasks:running() | Number of running tasks |
cx.tasks:failed() | Number of failed tasks |
cx.tasks:finished() | Number of completed tasks |
cx.tasks:total() | Total tasks |
info
cx is read-only in sync contexts. To modify state, emit events via ya.emit() or use ya.sync() with a callback.