enum State { None , Color , Link } export class Text { private _text : string = "" ; public state = State . None ; constructor ( initialText = "" ) { this . _text = initialText ; } public append ( text ) { this . _text += text ; return this ; } param color example public appendColor ( color ) { if ( color . length > 8 ) color = color . slice ( 0 , 8 ) ; color = color . padEnd ( 8 , "F" ) ; if ( this . state === State . Link ) this . clearState ( ) ; this . _text += `[${ color }]` ; this . state = State . Color ; return this ; } public appendLink ( link ) { if ( this . state === State . Color ) this . clearState ( ) ; this . _text += `[${ link }]` ; this . state = State . Link ; return this ; } public clearState ( ) { this . _text += "[]" ; this . state = State . None ; return this ; } set text ( value ) { this . _text = value ; this . state = State . None ; } get text ( ) { return this . _text ; } toString ( ) { return this . _text ; } }