简体   繁体   English

如何美化shell字符串?

[英]How to beautify shell string?

I am getting strings from a shell output.我从 shell 输出中获取字符串。 They are formated using the shell colors eg :它们使用外壳颜色进行格式化,例如

[2m36:13 [22m [31mabcdefgh...xyz [39m

颜色定义列表

I'd like to show the formated string in a browser, ie with colors and without their definitions.我想在浏览器中显示格式化的字符串,带有颜色而没有它们的定义。

So is there any library or React Component for that ?那么是否有任何库或 React 组件呢?

Thanks谢谢

edit : I'd like something like this :编辑:我想要这样的东西:

function shell2Html(str) { /* ... */ }
shell2Html("[2m36:13 [22m [31mabcdefgh...xyz [39m")
// returns "<span class="red"><span class="bold">abcdefgh</span></span>"

您可以在 console.log 消息中添加 CSS:

console.log('%cHello World', 'color: red');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM