ANSI/VT100 code to change character look (SGR).

By default, resets everything to the terminal’s defaults.

Note:

The escape sequence inserted at the end of the string by terminal-related methods of String resets all character attributes to the terminal’s defaults. So, when combining format a and b, something like ("foo".a + " bar").b will not work as expected, but "foo".a.b + " bar".b will. You may also use TermCharFormat (this class).

Usage example:

print "{(new TermCharFormat).yellow_fg.bold}a{(new TermCharFormat).yellow_fg}b{new TermCharFormat}"

Introduced properties

fun black_bg: TermCharFormat

console :: TermCharFormat :: black_bg

Apply a black background and return self.
fun black_fg: TermCharFormat

console :: TermCharFormat :: black_fg

Apply a black foreground and return self.
fun blue_bg: TermCharFormat

console :: TermCharFormat :: blue_bg

Apply a blue background and return self.
fun blue_fg: TermCharFormat

console :: TermCharFormat :: blue_fg

Apply a blue foreground and return self.
fun bold: TermCharFormat

console :: TermCharFormat :: bold

Apply bold weight and return self.
fun cyan_bg: TermCharFormat

console :: TermCharFormat :: cyan_bg

Apply a cyan background and return self.
fun cyan_fg: TermCharFormat

console :: TermCharFormat :: cyan_fg

Apply a cyan foreground and return self.
fun default: TermCharFormat

console :: TermCharFormat :: default

Apply normal (default) format and return self.
fun default_bg: TermCharFormat

console :: TermCharFormat :: default_bg

Apply the default background and return self.
fun default_fg: TermCharFormat

console :: TermCharFormat :: default_fg

Apply the default foreground and return self.
init from(format: TermCharFormat)

console :: TermCharFormat :: from

Copies the attributes from the specified format.
fun green_bg: TermCharFormat

console :: TermCharFormat :: green_bg

Apply a green background and return self.
fun green_fg: TermCharFormat

console :: TermCharFormat :: green_fg

Apply a green foreground and return self.
fun inverse: TermCharFormat

console :: TermCharFormat :: inverse

Apply reverse video and return self.
fun magenta_bg: TermCharFormat

console :: TermCharFormat :: magenta_bg

Apply a magenta background and return self.
fun magenta_fg: TermCharFormat

console :: TermCharFormat :: magenta_fg

Apply a magenta foreground and return self.
fun normal_weight: TermCharFormat

console :: TermCharFormat :: normal_weight

Apply normal weight and return self.
fun not_underlined: TermCharFormat

console :: TermCharFormat :: not_underlined

Add the attribute that disable underlining and return self.
fun positive: TermCharFormat

console :: TermCharFormat :: positive

Add the attribute that disable reverse video and return self.
fun red_bg: TermCharFormat

console :: TermCharFormat :: red_bg

Apply a red background and return self.
fun red_fg: TermCharFormat

console :: TermCharFormat :: red_fg

Apply a red foreground and return self.
fun steady: TermCharFormat

console :: TermCharFormat :: steady

Add the attribute that disable blinking and return self.
fun underline: TermCharFormat

console :: TermCharFormat :: underline

Apply underlining and return self.
fun white_bg: TermCharFormat

console :: TermCharFormat :: white_bg

Apply a white background and return self.
fun white_fg: TermCharFormat

console :: TermCharFormat :: white_fg

Apply a white foreground and return self.
fun yellow_bg: TermCharFormat

console :: TermCharFormat :: yellow_bg

Apply a yellow background and return self.
fun yellow_fg: TermCharFormat

console :: TermCharFormat :: yellow_fg

Apply a yellow foreground and return self.

Redefined properties

redef type SELF: TermCharFormat

console $ TermCharFormat :: SELF

Type of this instance, automatically specialized in every class
redef fun to_s: String

console $ TermCharFormat :: to_s

User readable representation of self.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun black_bg: TermCharFormat

console :: TermCharFormat :: black_bg

Apply a black background and return self.
fun black_fg: TermCharFormat

console :: TermCharFormat :: black_fg

Apply a black foreground and return self.
fun blue_bg: TermCharFormat

console :: TermCharFormat :: blue_bg

Apply a blue background and return self.
fun blue_fg: TermCharFormat

console :: TermCharFormat :: blue_fg

Apply a blue foreground and return self.
fun bold: TermCharFormat

console :: TermCharFormat :: bold

Apply bold weight and return self.
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
protected fun csi: String

console :: TermEscape :: csi

The Control Sequence Introducer (CSI).
fun cyan_bg: TermCharFormat

console :: TermCharFormat :: cyan_bg

Apply a cyan background and return self.
fun cyan_fg: TermCharFormat

console :: TermCharFormat :: cyan_fg

Apply a cyan foreground and return self.
fun default: TermCharFormat

console :: TermCharFormat :: default

Apply normal (default) format and return self.
fun default_bg: TermCharFormat

console :: TermCharFormat :: default_bg

Apply the default background and return self.
fun default_fg: TermCharFormat

console :: TermCharFormat :: default_fg

Apply the default foreground and return self.
protected fun esc: Char

console :: TermEscape :: esc

The US-ASCII ESC character.
init from(format: TermCharFormat)

console :: TermCharFormat :: from

Copies the attributes from the specified format.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun green_bg: TermCharFormat

console :: TermCharFormat :: green_bg

Apply a green background and return self.
fun green_fg: TermCharFormat

console :: TermCharFormat :: green_fg

Apply a green foreground and return self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun inverse: TermCharFormat

console :: TermCharFormat :: inverse

Apply reverse video and return self.
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun magenta_bg: TermCharFormat

console :: TermCharFormat :: magenta_bg

Apply a magenta background and return self.
fun magenta_fg: TermCharFormat

console :: TermCharFormat :: magenta_fg

Apply a magenta foreground and return self.
fun normal_weight: TermCharFormat

console :: TermCharFormat :: normal_weight

Apply normal weight and return self.
fun not_underlined: TermCharFormat

console :: TermCharFormat :: not_underlined

Add the attribute that disable underlining and return self.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun positive: TermCharFormat

console :: TermCharFormat :: positive

Add the attribute that disable reverse video and return self.
fun red_bg: TermCharFormat

console :: TermCharFormat :: red_bg

Apply a red background and return self.
fun red_fg: TermCharFormat

console :: TermCharFormat :: red_fg

Apply a red foreground and return self.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun steady: TermCharFormat

console :: TermCharFormat :: steady

Add the attribute that disable blinking and return self.
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun underline: TermCharFormat

console :: TermCharFormat :: underline

Apply underlining and return self.
fun white_bg: TermCharFormat

console :: TermCharFormat :: white_bg

Apply a white background and return self.
fun white_fg: TermCharFormat

console :: TermCharFormat :: white_fg

Apply a white foreground and return self.
fun yellow_bg: TermCharFormat

console :: TermCharFormat :: yellow_bg

Apply a yellow background and return self.
fun yellow_fg: TermCharFormat

console :: TermCharFormat :: yellow_fg

Apply a yellow foreground and return self.
package_diagram console::TermCharFormat TermCharFormat console::TermEscape TermEscape console::TermCharFormat->console::TermEscape core::Object Object console::TermEscape->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class TermEscape

console :: TermEscape

A ANSI/VT100 escape sequence.

Class definitions

console $ TermCharFormat
# ANSI/VT100 code to change character look (SGR).
#
# By default, resets everything to the terminal’s defaults.
#
# Note:
#
# The escape sequence inserted at the end of the string by terminal-related
# methods of `String` resets all character attributes to the terminal’s
# defaults. So, when combining format `a` and `b`, something like
# `("foo".a + " bar").b` will not work as expected, but `"foo".a.b + " bar".b`
# will. You may also use `TermCharFormat` (this class).
#
# Usage example:
#
#     print "{(new TermCharFormat).yellow_fg.bold}a{(new TermCharFormat).yellow_fg}b{new TermCharFormat}"
class TermCharFormat
	super TermEscape

	private var attributes: Array[String] = new Array[String]

	# Copies the attributes from the specified format.
	init from(format: TermCharFormat) do
		attributes.add_all(format.attributes)
	end

	redef fun to_s do return "{csi}{attributes.join(";")}m"

	# Apply the specified SGR and return `self`.
	private fun apply(sgr: String): TermCharFormat do
		attributes.add(sgr)
		return self
	end

	# Apply normal (default) format and return `self`.
	fun default: TermCharFormat do return apply("0")

	# Apply bold weight and return `self`.
	fun bold: TermCharFormat do return apply("1")

	# Apply underlining and return `self`.
	fun underline: TermCharFormat do return apply("4")

	# Apply blinking or bold weight and return `self`.
	fun blink: TermCharFormat do return apply("5")

	# Apply reverse video and return `self`.
	fun inverse: TermCharFormat do return apply("7")

	# Apply normal weight and return `self`.
	fun normal_weight: TermCharFormat do return apply("22")

	# Add the attribute that disable underlining and return `self`.
	fun not_underlined: TermCharFormat do return apply("24")

	# Add the attribute that disable blinking and return `self`.
	fun steady: TermCharFormat do return apply("25")

	# Add the attribute that disable reverse video and return `self`.
	fun positive: TermCharFormat do return apply("27")

	# Apply a black foreground and return `self`.
	fun black_fg: TermCharFormat do return apply("30")

	# Apply a red foreground and return `self`.
	fun red_fg: TermCharFormat do return apply("31")

	# Apply a green foreground and return `self`.
	fun green_fg: TermCharFormat do return apply("32")

	# Apply a yellow foreground and return `self`.
	fun yellow_fg: TermCharFormat do return apply("33")

	# Apply a blue foreground and return `self`.
	fun blue_fg: TermCharFormat do return apply("34")

	# Apply a magenta foreground and return `self`.
	fun magenta_fg: TermCharFormat do return apply("35")

	# Apply a cyan foreground and return `self`.
	fun cyan_fg: TermCharFormat do return apply("36")

	# Apply a white foreground and return `self`.
	fun white_fg: TermCharFormat do return apply("37")

	# Apply the default foreground and return `self`.
	fun default_fg: TermCharFormat do return apply("39")

	# Apply a black background and return `self`.
	fun black_bg: TermCharFormat do return apply("40")

	# Apply a red background and return `self`.
	fun red_bg: TermCharFormat do return apply("41")

	# Apply a green background and return `self`.
	fun green_bg: TermCharFormat do return apply("42")

	# Apply a yellow background and return `self`.
	fun yellow_bg: TermCharFormat do return apply("43")

	# Apply a blue background and return `self`.
	fun blue_bg: TermCharFormat do return apply("44")

	# Apply a magenta background and return `self`.
	fun magenta_bg: TermCharFormat do return apply("45")

	# Apply a cyan background and return `self`.
	fun cyan_bg: TermCharFormat do return apply("46")

	# Apply a white background and return `self`.
	fun white_bg: TermCharFormat do return apply("47")

	# Apply the default background and return `self`.
	fun default_bg: TermCharFormat do return apply("49")
end
lib/console/console.nit:171,1--284,3