classafTerminal::AnsiBuf

sys::Obj
  afTerminal::AnsiBuf

Generates a sequence of ANSI escape codes.

Note that generated SGR command sequences are optimised where possible.

ESC

Source

const static Int ESC := 27

The ESC char, 0x1B.

add

Source

This add(Obj? x)

Convenience for print().

addChar

Source

This addChar(Int ch)

Convenience for printChar().

backspace

Source

This backspace()

Convenience for printChar('\b').

bg

Source

This bg(Color? col)

Sets the background colour to the given Color. Any alpha value is ignored. If null is passed, this method does nothing.

ansi-sequence: ESC[48;2;${r};${g};${b}m
bgIdx

Source

This bgIdx(Int? i)

Sets the background colour to the given palette colour (0..255). If null is passed, this method does nothing.

ansi-sequence: ESC[48;5;${i}m
bgReset

Source

This bgReset()

Resets the foreground colour to default.

ansi-sequence: ESC[49m
bgRgb

Source

This bgRgb(Int? rgb)

Sets the background colour to the given RGB integer. If null is passed, this method does nothing.

  • bits 16-23 red
  • bits 8-15 green
  • bits 0-7 blue

For example orange would be 0xFF_A5_00.

ansi-sequence: ESC[48;2;${r};${g};${b}m
bold

Source

This bold(Bool onOff := true)

Turns bold on or off.

ansi-sequence: ESC[1m or ESC[21m
clear

Source

This clear()

Clear the contents of the string buffer so that is has a size of zero. Return this.

clearLine

Source

This clearLine()

Clears the current line. The cursor position is unaffected.

ansi-sequence: ESC[2K
clearLineToEnd

Source

This clearLineToEnd()

Clears the current line from the cursor to the end. The cursor position is unaffected.

ansi-sequence: ESC[0K
clearLineToStart

Source

This clearLineToStart()

Clears the current line from the cursor to the start. The cursor position is unaffected.

ansi-sequence: ESC[1K
clearScreen

Source

This clearScreen()

Clears the screen.

ansi-sequence: ESC[2J
conceal

Source

This conceal(Bool onOff := true)

Turns concealed text on or off.

ansi-sequence: ESC[8m or ESC[28m

Not implemented.

crossedOut

Source

This crossedOut(Bool onOff := true)

Turns crossed out on or off.

ansi-sequence: ESC[4m or ESC[24m

Note this is represented by a squiggly underline in the ANSI Terminal.

csi

Source

This csi()

Writes the Control Sequence Initiator.

ansi-sequence: ESC[
curDown

Source

This curDown(Int? rows := 1)

Moves the cursor up a number of rows. Passing in 0 or null does nothing.

ansi-sequence: ESC[${rows}B
curEnd

Source

This curEnd()

Moves the cursor to the end of the current line.

ansi-sequence: ESC[w

Note this is an Alien-Factory extension - not an ANSI standard.

curHome

Source

This curHome()

Moves the cursor to the start of the current line.

ansi-sequence: ESC[v

Note this is an Alien-Factory extension - not an ANSI standard.

curHorizonal

Source

This curHorizonal(Int? column := 1)

Moves the cursor to an absolute column position. Note that ANSI standards state that column is 1 based, so curHorizonal(1) returns the cursor to the start of the line. Passing in 0 or null does nothing.

ansi-sequence: ESC[${col}G
curLeft

Source

This curLeft(Int? cols := 1)

Moves the cursor left a number of rows. Passing in 0 or null does nothing.

ansi-sequence: ESC[${cols}D
curRestore

Source

This curRestore()

Restores the cursor position - both horizontal and vertical. Does nothing if a cursor position has not yet been saved.

ansi-sequence: ESC[u
curRight

Source

This curRight(Int? cols := 1)

Moves the cursor right a number of rows. Passing in 0 or null does nothing.

ansi-sequence: ESC[${cols}C
curSave

Source

This curSave()

Saves the cursor position - both horizontal and vertical.

ansi-sequence: ESC[s
curUp

Source

This curUp(Int? rows := 1)

Moves the cursor up a number of rows. Passing in 0 or null does nothing.

ansi-sequence: ESC[${rows}A
fg

Source

This fg(Color? col)

Sets the foreground colour to the given Color. Any alpha value is ignored. If null is passed, this method does nothing.

ansi-sequence: ESC[38;2;${r};${g};${b}m
fgIdx

Source

This fgIdx(Int? i)

Sets the foreground colour to the given palette colour. (0..255) If null is passed, this method does nothing.

ansi-sequence: ESC[38;5;${i}m
fgReset

Source

This fgReset()

Resets the foreground colour to default.

ansi-sequence: ESC[39m
fgRgb

Source

This fgRgb(Int? rgb)

Sets the foreground colour to the given RGB integer. If null is passed, this method does nothing.

  • bits 16-23 red
  • bits 8-15 green
  • bits 0-7 blue

For example orange would be 0xFF_A5_00.

ansi-sequence: ESC[38;2;${r};${g};${b}m
italic

Source

This italic(Bool onOff := true)

Turns italics on or off.

ansi-sequence: ESC[3m or ESC[23m
make

Source

new make(Str? str := null)

Creates an AnsiBuf instance , optionally with the given string / ANSI sequence.

newLine

Source

This newLine()

Convenience for printChar('\n').

print

Source

This print(Obj? x := "")

Adds x.toStr to the end of this buffer. If x is null then the string "null" is added.

printChar

Source

This printChar(Int ch)

Optimised implementation for print(ch.toChar).

printFandoc

Source

This printFandoc(Str fandoc, Int? maxWidth := null)

Prints the given fandoc string to the buffer, converting bold and italic formatting to their ANSI representation.

If maxWidth is given then all text is wrapped at that width.

Pass the terminal column width as maxWidth to ensure all text is visible on screen.

printLine

Source

This printLine(Obj? x := "")

Adds x.toStr + "\n" to the end of this buffer. If x is null then the string "null" is added.

removeEscapeCodes

Source

const static Str removeEscapeCodes(Str str)

Removes all escape codes and non-printable characters from the given string.

reset

Source

This reset()

Resets text to:

  • default foreground colour
  • default background colour
  • non-bold
  • non-italics
  • no underline
ansi-sequence: ESC[m
size

Source

Int size()

Returns the number of chars in the buf.

toAnsi

Source

Str toAnsi()

Returns the contents of this ANSI buffer as a string.

toPlain

Source

Str toPlain()

Returns a copy of this ANSI string with all the escape codes and non-printable characters removed.

toStr

Source

virtual override Str toStr()

Returns toAnsi().

underline

Source

This underline(Bool onOff := true)

Turns underline on or off.

ansi-sequence: ESC[4m or ESC[24m
write

Source

This write(Obj? x)

Convenience for print().

writeChar

Source

This writeChar(Int ch)

Convenience for printChar().