DOCUMENTATION

I/O & Terminal

DOCUMENTATION

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

CallReturnsDescription
input.key()sReturns key if available, "" if not
input.key() @waitsWaits for a key and returns it
input.ready()btrue if a key is waiting in the buffer

Key Constants

ValueKey
"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.

DirectiveDescription
.terminal !clearClears the screen
.terminal !exitTerminates the VM process
.terminal !run sRuns s as a child process and returns its captured stdout - see the note below
.terminal !rawRaw mode - no echo, no buffering
.terminal !normalRestores normal terminal mode
.terminal !cursor onShows the cursor
.terminal !cursor offHides the cursor
.terminal !move x yMoves the cursor to position x, y (i)
.terminal !write exprPrints 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.
  • @wait on input.ready(): Compilation error.
  • .terminal directives: Are expressions and return a value. Every directive returns true (b) on success; .terminal !run returns the child's captured stdout as s, true when the process succeeded with no output, and false when 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 .xcx file, it is executed directly by the currently running xcx executable (extra arguments are forwarded to the script) - no OS file association is involved. Any other command goes through the OS shell (cmd /C on Windows, sh -c elsewhere). The child's stdout is printed to the terminal and returned as an s value; true when the process succeeded with no output; false when the process failed or could not be started.