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 Objecttrait Matchableclass Any
- Self type
-
Console.type