classafTerminal::AnsiBuf
sys::Obj afTerminal::AnsiBuf
Generates a sequence of ANSI escape codes.
Note that generated SGR command sequences are optimised where possible.
- ESC
const static Int ESC := 27
The
ESC
char,0x1B
.- add
Convenience for
print()
.- addChar
Convenience for
printChar()
.- backspace
This backspace()
Convenience for printChar(
\b
).- bg
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
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
This bgReset()
Resets the foreground colour to default.
ansi-sequence: ESC[49m
- bgRgb
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
Turns bold on or off.
ansi-sequence: ESC[1m or ESC[21m
- clear
This clear()
Clear the contents of the string buffer so that is has a size of zero. Return this.
- clearLine
This clearLine()
Clears the current line. The cursor position is unaffected.
ansi-sequence: ESC[2K
- clearLineToEnd
This clearLineToEnd()
Clears the current line from the cursor to the end. The cursor position is unaffected.
ansi-sequence: ESC[0K
- clearLineToStart
This clearLineToStart()
Clears the current line from the cursor to the start. The cursor position is unaffected.
ansi-sequence: ESC[1K
- clearScreen
This clearScreen()
Clears the screen.
ansi-sequence: ESC[2J
- conceal
This conceal(Bool onOff := true)
Turns concealed text on or off.
ansi-sequence: ESC[8m or ESC[28m
Not implemented.
- crossedOut
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
This csi()
Writes the Control Sequence Initiator.
ansi-sequence: ESC[
- curDown
Moves the cursor up a number of rows. Passing in
0
ornull
does nothing.ansi-sequence: ESC[${rows}B
- curEnd
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
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
This curHorizonal(Int? column := 1)
Moves the cursor to an absolute column position. Note that ANSI standards state that
column
is 1 based, socurHorizonal(1)
returns the cursor to the start of the line. Passing in0
ornull
does nothing.ansi-sequence: ESC[${col}G
- curLeft
Moves the cursor left a number of rows. Passing in
0
ornull
does nothing.ansi-sequence: ESC[${cols}D
- curRestore
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
Moves the cursor right a number of rows. Passing in
0
ornull
does nothing.ansi-sequence: ESC[${cols}C
- curSave
This curSave()
Saves the cursor position - both horizontal and vertical.
ansi-sequence: ESC[s
- curUp
Moves the cursor up a number of rows. Passing in
0
ornull
does nothing.ansi-sequence: ESC[${rows}A
- fg
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
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
This fgReset()
Resets the foreground colour to default.
ansi-sequence: ESC[39m
- fgRgb
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
This italic(Bool onOff := true)
Turns italics on or off.
ansi-sequence: ESC[3m or ESC[23m
- make
new make(Str? str := null)
Creates an
AnsiBuf
instance , optionally with the given string / ANSI sequence.- newLine
This newLine()
Convenience for printChar(
\n
).- print
Adds
x.toStr
to the end of this buffer. Ifx
is null then the string "null" is added.- printChar
Optimised implementation for
print(ch.toChar)
.- printFandoc
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
Adds
x.toStr + "\n"
to the end of this buffer. Ifx
is null then the string "null" is added.- removeEscapeCodes
static Str removeEscapeCodes(Str str)
Removes all escape codes and non-printable characters from the given string.
- reset
This reset()
Resets text to:
- default foreground colour
- default background colour
- non-bold
- non-italics
- no underline
ansi-sequence: ESC[m
- size
Int size()
Returns the number of chars in the buf.
- toAnsi
Str toAnsi()
Returns the contents of this ANSI buffer as a string.
- toPlain
Str toPlain()
Returns a copy of this ANSI string with all the escape codes and non-printable characters removed.
- toStr
virtual override Str toStr()
Returns
toAnsi()
.- underline
This underline(Bool onOff := true)
Turns underline on or off.
ansi-sequence: ESC[4m or ESC[24m
- write
Convenience for
print()
.- writeChar
Convenience for
printChar()
.