Terminal is a object with you can import from lib, or get in second parameters on handles of project.
import { terminal } from "cowmand";
or
import { Terminal } from "cowmand"; // Importing types
program.use((context, terminal: Terminal) => {
})
Log is to you print a simple message on terminal.
Example:
import { Terminal } from "cowmand"; // Importing types
program.use((context, terminal: Terminal) => {
terminal
.log("Your login is ok!");
})
Using log you can print multiples lines in cascade.
import { Terminal } from "cowmand"; // Importing types
program.use((context, terminal: Terminal) => {
terminal
.log("Your login is ok!")
.log("You are welcome");
})
Error you can use to print a error for your user on terminal.
Example:
import { Terminal } from "cowmand"; // Importing types
program.use((context, terminal: Terminal) => {
terminal
.error("Error in login: ", [
"Your password is wrong",
"You can't start de application",
"Contact support on oi@support.com"
]);
})
You can print an array of items in a table viewer.
Example:
import { Terminal } from "cowmand"; // Importing types
program.use((context, terminal: Terminal) => {
terminal
.table([
{
name: "Marcon",
age: 23,
from: "Brazil"
},
{
name: "Julia",
age: 21,
from: "Italy"
}
]);
})
This property ends the program, you need use on can finish.
You can use direct after .log, .error and .table, or use only terminal.end().
Direct after:
import { Terminal } from "cowmand"; // Importing types
program.use((context, terminal: Terminal) => {
return terminal
.log("Hello Word")
.end();
})
program.use((context, terminal: Terminal) => {
return terminal
.log("You can find file 'my-work-list.docs'")
.error("Not found", ["You file not exist."])
.end();
})
Using only terminal.end();
import { Terminal } from "cowmand"; // Importing types
program.use((context, terminal: Terminal) => {
terminal
.log("Hello Word");
// Process
terminal
.log("It's all ok!");
// Process
return terminal.end();
})
You can use to print a loading on terminal.
import { Terminal } from "cowmand"; // Importing types
const delay = (ms: number) =>
new Promise(resolve => {
setTimeout(resolve, ms);
});
program.use(async (context, terminal: Terminal) => {
const loading = terminal.loading('Logging in...');
await delay(3000);
loading.succeed('Logged in!');
return terminal.end();
})
When you can ask a question to user or your user need add an information on an input, you can use this terminal property.
Example:
import { Terminal } from "cowmand"; // Importing types
program.use(async (context, terminal: Terminal) => {
const user = await terminal
.ask("Username: ");
terminal.log(`Your user name is ${user}`);
return terminal.end();
})
Example hidden information:
import { Terminal } from "cowmand"; // Importing types
program.use(async (context, terminal: Terminal) => {
const password = await terminal
.ask("Password: ", { hidden: true });
terminal.log(`Your password is ${password}`);
return terminal.end();
})