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

print

Write text without a trailing newline.

MethodParametersReturnsDescription
printmessage: String^NoneWrite 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.

MethodParametersReturnsDescription
printLinemessage: String^NoneWrite line to stdout
xxml
Run Console::printLine(String::Constructor("Hello World"));
Run Console::printLine(String::Constructor("Next line"));

printError

Write to standard error stream.

MethodParametersReturnsDescription
printErrormessage: String^NoneWrite to stderr
xxml
Run Console::printError(String::Constructor("Error: file not found"));

printFormatted

Formatted output with placeholder substitution.

MethodParametersReturnsDescription
printFormattedformat: String^, value: String^NonePrintf-style output
xxml
Run Console::printFormatted(String::Constructor("Name: %s"), String::Constructor("Alice"));

clear

Clear the console screen.

MethodParametersReturnsDescription
clearNoneClear terminal

Input Methods

readLine

Read a line of text from stdin.

MethodParametersReturnsDescription
readLineString^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.

MethodParametersReturnsDescription
readCharString^Read single character

readInt

Read and parse an integer.

MethodParametersReturnsDescription
readIntInteger^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.

MethodParametersReturnsDescription
readFloatFloat^Read and parse float
readDoubleDouble^Read and parse double
readBoolBool^Read and parse boolean

System Utilities

getTime / getTimeMillis

Get current time since epoch.

MethodParametersReturnsDescription
getTimeInteger^Seconds since epoch
getTimeMillisInteger^Milliseconds since epoch
xxml
Instantiate Integer^ As <now> = Console::getTime();
Instantiate Integer^ As <nowMs> = Console::getTimeMillis();

sleep

Pause execution for a specified duration.

MethodParametersReturnsDescription
sleepmilliseconds: Integer^NonePause for duration
xxml
Run Console::sleep(Integer::Constructor(1000));  // Sleep 1 second

exit

Terminate the program with an exit code.

MethodParametersReturnsDescription
exitexitCode: Integer^NoneTerminate process
xxml
Run Console::exit(Integer::Constructor(0));  // Exit with code 0

Environment Variables

getEnv / setEnv

Access and modify environment variables.

MethodParametersReturnsDescription
getEnvvarName: String^String^Get env variable
setEnvvarName: 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]

See Also