website is under construction
Standard Library

Console

The console module writes to and reads from the terminal.

Along with type(), console is one of only two names available without an import. console.log() is how a Ghost program writes a line of output.

The logging methods each prefix their output with a label, which is what separates them from log().

Output goes through the current scope's writer rather than straight to the process's standard output, so redirected output is respected — inside an http.handle() callback, every method here writes to the response body.

Methods

Every output method accepts any number of values, and joins them with a single space.

console.clear()

Clears the terminal.

console.clear()

console.error()

Outputs an error message to the console, prefixed with error:.

console.error("This is an error message")

// >> error: This is an error message

console.info()

Outputs an informative message to the console, prefixed with info:.

console.info("This is an info message")

// >> info: This is an info message

console.log()

Outputs a message to the console for general logging information, followed by a newline. Unlike the other logging methods it adds no prefix.

console.log("This is a log message")

// >> This is a log message

console.newLine()

Outputs a single blank line.

console.newLine()

console.write()

Outputs values without a trailing newline, so the next write continues on the same line.

console.write("Loading")
console.write("...")
console.newLine()

// >> Loading...

console.read()

Reads one line from standard input and returns it as a string, without the newline. If a string is passed, it is written first as a prompt. At end of input it returns null.

name = console.read("What is your name? ")

console.log("Hello, " + name)

console.warn()

Outputs a warning message to the console, prefixed with warning:.

console.warn("This is a warning message")

// >> warning: This is a warning message