I/O & Terminal
DOCUMENTATIONConsole Output (
User Input (
Delay (
Raw Input (
Terminal Commands (
XCX 4.4.1 I/O and System Commands
Console Output (>!)
The >! operator prints values to stdout, followed by a newline.
xcx
_
⛶
×
1>! "Hello";
2>! 42;
3>! "Path: " + path;
Escape sequences like \n (newline), \t (tab), and \r (carriage return) are supported.
User Input (>?)
The >? operator reads a line from stdin and attempts to parse it into the target variable.
xcx
_
⛶
×
1i: age;
2>! "Enter age:";
3>? age;
Delay (@wait)
Pauses VM execution for a specified number of milliseconds.
xcx
_
⛶
×
1@wait 1000; --- Waits for 1 second
@wait is a blocking operation. It does not yield the fiber.
Raw Input (input)
The input module allows reading single keys without waiting for Enter.
Methods
| Call | Returns | Description |
|---|---|---|
input.key() | s | Returns key if available, "" if not |
input.key() @wait | s | Waits for a key and returns it |
input.ready() | b | true if a key is waiting in the buffer |
Key Constants
| Value | Key |
|---|---|
"UP" | Arrow Up |
"DOWN" | Arrow Down |
"LEFT" | Arrow Left |
"RIGHT" | Arrow Right |
"ENTER" | Enter |
"ESC" | Escape |
"BACKSPACE" | Backspace |
"TAB" | Tab |
"F1" ... "F12" | F1–F12 |
"KEY_CTRL_C" | Ctrl+C |
"KEY_CTRL_Z" | Ctrl+Z |
"KEY_CTRL_S" | Ctrl+S |
Regular characters are returned directly: "a", "Z", "5", " ".
Example
xcx
_
⛶
×
1s: k = input.key();
2if (k == "UP") then;
3 y = y - 1;
4end;
5
6--- wait for specific key
7s: confirm = input.key() @wait;
8if (confirm == "q") then;
9 return;
10end;
Terminal Commands (.terminal)
Directly interact with the system environment or current process.
| Directive | Description |
|---|---|
.terminal !clear | Clears the screen |
.terminal !exit | Terminates the VM process |
.terminal !run s | Runs s as a child process and returns its captured stdout - see the note below |
.terminal !raw | Raw mode - no echo, no buffering |
.terminal !normal | Restores normal terminal mode |
.terminal !cursor on | Shows the cursor |
.terminal !cursor off | Hides the cursor |
.terminal !move x y | Moves the cursor to position x, y (i) |
.terminal !write expr | Prints expr without a trailing newline |
Example - Game Loop
xcx
_
⛶
×
1.terminal !raw;
2.terminal !cursor off;
3.terminal !clear;
4
5while (true) do;
6 s: k = input.key();
7 if (k == "ESC") then; break; end;
8 if (k == "UP") then; y = y - 1; end;
9 .terminal !move x y;
10 .terminal !write "@";
11 @wait 16;
12end;
13
14.terminal !cursor on;
15.terminal !normal;
Error Handling and Constraints
input.key()in normal mode: Returns""and prints a warning alert.@waitoninput.ready(): Compilation error..terminaldirectives: Are expressions and return a value. Every directive returnstrue(b) on success;.terminal !runreturns the child's captured stdout ass,truewhen the process succeeded with no output, andfalsewhen it failed..terminal !move: Arguments must be integers (i).- Terminal Availability: The VM will halt with a fatal error if console handles are redirected or unavailable.
.terminal !run: Runs the argument as a child process and is usable in expressions. When the first argument is a.xcxfile, it is executed directly by the currently runningxcxexecutable (extra arguments are forwarded to the script) - no OS file association is involved. Any other command goes through the OS shell (cmd /Con Windows,sh -celsewhere). The child's stdout is printed to the terminal and returned as ansvalue;truewhen the process succeeded with no output;falsewhen the process failed or could not be started.