Djinn Lang
Std

Console

Overview

The Console struct in std::sys provides standard I/O operations. It supports both synchronous and async output, with a buffered formatting system that handles {0}, {1}, etc. placeholders.

import std::sys;

Methods

Method

Description

Console.printf(i8* format)Writes a C-style format string to stdout (delegates to C printf).
Console.error(i8* message)Writes a message to stderr. Returns c_result.
Console.writeSync(str format, ...args)Synchronous buffered write with placeholder formatting.
await Console.write(str format, ...args)Async buffered write with placeholder formatting.
await Console.print(i8* message, i64 len)Async raw write to stdout.
await Console.readLine()Async read a line from stdin. Returns void* buffer.

Formatted Output

writeSync and write support indexed placeholders {0}, {1}, etc. with variadic arguments. The formatting engine inspects runtime type info to print integers, floats, and strings:

import std::sys;

void main() {
    Console.writeSync("Hello {0}, you are {1} years old\n", "Alice", 30);
}

Async I/O

The async methods use the Djinn runtime's event loop for non-blocking I/O:

import std::sys;

async void main() {
    await Console.write("Enter your name: ");
    void* input = await Console.readLine();
    await Console.write("Hello, {0}!\n", (i8*)input);
}

Constants

Constant

Value

Description

Console.stdin0Standard input file descriptor
Console.stdout1Standard output file descriptor
Console.stderr2Standard error file descriptor

On this page