-
Notifications
You must be signed in to change notification settings - Fork 0
Applications
The application system is needed to extend the built-in functionality of the simulator.
To connect an application to the simulator/terminal, pass it through props applications.
Example:
import {Terminal} from 'reterm';
function App(props) {
const myApplication = /* some application */;
const myAnotherApplication = /* some another application */;
return (
<Terminal
applications={{myApplication, 'command': myAnotherApplication}}
/>
)
}When passing an object as a {variable}, the launch command will be the name of the variable (in the example it will be "myApplication").
When passing the object as {"key": value} of the run command will be the key (in the example it will be "command").
To run the application, enter the application command in input (for example, "myApplication" and "command").
An application is any object that implements the TermApp interface. It contains a required execute function that can return a ReactNode and optional information for the help command.
Examples:
myOutputApp.application.ts
const myOutputApp: TermApp = {
help: {
template: 'myApp [text]',
description: 'make soo cool'
},
execute: (command /*: string */, closeApp /*: closeApp*/) => {
return closeApp(command);
}
}myComponentApp.tsx
const myComponentApp: TermApp = {
help: {
template: 'myApp <params>',
description: 'show something'
},
execute: (command /*: string */, closeApp /*: closeApp*/) => {
return <MyComponent closeApp={closeApp}/> /* React.FC<{TermAppComponent}> */;
}
}Reminder, always use closeApp to end the application
The call is made when the first word of the user command matches the value from the available applications object. When called, the execute method is called, to which the following parameters are passed:
command - original command
closeApp - application close function
value - information about the internal data of the simulator and the user's device
The simulator stops rendering I/O and displays the running application until the closeApp method is called. If the application does not display the component on the screen, then a blank screen will be shown.
for more convenient work with the command, there is a built-in method for trimming the first word (starting the application) - getArgs(command: string). It returns an object from an array of arguments and arguments as a string (user input without the first word).