class Object
Public Instance Methods
ansi_screen(file_name, max_col = 80, invert = false, bright = true, page = @page)
click to toggle source
a Hiki plugin method to render a file of text with ANSI escape sequences. Attached file name should be specified as file_name. max_row can be specified. invert and bright can be specified to change colors. page can be specified to show a file attached to another page.
# File lib/ansisys.rb, line 736 def ansi_screen(file_name, max_col = 80, invert = false, bright = true, page = @page) return '' unless file_name =~ /\.(txt|rd|rb|c|pl|py|sh|java|html|htm|css|xml|xsl|sql|yaml)\z/i page_file_name = "#{page.untaint.escape}/#{file_name.untaint.escape}" path = "#{@conf.cache_path}/attach/#{page_file_name}" unless File.exists?(path) raise PluginError, "No such file:#{page_file_name}" end data = File.open(path){|f| f.read}.to_euc colors = AnsiSys::Screen.default_css_colors(invert, bright) styles = AnsiSys::CSSFormatter.hash_to_styles(AnsiSys::Screen.css_styles(colors, max_col, nil), '; ') terminal = AnsiSys::Terminal.new terminal.echo(data) return terminal.render(:html, max_col, nil, colors, 'screen', styles, 'e') + "\n" end