This module provides a menu-driven configuration dialog for the terminal UI system.
::: tip TIP
To use this module, you need to import it first: import("core.ui.mconfdialog")
:::
::: tip NOTE
The UI module is primarily used for xmake's internal xmake f --menu menu-based visual configuration. It provides basic UI components that can also be used by users to implement their own terminal UIs.
:::
The mconfdialog module extends boxdialog and provides a comprehensive menu-based configuration interface. It allows users to configure settings through a hierarchical menu, with support for boolean, number, string, choice, and menu configurations. It also includes features like help dialogs, search functionality, and scrollbar support for long menus.
::: tip API
mconfdialog:new(name: <string>, bounds: <rect>, title: <string>)
:::
| Parameter | Description |
|---|---|
| name | Required. Dialog name string |
| bounds | Required. Dialog bounds rectangle |
| title | Required. Dialog title string |
| Type | Description |
|---|---|
| mconfdialog | Returns a menu configuration dialog instance |
Create a menu configuration dialog:
import("core.ui.mconfdialog")
import("core.ui.rect")
local dialog = mconfdialog:new("config", rect{1, 1, 80, 25}, "Configuration")
::: tip API
mconfdialog:load(configs: <table>)
:::
| Parameter | Description |
|---|---|
| configs | Required. Array of configuration items (created with menuconf.* functions) |
| Type | Description |
|---|---|
| boolean | Returns true on success |
Load configurations into the dialog:
local configs = {
menuconf.boolean{description = "Enable debug"},
menuconf.string{value = "x86_64", description = "Target architecture"},
menuconf.number{value = 10, default = 10, description = "Thread count"},
menuconf.choice{
value = 2,
values = {"gcc", "clang", "msvc"},
description = "Compiler"
}
}
dialog:load(configs)
::: tip API
mconfdialog:configs()
:::
No parameters
| Type | Description |
|---|---|
| table | Returns array of configuration items |
Access loaded configurations:
local configs = dialog:configs()
for _, config in ipairs(configs) do
print("Config:", config:prompt())
print("Value:", config.value)
end
::: tip API
mconfdialog:menuconf()
:::
No parameters
| Type | Description |
|---|---|
| menuconf | Returns the menu configuration instance |
Access the underlying menuconf component:
local menu = dialog:menuconf()
::: tip API
mconfdialog:show_help()
:::
No parameters
No return value
Display help information for the currently selected configuration item:
-- This is typically triggered by pressing '?' key
dialog:show_help()
::: tip API
mconfdialog:show_search()
:::
No parameters
No return value
Show search dialog to find configuration items:
-- This is typically triggered by pressing '/' key
dialog:show_search()
::: tip API
mconfdialog:show_exit(message: <string>)
:::
| Parameter | Description |
|---|---|
| message | Required. Confirmation message to display |
No return value
Show exit confirmation dialog:
dialog:show_exit("Did you wish to save your new configuration?")
::: tip API
mconfdialog:on_event(e: <event>)
:::
| Parameter | Description |
|---|---|
| e | Required. Event object |
| Type | Description |
|---|---|
| boolean | Returns true if event was handled, false otherwise |
Handle keyboard events for configuration navigation:
function dialog:on_event(e)
if e.type == event.ev_keyboard then
if e.key_name == "?" then
self:show_help()
return true
elseif e.key_name == "/" then
self:show_search()
return true
end
end
return mconfdialog.on_event(self, e)
end
The following keys are supported:
Up/Down: Navigate menu itemsSpace: Toggle boolean valuesY: Enable booleanN: Disable booleanEsc/Back: Go back?: Show help/: Search