View Categories

Developer Examples (Full Working Recipes)

3 min read

This article gives practical, copy-paste recipes that developers can use immediately.
Each example follows the structure of your real terminal engine, registry, output system, and event architecture.

All examples assume you enqueue a custom JS file:

wp_enqueue_script(
    'my-terminal-ext',
    get_stylesheet_directory_uri() . '/terminal-ext.js',
    ['cointacted-social-terminal-js'],
    '1.0',
    true
);

Place the recipe code inside terminal-ext.js.


Example 1 — Simple “Hello” Command #

CointactedSocialTerminalTerminal.registry.hello = function () {
    cointacted_social_terminal_append_line("Hello from custom command!", "success");
};

Usage:

hello

Example 2 — Command with Arguments #

CointactedSocialTerminalTerminal.registry.say = function (input) {
    const msg = input.args.join(" ") || "You said nothing!";
    cointacted_social_terminal_append_line(msg, "system");
};

Usage:

say Hello world!

Example 3 — Fetch Data from an External API #

This is one of the most common use cases.

CointactedSocialTerminalTerminal.registry.price = async function (input) {
    const coin = input.args[0] || "bitcoin";

    cointacted_social_terminal_append_line(`Fetching ${coin} price...`, "system");

    try {
        const res = await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${coin}&vs_currencies=usd`);
        const data = await res.json();

        if (!data[coin]) {
            return cointacted_social_terminal_append_line("Coin not found.", "error");
        }

        cointacted_social_terminal_append_line(`Price: $${data[coin].usd}`, "success");
    } catch (e) {
        cointacted_social_terminal_append_line("API error.", "error");
    }
};

Usage:

price ethereum

Example 4 — Multi-Step Command (Interactive) #

CointactedSocialTerminalTerminal.registry.checkin = function () {
    cointacted_social_terminal_append_line("Checking you in...", "system");

    setTimeout(() => {
        cointacted_social_terminal_append_line("✔ Step 1: Verified", "success");

        setTimeout(() => {
            cointacted_social_terminal_append_line("✔ Step 2: Logged progress", "success");

            setTimeout(() => {
                cointacted_social_terminal_append_line("🎉 Check-in complete!", "success");
            }, 700);

        }, 700);

    }, 700);
};

Usage:

checkin

Example 5 — Command with Subcommands #

CointactedSocialTerminalTerminal.registry.user = function (input) {
    const sub = input.args[0];

    switch (sub) {
        case "info":
            cointacted_social_terminal_append_line("User Info:", "system");
            cointacted_social_terminal_append_line("Name: Demo User", "system");
            break;

        case "logout":
            cointacted_social_terminal_append_line("Logging out…", "error");
            break;

        default:
            cointacted_social_terminal_append_line("Usage: user <info|logout>", "error");
    }
};

Usage:

user info

Example 6 — Command that Calls a WordPress REST Route #

On PHP side (your add-on or theme):

add_action('rest_api_init', function () {
    register_rest_route('cst/v1', '/hello', [
        'methods'  => 'GET',
        'callback' => fn() => ['message' => 'Hello from REST!'],
        'permission_callback' => '__return_true'
    ]);
});

JS side:

CointactedSocialTerminalTerminal.registry.resthello = async function () {
    const res = await fetch('/wp-json/cst/v1/hello');
    const json = await res.json();

    cointacted_social_terminal_append_line(json.message, "success");
};

Usage:

resthello

Example 7 — Command with Error Handling #

CointactedSocialTerminalTerminal.registry.divide = function (input) {
    const [a, b] = input.args.map(Number);

    if (isNaN(a) || isNaN(b)) {
        return cointacted_social_terminal_append_line("Usage: divide <number> <number>", "error");
    }

    if (b === 0) {
        return cointacted_social_terminal_append_line("Cannot divide by zero.", "error");
    }

    cointacted_social_terminal_append_line(`Result: ${a / b}`, "success");
};

Example 8 — UI Popup Command (JS Alert Example) #

CointactedSocialTerminalTerminal.registry.popup = function () {
    alert("This is a popup example!");
    cointacted_social_terminal_append_line("Popup shown.", "success");
};

Usage:

popup

Example 9 — Store Value in Local Storage #

CointactedSocialTerminalTerminal.registry.save = function (input) {
    const msg = input.args.join(" ");
    localStorage.setItem("cst_saved", msg);

    cointacted_social_terminal_append_line("Saved!", "success");
};

CointactedSocialTerminalTerminal.registry.load = function () {
    const value = localStorage.getItem("cst_saved") || "Nothing saved.";
    cointacted_social_terminal_append_line(value, "system");
};

Usage:

save Remember this
load

Example 10 — Animated Output (Typing Effect) #

CointactedSocialTerminalTerminal.registry.type = function () {
    const text = "Typing like a real terminal...";
    let idx = 0;

    function tick() {
        if (idx < text.length) {
            cointacted_social_terminal_append_line(text.slice(0, idx + 1), "fun");
            idx++;
            setTimeout(tick, 40);
        }
    }

    tick();
};

Usage:

type

Example 11 — Wallet-Aware Command (Safe) #

Works only if wallet detection is enabled & wallet unlocked.

CointactedSocialTerminalTerminal.registry.myaddr = function () {
    const addr = CointactedSocialTerminalTerminal.wallet?.address;

    if (!addr) {
        return cointacted_social_terminal_append_line("Unlock MetaMask.", "error");
    }

    cointacted_social_terminal_append_line(`Your address: ${addr}`, "wallet");
};

Example 12 — Admin-Only Command #

CointactedSocialTerminalTerminal.registry.secure = function () {
    if (!CointactedSocialTerminalTerminal.user?.is_admin) {
        return cointacted_social_terminal_append_line("Admins only.", "error");
    }

    cointacted_social_terminal_append_line("Welcome admin.", "admin");
};

Example 13 — Command that Chains Another Command #

CointactedSocialTerminalTerminal.registry.chain = function () {
    cointacted_social_terminal_append_line("Running wallet...", "system");

    CointactedSocialTerminalTerminal.run("wallet");
};

Example 14 — Command with Randomized Behavior #

CointactedSocialTerminalTerminal.registry.magic = function () {
    const messages = [
        "You will build something amazing.",
        "Your idea will explode in 2025.",
        "Success is closer than you think."
    ];

    const random = messages[Math.floor(Math.random() * messages.length)];

    cointacted_social_terminal_append_line(random, "fun");
};

Example 15 — Full Mini-App: “Countdown Timer” #

CointactedSocialTerminalTerminal.registry.countdown = function (input) {
    let n = parseInt(input.args[0]);

    if (isNaN(n)) {
        return cointacted_social_terminal_append_line("Usage: countdown <seconds>", "error");
    }

    function tick() {
        if (n >= 0) {
            cointacted_social_terminal_append_line(n, "system");
            n--;
            setTimeout(tick, 1000);
        }
    }

    tick();
};

Usage:

countdown 5

Summary #

This article provides practical recipes showing how to build:

✔ Basic commands #

✔ Commands with arguments #

✔ API-powered commands #

✔ Multi-step & interactive commands #

✔ Subcommands #

✔ REST API integration #

✔ Safely handling errors #

✔ Popups & UI logic #

✔ Local storage persistence #

✔ Animations #

✔ Wallet-awareness #

✔ Admin-only logic #

✔ Command chaining #

✔ Randomized output #

✔ Mini-apps (timers, tasks, workflows) #

These examples help developers adopt and extend the terminal instantly.

Leave a Reply

Your email address will not be published. Required fields are marked *