Terminal

class Terminal

Functions for printing styled text to the terminal.

Use functions like print and println instead of kotlin.io.println to automatically downsample any TextColors and TextStyles you use in strings, and to render widgets like table and HorizontalRule.

The default constructor for this class will detect the current terminal capabilities, but you can override this detection by passing your desired value for ansiLevel, hyperlinks, and interactive.

Constructors

Link copied to clipboard
constructor(ansiLevel: AnsiLevel? = null, theme: Theme = Theme.Default, width: Int? = null, height: Int? = null, hyperlinks: Boolean? = null, tabWidth: Int = 8, interactive: Boolean? = null)
constructor(theme: Theme, tabWidth: Int, terminalInterface: TerminalInterface)
constructor(theme: Theme, terminalInterface: TerminalInterface)
constructor(terminalInterface: TerminalInterface)

Properties

Link copied to clipboard

Functions for controlling the terminal's cursor.

Link copied to clipboard

The terminal capabilities that were detected or set in the constructor.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
inline fun <T> Terminal.animation(trailingLinebreak: Boolean = true, crossinline draw: (T) -> Widget): Animation<T>

Create an Animation that uses the draw function to render objects of type T.

Link copied to clipboard
fun danger(message: Any?, whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null, stderr: Boolean = false)

Print a line styled with the theme's danger style.

Link copied to clipboard
fun info(message: Any?, whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null, stderr: Boolean = false)

Print a line styled with the theme's info style.

Link copied to clipboard
fun muted(message: Any?, whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null, stderr: Boolean = false)

Print a line styled with the theme's muted style.

Link copied to clipboard
fun print(widget: Widget, stderr: Boolean = false)

Print a widget to the terminal.

fun print(message: Any?, whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null, stderr: Boolean = false)

Print a message to the terminal.

Link copied to clipboard
fun println(stderr: Boolean = false)

Print a line break to the terminal.

fun println(widget: Widget, stderr: Boolean = false)

Print a widget to the terminal, followed by a line break.

fun println(message: Any?, whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null, stderr: Boolean = false)

Print a message to the terminal, followed by a line break.

Link copied to clipboard
fun prompt(prompt: String, default: String? = null, showDefault: Boolean = true, showChoices: Boolean = true, hideInput: Boolean = false, choices: Collection<String> = emptyList(), promptSuffix: String = ": ", invalidChoiceMessage: String = "Invalid value, choose from "): String?

Print a prompt to the user and return the value they enter.

inline fun <T> prompt(prompt: String, default: T? = null, showDefault: Boolean = true, showChoices: Boolean = true, hideInput: Boolean = false, choices: Collection<T> = emptyList(), promptSuffix: String = ": ", invalidChoiceMessage: String = "Invalid value, choose from ", crossinline convert: (String) -> ConversionResult<T>): T?
Link copied to clipboard
fun rawPrint(message: String, stderr: Boolean = false)

Print a message to the terminal without parsing or rendering it.

Link copied to clipboard
fun readLineOrNull(hideInput: Boolean): String?

Read a line of input from stdin.

Link copied to clipboard
fun render(widget: Widget): String

Render a widget as a string

fun render(message: Any?, whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null): String

Render a message to a string.

Link copied to clipboard
fun success(message: Any?, whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null, stderr: Boolean = false)

Print a line styled with the theme's success style.

Link copied to clipboard
inline fun <T> Terminal.textAnimation(whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null, tabWidth: Int? = null, trailingLinebreak: Boolean = true, crossinline draw: (T) -> String): Animation<T>

Create an Animation that wraps the result of the draw function into a Text widget and renders it.

Link copied to clipboard
fun warning(message: Any?, whitespace: Whitespace = Whitespace.PRE, align: TextAlign = TextAlign.NONE, overflowWrap: OverflowWrap = OverflowWrap.NORMAL, width: Int? = null, stderr: Boolean = false)

Print a line styled with the theme's warning style.