* 格式化输出文本
(text: string, options: DisplayOptions = {})
| 22 | * 格式化输出文本 |
| 23 | */ |
| 24 | private static formatText(text: string, options: DisplayOptions = {}): string { |
| 25 | const opts = { ...this.defaultOptions, ...options }; |
| 26 | |
| 27 | let result = text; |
| 28 | |
| 29 | // 添加前缀 |
| 30 | if (opts.prefix) { |
| 31 | result = opts.prefix + result; |
| 32 | } |
| 33 | |
| 34 | // 添加后缀 |
| 35 | if (opts.suffix) { |
| 36 | result = result + opts.suffix; |
| 37 | } |
| 38 | |
| 39 | // 添加缩进 |
| 40 | if (opts.indent && opts.indent > 0) { |
| 41 | const indent = ' '.repeat(opts.indent); |
| 42 | result = indent + result.split('\n').join('\n' + indent); |
| 43 | } |
| 44 | |
| 45 | return result; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * 输出文本 |