linux shell output to html

后端 未结 5 1847
时光说笑
时光说笑 2020-12-08 05:45

is there any way to convert bash output to html ? for example if I had some colorized output in bash ( something like htop ), how can I convert it to html tags ... ( somethi

5条回答
  •  余生分开走
    2020-12-08 06:05

    Without any pretty-printing, the simplest thing you can always do is to escape everything that needs escaping, and wrap a basic HTML shell around (the following should be valid minimal HTML5). For example, get a hold of fastesc: http://raa.ruby-lang.org/project/fastesc/, and that wrap it into an HTML shell.

    If you want to preserve the ANSI magic, then you need to convert that to HTML, perhaps with http://ansi-sys.rubyforge.org/

    And then do something like this, depending on your needs:

    require 'ansisys'
    
    
    def ansi_escape(string)
        terminal = AnsiSys::Terminal.new
        terminal.echo(string)
        terminal.render 
    end
    
    def to_html(string)
        %Q{ 
            Converted to html
            
            #{ansi_escape(string)}
            
    } end

提交回复
热议问题