← index

Termabstract

inherits Object

Terminal facts and markup rendering. color? answers whether styled output is on — the same detection the standard-stream writers use (a terminal, NO_COLOR unset, CLICOLOR_FORCE honored) — and width/height the console size. render: turns color markup into escape codes unconditionally (for output that bypasses the std streams); strip: turns it into plain text.

Term.strip:#ANSI'[red]x[/]'.string     "* -> 'x'

Class methods

color?

Whether styled output is ON for this run — stdout is a terminal, NO_COLOR is unset (or CLICOLOR_FORCE set). The std-stream writers strip color exactly when this is false, so it is the "should I draw the fancy version?" question.

native

height

The console height in rows, or nil when there is no terminal to measure.

native

render:

The markup (a String or ANSI value) rendered to ANSI escape codes UNCONDITIONALLY — for output that bypasses the standard streams (a file to be cated, a socket). Writing an ANSI value to [IO]Stdout/Stderr does this automatically when color?.

(Term.render:'[bold]x[/]').length > 1     "* -> true

native

strip:

The plain text of some markup (a String or ANSI value) — tags applied and escape codes removed, exactly what a non-color write emits. The rendered width of styled text is (Term.strip:x).length.

Term.strip:'[red]on [[fire]![/]'     "* -> 'on [fire]!'

native

tty?

Whether standard output is a terminal (false when piped or redirected). color? is usually the better question — it also honors NO_COLOR.

native

width

The console width in columns, or nil when there is no terminal to measure (piped output).

native