Console

io.worxbend.tui.dsl.Console
object Console

Print mode: render any view, widget or Text once to standard output as styled text, with no runner, no event loop and no terminal taken over — the way Rich prints a table or Ink renders to a string.

This is what opens every widget — tables, trees, charts, Markdown, panels — to a command-line tool that will never be a full-screen application: Console.print(panel("Build")(table(rows, header))) lays the view out at the terminal's width, measures the rows it needs, composes a frame through Snapshot and writes it as newline-separated rows with the colour depth the environment allows. The encoding is FrameEncoder.encodeLines in tui-terminal: no cursor movement, styles as deltas from the terminal default, a reset on every row that set one — and, when colour is off, no escape sequence at all, so NO_COLOR=1 mytool > report.txt leaves a plain text file behind.

width and colors default to what detectedWidth and detectedColors read from the process: the terminal's width when standard output is one, else COLUMNS, else 80 columns; the colour depth ColorDepth.detect resolves (NO_COLOR, FORCE_COLOR, CLICOLOR_FORCE, TERM=dumb and the terminal's capability) when standard output is a terminal, and no colour when it is not, unless one of the force variables says otherwise. The height is the view's own measurement — Element.intrinsicHeight at that width — falling back to LINES, then 24 rows, for a view that cannot say (one whose root is .fill, say); pass height to decide yourself.

What it deliberately is not: interactive or animated, for the same reasons Snapshot is not. Focus is drawn on the first focusable element, an animated element renders at whatever position it computes for the time it is handed, and reactive reads subscribe nothing. A TuiApp that should degrade to this when it has no terminal sets RunnerConfig.withNonInteractive instead of calling this directly — see io.worxbend.tui.runtime.NonInteractivePolicy.

Shadowing, stated plainly because it bites: under import io.worxbend.tui.dsl.* the name Console resolves here rather than to scala.Console, so an app that wrote Console.println(...) or Console.err with the one import has to write scala.Console.err (or plain println). The name is kept because it is the one every terminal toolkit uses for exactly this object.

Callable from any thread: it registers no render loop and writes no signal. The print variants write to the standard-output descriptor as UTF-8 regardless of the platform charset — every border and glyph is non-ASCII, and a POSIX locale would otherwise print them as ? — and flush after each call.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Console.type

Members list

Value members

Concrete methods

def detectedColors(env: Map[String, String] = ..., terminal: Boolean = ...): ColorDepth

The colour depth to print with. On a terminal, what ColorDepth.detect resolves from env. Off a terminal — a file, a pipe — no colour at all, because TERM is still set in a piped process's environment and would otherwise fill the file with escape sequences; FORCE_COLOR or CLICOLOR_FORCE overrides that, which is how a pager or a CI log viewer that renders ANSI asks for it.

The colour depth to print with. On a terminal, what ColorDepth.detect resolves from env. Off a terminal — a file, a pipe — no colour at all, because TERM is still set in a piped process's environment and would otherwise fill the file with escape sequences; FORCE_COLOR or CLICOLOR_FORCE overrides that, which is how a pager or a CI log viewer that renders ANSI asks for it.

Attributes

def detectedHeight(env: Map[String, String] = ...): Int

How tall a no-TTY run composes its frame, and the height a view that cannot measure itself prints at: a positive LINES, else FallbackHeight.

How tall a no-TTY run composes its frame, and the height a view that cannot measure itself prints at: a positive LINES, else FallbackHeight.

Attributes

def detectedWidth(env: Map[String, String] = ..., terminalWidth: => Option[Int] = ...): Int

How wide to print: the terminal's own width when standard output is one, else a positive COLUMNS, else FallbackWidth. Both inputs are parameters so a test can inject them; the defaults read the process.

How wide to print: the terminal's own width when standard output is one, else a positive COLUMNS, else FallbackWidth. Both inputs are parameters so a test can inject them; the defaults read the process.

Attributes

def isNonInteractive(env: Map[String, String] = ..., terminal: Boolean = ...): Boolean

Whether a run has no terminal to be interactive on: standard output is not a terminal, or CI is set to anything but the empty string, 0 or false. What TuiApp.printTarget consults before applying a io.worxbend.tui.runtime.NonInteractivePolicy.

Whether a run has no terminal to be interactive on: standard output is not a terminal, or CI is set to anything but the empty string, 0 or false. What TuiApp.printTarget consults before applying a io.worxbend.tui.runtime.NonInteractivePolicy.

Attributes

def printLines(text: Text): Unit

Writes text as styled lines with the detected colour depth, newline-terminated.

Writes text as styled lines with the detected colour depth, newline-terminated.

Attributes

def render(view: View, width: Int, colors: ColorDepth, theme: Theme = ..., height: Option[Int] = ...): String

view as styled text: laid out at width, height rows tall when given and the view's own measurement otherwise, encoded for colors. Rows are separated by \n; there is no trailing newline, so the result slots into a larger message. theme is the one the view's themed factories draw with.

view as styled text: laid out at width, height rows tall when given and the view's own measurement otherwise, encoded for colors. Rows are separated by \n; there is no trailing newline, so the result slots into a larger message. theme is the one the view's themed factories draw with.

Attributes

def renderLines(text: Text, colors: ColorDepth): String

A Text as styled lines: one row per Line, as wide as its widest line, each span's style encoded for colors.

A Text as styled lines: one row per Line, as wide as its widest line, each span's style encoded for colors.

Attributes

def renderWidget(widget: Widget, size: Size, colors: ColorDepth): String

A raw widget rendered into a size-shaped buffer, encoded for colors — for a widget that is not wrapped in an element, or one whose size the caller already knows. Named apart from render rather than overloading it: a View is a context function, and an overloaded parameter gives the compiler no expected type to build one from, so render(panel(...)) would stop compiling.

A raw widget rendered into a size-shaped buffer, encoded for colors — for a widget that is not wrapped in an element, or one whose size the caller already knows. Named apart from render rather than overloading it: a View is a context function, and an overloaded parameter gives the compiler no expected type to build one from, so render(panel(...)) would stop compiling.

Attributes

def write(text: String): Unit

Concrete fields

val FallbackHeight: Int

The height print mode falls back to when the view cannot measure itself and LINES does not say.

The height print mode falls back to when the view cannot measure itself and LINES does not say.

Attributes

val FallbackWidth: Int

The width print mode falls back to when neither the terminal nor COLUMNS says.

The width print mode falls back to when neither the terminal nor COLUMNS says.

Attributes