Top Level Namespace

Defined Under Namespace

Modules: AnsiSys

Instance Method Summary collapse

Instance Method Details

#ansi_screen(file_name, max_col = 80, invert = false, bright = true, page = @page) ⇒ Object

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.



735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'lib/ansisys.rb', line 735

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