This module provides the main application container for the terminal UI system. You can inherit from application to implement your own terminal UI applications.
::: tip TIP
To use this module, you need to import it first: import("core.ui.application")
:::
::: 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 application module uses inheritance. You create your own application instance and customize its behavior:
import("core.ui.application")
local app = application()
function app:init()
-- Your initialization code
end
::: tip API
local app = application()
:::
No parameters for constructor
| Type | Description |
|---|---|
| application | Returns a new application instance |
Create an application instance that you can customize:
import("core.ui.application")
local demo = application()
::: tip API
application:init(name: <string>, argv?: <table>)
:::
| Parameter | Description |
|---|---|
| name | Required. Application name string |
| argv | Optional. Command line arguments table |
No return value
Initialize your custom application. This is called automatically by run():
function demo:init()
application.init(self, "myapp")
self:background_set("blue")
-- Add your UI components here
self:insert(self:main_dialog())
end
::: tip API
application:run(...)
:::
| Parameter | Description |
|---|---|
| ... | Optional. Additional arguments |
No return value
Start your application. This initializes the UI, calls init(), and starts the event loop:
local demo = application()
function demo:init()
application.init(self, "demo")
self:background_set("blue")
self:insert(self:main_dialog())
end
-- Start the application
demo:run()
::: tip API
application:background_set(color: <string>)
:::
| Parameter | Description |
|---|---|
| color | Required. Color name (e.g., "blue", "red") |
No return value
Set the background color for your application:
self:background_set("blue")
::: tip API
application:insert(view: <view>, opt?: <table>)
:::
| Parameter | Description |
|---|---|
| view | Required. View to insert |
| opt | Optional. Options table, supports: {centerx = true, centery = true} |
No return value
Add views to your application with optional positioning:
-- Add a dialog
self:insert(self:main_dialog())
-- Add a centered dialog
self:insert(self:input_dialog(), {centerx = true, centery = true})
::: tip API
application:on_resize()
:::
No parameters
No return value
Override this method to handle resize events and update your UI layout:
function demo:on_resize()
self:main_dialog():bounds_set(rect{1, 1, self:width() - 1, self:height() - 1})
self:center(self:input_dialog(), {centerx = true, centery = true})
application.on_resize(self)
end
::: tip API
application:menubar()
:::
No parameters
| Type | Description |
|---|---|
| menubar | Returns the menu bar instance |
Access the menu bar component:
local menubar = app:menubar()
::: tip API
application:desktop()
:::
No parameters
| Type | Description |
|---|---|
| desktop | Returns the desktop instance |
Access the desktop area for placing views:
local desktop = app:desktop()
::: tip API
application:statusbar()
:::
No parameters
| Type | Description |
|---|---|
| statusbar | Returns the status bar instance |
Access the status bar component:
local statusbar = app:statusbar()
statusbar:text_set("Ready")