Skip to main content

Runtime API (rt)

The rt global provides access to runtime environment values: CLI arguments, terminal dimensions, and user preferences from every configuration section.


CLI Arguments

FieldTypeDescription
rt.args[string]CLI arguments passed to Yazi on startup
for i, arg in ipairs(rt.args) do
ya.err(string.format("arg[%d]: %s", i, arg))
end

Terminal Properties

FieldTypeDescription
rt.term.widthintegerTerminal width in columns
rt.term.heightintegerTerminal height in rows
rt.term.pixel_widthintegerTerminal width in pixels (protocol-dependent)
rt.term.pixel_heightintegerTerminal height in pixels
local function center_text(text)
local pad = math.floor((rt.term.width - #text) / 2)
return string.rep(" ", pad) .. text
end

Preferences

rt exposes user preferences from every TOML configuration section as nested tables.

[mgr] Section

--~/.config/yazi/yazi.toml
-- [mgr]
-- ratio = [1, 2, 3]
-- show_hidden = false

local ratio = rt.mgr.ratio -- { 1, 2, 3 }
local hidden = rt.mgr.show_hidden -- false

[plugin] Section

-- [plugin]
-- prepend_preloaders = []
-- append_preloaders = []
-- prepend_previewers = []
-- append_previewers = []

local preloaders = rt.plugin.prepend_preloaders

[preview] Section

-- [preview]
-- max_width = 600
-- max_height = 900

local max_w = rt.preview.max_width
local max_h = rt.preview.max_height

[open] Section

-- [open] rules
local rules = rt.open.rules
-- rules: [ { name = "*.pdf", use = "zathura" }, ... ]

[tasks] Section

-- [tasks]
-- micro_workers = 5
-- macro_workers = 2

local micro = rt.tasks.micro_workers
local macro = rt.tasks.macro_workers

Example: Responsive Layout

local function responsive_layout()
if rt.term.width < 120 then
return ui.Layout()
:direction(ui.Layout.VERTICAL)
:constraints({
ui.Constraint.Ratio(1, 3),
ui.Constraint.Ratio(2, 3),
})
else
return ui.Layout()
:direction(ui.Layout.HORIZONTAL)
:constraints({
ui.Constraint.Ratio(1, 4),
ui.Constraint.Ratio(3, 4),
})
end
end
info

rt is available globally in both sync and async contexts. It is populated at startup and does not change during a Yazi session.