Skip to content

Protocol

Console

Protocol for powering styled Console I/O.
protocol Console : AnyObject, Sendable

Output

Consoles can output stylized text via the ConsoleText struct.

console.output("Hello, " + "world!".consoleText(color: .green))

Tip

See ConsoleStyle for all available text style options.

There are also convenience methods for printing common styles.

console.info("Here is some information")

Input

Consoles can also request input from the user.

let answer = console.ask("How are you doing?")
print(answer)

Clear

Consoles can clear previously outputted content using clear(_:).

console.print("Hello!")
console.clear(.line) // delete hello

See pushEphemeral() method for clearing arbitrary chunks of output.

Other

Use the report(error:newLine:) method for reporting errors to the Console.

Get the Console’s current size using the size property.

Topics

Instance Properties

Instance Methods

Relationships

Inherits From

  • Swift.Sendable
  • Swift.SendableMetatype

Conforming Types

See Also

Terminal