Class: VimColor::Format_ansi

Inherits:
Object
  • Object
show all
Defined in:
lib/msgpack/idl/command/vimcolor.rb

Constant Summary collapse

AnsiCodes =
{
	:normal        =>  0,
	:reset         =>  0,
	:bold          =>  1,
	:dark          =>  2,
	:italic        =>  3,
	:underline     =>  4,
	:blink         =>  5,
	:rapid_blink   =>  6,
	:negative      =>  7,
	:concealed     =>  8,
	:strikethrough =>  9,
	:black         => 30,
	:red           => 31,
	:green         => 32,
	:yellow        => 33,
	:blue          => 34,
	:magenta       => 35,
	:cyan          => 36,
	:white         => 37,
	:on_black      => 40,
	:on_red        => 41,
	:on_green      => 42,
	:on_yellow     => 43,
	:on_blue       => 44,
	:on_magenta    => 45,
	:on_cyan       => 46,
	:on_white      => 47,
}

Instance Method Summary collapse

Constructor Details

#initialize(colors = {}) ⇒ Format_ansi

Returns a new instance of Format_ansi.



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/msgpack/idl/command/vimcolor.rb', line 220

def initialize(colors = {})
	@result = ''
	@colors = Hash.new([])
	@colors.merge!({
		'Comment'    => [ :cyan ],
		'Constant'   => [ :red ],
		'Identifier' => [ :green  ],
		'Statement'  => [ :yellow ],
		'PreProc'    => [ :magenta ],
		'Type'       => [ :green ],
		'Special'    => [ :magenta ],
		'Underlined' => [ :underline ],
		'Error'      => [ :red ],
		'Todo'       => [ :black, :on_yellow ],
	})
	@colors.merge!(colors)
end

Instance Method Details

#push(type, text) ⇒ Object



237
238
239
240
241
242
243
244
245
246
# File 'lib/msgpack/idl/command/vimcolor.rb', line 237

def push(type, text)
	seq = ''
	codes = @colors[type].dup
	codes.unshift(:reset)
	codes.each {|c|
		num = AnsiCodes[c]
		seq << "\e[#{num}m" if num
	}
	@result << seq << text
end

#resultObject



247
248
249
250
# File 'lib/msgpack/idl/command/vimcolor.rb', line 247

def result
	@result << "\e[0m"
	@result
end