开发预览 更新于 2026-05-10

AnsiText ANSI 文本

解析 ANSI 转义序列(\x1b[...m)渲染为彩色 span,纯展示,不依赖 xterm.js。

基础用法

支持基础 16 色(前景 + 背景)+ bright 8 色 + 修饰(bold / dim / italic / underline / inverse)。 颜色映射到 token,与主题一致;不解析 24-bit truecolor 转义。

 build succeeded in 1.2s
  warning: 3 unused exports
 test failed

  expected:  foo 
  received:  bar 
<CfAnsiText :text="terminalOutput" />
<CfAnsiText text={terminalOutput} />

3 档尺寸

sm / md / lg 调整字号与行距,常用于 toast 内紧凑日志(sm)vs 终端面板(lg)。

 test passed
  duration: 12ms
  expected:  foo 
  actual  :  bar 
 test passed
  duration: 12ms
  expected:  foo 
  actual  :  bar 
 test passed
  duration: 12ms
  expected:  foo 
  actual  :  bar 
<CfAnsiText :text="log" size="sm" />
<CfAnsiText :text="log" size="lg" />
<CfAnsiText text={log} size="sm" />
<CfAnsiText text={log} size="lg" />

API

属性类型默认值说明
textstring含 ANSI 转义的字符串
size'sm' | 'md' | 'lg''md'
wrapbooleantrue软换行
preserveWhitespacebooleantrue<pre> 行为

支持的 SGR 代码:0 1 2 3 4 7 22 23 24 27 30-37 39 40-47 49 90-97 100-107

反馈与讨论

AnsiText ANSI 文本 的讨论

0
0 / 600
一键发送
正在加载评论...