Esempio n. 1
0
File: pyc_dbg.py Progetto: 0xcc/pyc
	def context_lines(self, lines, lineno, **kwargs):
		opts = {
			'highlight':			{},  				#dict of color => highlight set
			'output_size':			1,					#total number of context lines
			'prev_lines':			0,					#amt of preceding lines of context
			'arrow':				False,
			'arrow_color':			None
		}

		for k in opts.keys():
			if k in kwargs:
				opts[k] = kwargs[k]

		start = lineno - opts['prev_lines']
		if start < 1:
			start = 1 
		
		fin = start + opts['output_size']
		if fin > (len(lines) - 1):
			fin = (len(lines) - 1)

		output = []
		for i in range(start, fin):
			if opts['arrow'] and i == (lineno):
				arr_s = "<<"+"-"*40
				if opts['arrow_color']:
					arr_s = pyc_color.ansi_color(arr_s, opts['arrow_color'])
				out = "%d\t%s %s" % (i, lines[i], arr_s)
			else:
				out = "%d\t%s" % (i, lines[i])

			for (color, hset) in opts['highlight'].items():
				if i in hset:
					out = pyc_color.ansi_color(out, color)
					break

			output.append(out)
		
		return output
Esempio n. 2
0
File: pyc_dbg.py Progetto: 0xcc/pyc
	def live_context(self, live_map, prev_live_map, io):
		for (name, (val, live, location) ) in live_map.items():
			left = "%s(%s)" % (name, location)
			val_s = str(val)
			if name in prev_live_map:
				(prev_val, prev_live, dummy) = prev_live_map[name]
				if live and not prev_live:
					left = "*%s" % left
	
				if prev_val != val:
					val_s += pyc_color.red(" <= (%s)" % prev_val)

			line = "%s %s" % (left.ljust(25), val_s)
			if live:
				line = pyc_color.ansi_color(line, 36)

			print >>io, line