Commands & Callbacks
The Terminal app uses a centralized NUI callback to handle all user input. This logic is exposed in an "open" file to allow for deep customization of how commands are parsed and executed.
The terminalCommand Callback
Located in client/open/open.lua, this callback is the bridge between the React UI and your Lua logic.
Core Logic
RegisterNUICallback('terminalCommand', function(data, cb)
local command = data.command
local args = data.args
local resp = {
status = 'error',
message = string.format("Error: '%s' is not recognized.", command)
}
if TerminalCommands[command] then
local result = TerminalCommands[command](args)
if type(result) == "table" then
resp = result
else
resp = { status = 'output', message = result }
end
end
cb(resp)
end)Parameters (data)
command: The first word of the user's input (lowercase).args: The rest of the input string as a single argument.
Response (resp)
The callback expects a table response:
status:'success','error','info', or'output'. This determines the text color in the terminal.message: The (HTML-supported) string to display as the result.
How to use this Callback
While the default implementation uses the TerminalCommands table, you can modify the callback to:
- Add Middleware: Log every command executed to a database or Discord webhook.
- External Logic: Forward specific commands to other resources via events or exports.
- Dynamic Parsing: Change how arguments are split (e.g., support for quoted arguments).
Example: Logging Commands
RegisterNUICallback('terminalCommand', function(data, cb)
-- Log to server
TriggerServerEvent('terminal:logCommand', data.command, data.args)
-- Continue with normal execution...
end)