cromo The Cromo Guide
Download PDF IT

std.os

The system the program runs on: its name, the variables of the environment, the current folder, the standard input, and the end of the program. The arguments of the program arrive in main(list<string> args).

cromo
import std.os

println("{} in {}", os.name(), os.currentFolder())
if (!os.hasEnv("HOME")) {
    eprintln("HOME is not set")
    os.exit(1)
}
string input = os.readInput()

The guide: Files, processes and time.

Made from the documentation in the sources of the library.

#Functions

#exit

cromo
void exit(i32 code)

Ends the program at once with the exit code, after writing what was printed. The objects still alive are not destroyed, as with exit() of C.

#readInput

cromo
string readInput()

All the standard input that is left, to its end, as text: what a filter reads. Throws if it is not UTF-8. From a terminal, the input ends with Ctrl+D on Linux, and on Windows with Ctrl+Z at the start of a line and Enter. Read the standard input from one thread at a time.

#readLine

cromo
bool readLine(ref string line)

Reads the next line of the standard input into line, without its end, \n or \r\n; a last line without \n is read too. False at the end of the input, with line empty. Throws if the line is not UTF-8. Read the standard input from one thread at a time.

cromo
string line
for (os.readLine(ref line)) {
    println("> {}", line)
}

#readInputBytes

cromo
list<u8> readInputBytes(i64 most)

Up to most bytes of the standard input, as soon as some arrive, as they are: what a program reads when its input is not text, or has its own lengths. Empty at the end of the input. It reads after what readLine and readInput have read. Read the standard input from one thread at a time.

cromo
list<u8> header = os.readInputBytes(16)

#name

cromo
string name()

The name of the system: "windows", or "linux", also on Android.

#processId

cromo
i64 processId()

The id that the system gives to this process.

#hasEnv

cromo
bool hasEnv(string name)

Whether the variable name is in the environment, also with an empty value. On Windows the names do not distinguish upper and lower case.

#env

cromo
string env(string name)

The value of the variable name of the environment, or "" when it is not set: hasEnv tells an empty value from a missing one. On Windows the names do not distinguish upper and lower case.

#currentFolder

cromo
string currentFolder()

The absolute path of the current folder, from which the relative paths start.

#programPath

cromo
string programPath()

The absolute path of the executable of this program: its folder is where a program finds the files installed next to it.

#processors

cromo
i64 processors()

How many processors this program can use, at least 1: how many threads can work at the same time.

#isTerminal

cromo
bool isTerminal(i32 stream)

Whether a standard stream of this program is a terminal, and not a file or a pipe: 0 for the input, 1 for the output, 2 for the errors, as the descriptors of C. A program asks it before it writes colors, or a line that it rewrites.