- πΉ 1. User types into the input field
- πΉ 2. User presses Enter (Keyboard Event)
- πΉ 3. Input Parsing (Tokenizer)
- πΉ 4. Aliases Resolved
- πΉ 5. Check if the command exists
- πΉ 6. Permission Check (Guest vs Logged-In)
- πΉ 7. Help/Data Query Before Execution
- πΉ 8. Command Execution (Your Function Runs)
- πΉ 9. Your Command Prints Output Using:
- πΉ 10. Each Output Line Dispatches an Event
- πΉ 11. History Recording
- πΉ 12. Multi-Line Output Completion
- πΉ 13. Terminal Auto-Scroll Behavior
- πΉ 14. Command Completion
- πΉ Lifecycle Overview Diagram
- π― Summary
What happens from the moment the user types a command until the terminal prints output
Understanding the command lifecycle helps developers:
- override commands safely
- extend behavior
- hook into the right moment
- debug advanced issues
- build add-ons properly
This is the internal flow used by your real plugin.
πΉ 1. User types into the input field #
The user enters something like:
wallet
or:
say Hello world
This text lives inside the input element:
<input id="cointacted-social-terminal-input">
No processing happens yet.
πΉ 2. User presses Enter (Keyboard Event) #
A key listener captures it:
if (event.key === "Enter") { ... }
When pressed:
- The input value is read β this becomes
input.raw - The input is cleared
- The cursor resets position
- The command is handed to the parser
πΉ 3. Input Parsing (Tokenizer) #
The text is split into:
cmd // primary command (string)
args // list of arguments (array)
raw // entire text (string)
Example:
Input:
say Hello world
Parser output:
cmd: "say"
args: ["Hello", "world"]
raw: "say Hello world"
Parser rules:
- multiple spaces collapse into one
- leading and trailing spaces are stripped
- quotes are not yet supported (future)
πΉ 4. Aliases Resolved #
If the user typed an alias:
cls
The system resolves it to:
clear
This is done by scanning:
commands_meta[cmd].alias
If alias matches, it maps to the real command name.
πΉ 5. Check if the command exists #
The system checks:
CointactedSocialTerminalTerminal.registry[cmd]
If no match:
- runs the command_not_found handler
- usually prints:
Command not found: xyz
Add-ons may override this handler.
πΉ 6. Permission Check (Guest vs Logged-In) #
If the site is in guest-restricted mode:
- commands with
public: truecan run - others require login
If the command is private and the user is logged out:
The terminal prints:
You must be logged in to use this command.
And execution stops.
πΉ 7. Help/Data Query Before Execution #
Before running a command, the system:
- retrieves metadata
- checks if hidden
- checks its group
- prepares help-side access rules
This allows help to reflect the correct state.
πΉ 8. Command Execution (Your Function Runs) #
Now the command actually executes:
registry[cmd](input);
This is where your code lives:
registry.mycmd = function(input) {
// your logic here
};
Execution is synchronous or async
(both types work automatically).
πΉ 9. Your Command Prints Output Using: #
cointacted_social_terminal_append_line(text, type);
This function:
- escapes HTML
- auto-scrolls
- wraps into
<div class="cointacted-social-terminal__line"> - applies a type-specific class
- inserts line into output panel
Example output DOM:
<div class="cointacted-social-terminal__line cointacted-social-terminal__line--system">
Hello world
</div>
πΉ 10. Each Output Line Dispatches an Event #
Every time you call append_line(), the terminal fires:
cointacted_social_terminal_output
With:
event.detail = {
text: "Hello world",
type: "system"
};
Add-ons can listen to this to:
- sync data
- trigger animations
- apply effects
- monitor user activity
- run analytics
This is one of the most powerful hooks.
πΉ 11. History Recording #
After execution, the command is:
- appended to session history
- accessible through:
!!
!3
history
History is stored only in memory (no database).
πΉ 12. Multi-Line Output Completion #
A command may produce:
- no lines
- one line
- multiple lines
- asynchronous delayed lines
All output is appended in the order printed.
Async example:
append_line("Step 1");
setTimeout(() => append_line("Step 2"), 500);
The lifecycle supports this naturally.
πΉ 13. Terminal Auto-Scroll Behavior #
After each output:
- terminal scrolls to bottom
- unless the user manually scrolled up
This prevents:
- annoying forced scrolling
- loss of scroll position
πΉ 14. Command Completion #
After execution:
- control returns to user
- input is ready
- cursor reappears
- registry stays alive for next commands
No special teardown is needed.
πΉ Lifecycle Overview Diagram #
Here is the complete lifecycle in order:
User typing
β
Press Enter
β
Parser β (cmd, args, raw)
β
Alias resolution
β
Command exists? β No β command_not_found β END
β
Guest mode check (if enabled)
β
Metadata loading
β
Execute registry[cmd](input)
β
append_line(text, type)
β
Output event fired
β
History updated
β
Auto-scroll
β
Command complete
This flow applies to:
- built-in commands
- add-on commands
- overridden commands
- custom theme commands
Everything is unified through this lifecycle.
π― Summary #
The terminal lifecycle includes:
β input parsing #
β alias resolution #
β permission filtering #
β metadata preparation #
β command execution #
β output printing #
β events #
β history #
β scroll management #
Understanding this flow allows developers to:
- override safely
- add advanced features
- hook at the right stage
- debug deeply
- write powerful add-ons