Console
Console I/O operations for terminal interaction. The Console class provides static methods for input, output, timing, and system utilities.
xxml
#import Language::Core;
#import Language::System;Output Methods
Write text without a trailing newline.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| message: String^ | None | Write to stdout |
xxml
Run Console::print(String::Constructor("Hello "));
Run Console::print(String::Constructor("World"));
// Output: Hello World (on same line)printLine
Write text with a trailing newline.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| printLine | message: String^ | None | Write line to stdout |
xxml
Run Console::printLine(String::Constructor("Hello World"));
Run Console::printLine(String::Constructor("Next line"));printError
Write to standard error stream.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| printError | message: String^ | None | Write to stderr |
xxml
Run Console::printError(String::Constructor("Error: file not found"));printFormatted
Formatted output with placeholder substitution.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| printFormatted | format: String^, value: String^ | None | Printf-style output |
xxml
Run Console::printFormatted(String::Constructor("Name: %s"), String::Constructor("Alice"));clear
Clear the console screen.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| clear | — | None | Clear terminal |
Input Methods
readLine
Read a line of text from stdin.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| readLine | — | String^ | Read line from stdin |
xxml
Run Console::print(String::Constructor("Enter name: "));
Instantiate String^ As <name> = Console::readLine();
Run Console::printLine(String::Constructor("Hello, ").append(name));readChar
Read a single character.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| readChar | — | String^ | Read single character |
readInt
Read and parse an integer.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| readInt | — | Integer^ | Read and parse integer |
xxml
Run Console::print(String::Constructor("Enter age: "));
Instantiate Integer^ As <age> = Console::readInt();readFloat / readDouble / readBool
Read and parse other primitive types.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| readFloat | — | Float^ | Read and parse float |
| readDouble | — | Double^ | Read and parse double |
| readBool | — | Bool^ | Read and parse boolean |
System Utilities
getTime / getTimeMillis
Get current time since epoch.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| getTime | — | Integer^ | Seconds since epoch |
| getTimeMillis | — | Integer^ | Milliseconds since epoch |
xxml
Instantiate Integer^ As <now> = Console::getTime();
Instantiate Integer^ As <nowMs> = Console::getTimeMillis();sleep
Pause execution for a specified duration.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| sleep | milliseconds: Integer^ | None | Pause for duration |
xxml
Run Console::sleep(Integer::Constructor(1000)); // Sleep 1 secondexit
Terminate the program with an exit code.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| exit | exitCode: Integer^ | None | Terminate process |
xxml
Run Console::exit(Integer::Constructor(0)); // Exit with code 0Environment Variables
getEnv / setEnv
Access and modify environment variables.
| Method | Parameters | Returns | Description |
|---|---|---|---|
| getEnv | varName: String^ | String^ | Get env variable |
| setEnv | varName: String^, value: String^ | Bool^ | Set env variable |
xxml
Instantiate String^ As <path> = Console::getEnv(String::Constructor("PATH"));
Instantiate Bool^ As <success> = Console::setEnv(
String::Constructor("MY_VAR"),
String::Constructor("my_value")
);Complete Example
console_example.xxml
1 #import Language::Core; 2 #import Language::System; 3 4 [ Entrypoint 5 { 6 // Greet user 7 Run Console::print(String::Constructor("What is your name? ")); 8 Instantiate String^ As <name> = Console::readLine(); 9 10 Run Console::print(String::Constructor("How old are you? ")); 11 Instantiate Integer^ As <age> = Console::readInt(); 12 13 // Display info 14 Run Console::printLine(String::Constructor("")); 15 Run Console::printLine(String::Constructor("Hello, ").append(name).append(String::Constructor("!"))); 16 Run Console::printLine(String::Constructor("You are ").append(age.toString()).append(String::Constructor(" years old."))); 17 18 // Timing example 19 Instantiate Integer^ As <start> = Console::getTimeMillis(); 20 Run Console::sleep(Integer::Constructor(500)); 21 Instantiate Integer^ As <elapsed> = Console::getTimeMillis().subtract(start); 22 Run Console::printLine(String::Constructor("Waited ").append(elapsed.toString()).append(String::Constructor("ms"))); 23 24 Exit(0); 25 } 26 ]