summaryrefslogtreecommitdiffstats
path: root/powerline/segments/pdb.py
blob: bd6a38b7bcbec924aa250a7ab844654c4ef8f44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)

import os

from powerline.theme import requires_segment_info


@requires_segment_info
def current_line(pl, segment_info):
	'''Displays line number that is next to be run
	'''
	return str(segment_info['curframe'].f_lineno)


@requires_segment_info
def current_file(pl, segment_info, basename=True):
	'''Displays current file name

	:param bool basename:
		If true only basename is displayed.
	'''
	filename = segment_info['curframe'].f_code.co_filename
	if basename:
		filename = os.path.basename(filename)
	return filename


@requires_segment_info
def current_code_name(pl, segment_info):
	'''Displays name of the code object of the current frame
	'''
	return segment_info['curframe'].f_code.co_name


@requires_segment_info
def current_context(pl, segment_info):
	'''Displays currently executed context name

	This is similar to :py:func:`current_code_name`, but gives more details.

	Currently it only gives module file name if code_name happens to be 
	``<module>``.
	'''
	name = segment_info['curframe'].f_code.co_name
	if name == '<module>':
		name = os.path.basename(segment_info['curframe'].f_code.co_filename)
	return name


@requires_segment_info
def stack_depth(pl, segment_info, full_stack=False):
	'''Displays current stack depth

	Result is relative to the stack depth at the time prompt was first run.

	:param bool full_stack:
		If true then absolute depth is used.
	'''
	return str(len(segment_info['pdb'].stack) - (
		0 if full_stack else segment_info['initial_stack_length']))