The Cointacted Social Terminal fires events every time something happens — a command runs, a line is printed, or output is updated.
Developers can hook into these events to build:
- analytics
- gamification
- logging systems
- animations
- sound effects
- custom UI reactions
- integrations with external services
- add-on logic
This article explains how these events work and how to use them.
1. Output Event: cointacted_social_terminal_output #
This event fires every time the terminal prints a line, no matter the source:
- core commands
- custom commands
- add-ons
- system messages
- errors
- wallet info
- fun commands
Event Listener: #
document.addEventListener(
'cointacted_social_terminal_output',
function(event) {
console.log("Output:", event.detail.text);
console.log("Type:", event.detail.type);
}
);
Event structure: #
event.detail = {
text: "Printed text",
type: "system" // or error, success, wallet, fun, admin...
};
2. Example Uses #
Analytics Tracking #
document.addEventListener('cointacted_social_terminal_output', (e) => {
fetch('/wp-json/terminal/v1/log', {
method: 'POST',
body: JSON.stringify(e.detail)
});
});
Display a sound when errors occur #
document.addEventListener('cointacted_social_terminal_output', (e) => {
if (e.detail.type === "error") {
new Audio('/sounds/error.mp3').play();
}
});
Trigger confetti when success happens #
document.addEventListener('cointacted_social_terminal_output', (e) => {
if (e.detail.type === "success") {
launchConfetti();
}
});
3. Command Execution Event (Optional/Internal) #
Your plugin implementation primarily exposes the output event because it is the safe, sanitized point after execution.
If you want to catch commands before they run, you can wrap or override registry handlers:
const old = CointactedSocialTerminalTerminal.registry.mycommand;
CointactedSocialTerminalTerminal.registry.mycommand = function(input) {
console.log("Running custom command:", input.cmd, input.args);
return old(input);
};
This technique allows:
- validation
- blocking commands
- guarding features
- analytics
- permission checks
But use this carefully.
4. Detecting Command Errors #
If a command throws an error internally, the terminal still fires an output event with:
type: "error"
This makes it easy to build troubleshooting tools.
Example:
document.addEventListener('cointacted_social_terminal_output', (e) => {
if (e.detail.type === "error") {
alert("Oops! Something wrong happened.");
}
});
5. Detecting Wallet Updates (via WALLET commands) #
When wallet-related commands run (wallet, chain, gas, block, etc.), they all print output that emits the event.
So you can detect wallet state easily:
document.addEventListener('cointacted_social_terminal_output', (e) => {
if (e.detail.type === "wallet") {
console.log("Wallet update:", e.detail.text);
}
});
This can drive:
- dashboards
- network indicators
- real-time wallet widgets
- blockchain add-on interactions
6. Chaining Events #
You can use events to create multi-step flows.
Example: When a custom command prints a certain keyword, run a second command:
document.addEventListener('cointacted_social_terminal_output', (e) => {
if (e.detail.text.includes("ready")) {
CointactedSocialTerminalTerminal.run("status");
}
});
7. Best Practices #
✔ Always check event.detail.type #
Don’t run logic for every line unless necessary.
✔ Use throttling for heavy logic #
If you’re logging every output to API, limit requests.
✔ Never modify core output inside the event #
Use it for observing, not altering.
✔ For advanced overrides, wrap the registry handler instead #
8. Summary #
Terminal events allow developers to:
✔ track every printed line #
✔ react to command output #
✔ trigger animations or sounds #
✔ log analytics #
✔ sync command data to backend #
✔ detect wallet updates #
✔ create reactive workflows #
✔ build advanced add-ons #
The output event is one of the most powerful extension points in the entire terminal framework.