Add pdb-specific segments and make default theme use them
This commit is contained in:
parent
b0d295301b
commit
cac9754fcf
|
@ -23,3 +23,9 @@ Vim listers
|
|||
|
||||
.. automodule:: powerline.listers.vim
|
||||
:members:
|
||||
|
||||
Pdb listers
|
||||
-----------
|
||||
|
||||
.. automodule:: powerline.listers.pdb
|
||||
:members:
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
************
|
||||
PDB segments
|
||||
************
|
||||
|
||||
.. automodule:: powerline.segments.pdb
|
||||
:members:
|
||||
|
|
@ -475,6 +475,15 @@ Pdb
|
|||
``pdb``
|
||||
Currently active :py:class:`pdb.Pdb` instance.
|
||||
|
||||
``curframe``
|
||||
Frame which will be run next. Note: due to the existence of
|
||||
:py:func:`powerline.listers.pdb.frame_lister` one must not use
|
||||
``segment_info['pdb'].curframe``.
|
||||
|
||||
``initial_stack_length``
|
||||
Equal to the length of :py:attr:`pdb.Pdb.stack` at the first invocation of
|
||||
the prompt decremented by one.
|
||||
|
||||
Segment class
|
||||
=============
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"groups": {
|
||||
"current_context": "current_code_name"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"groups": {
|
||||
"current_line": { "fg": "gray10", "bg": "gray4", "attrs": ["bold"] },
|
||||
"current_file": { "fg": "gray10", "bg": "gray4", "attrs": ["bold"] },
|
||||
"current_code_name": { "fg": "gray9", "bg": "gray4", "attrs": ["bold"] },
|
||||
"stack_depth": { "fg": "gray1", "bg": "gray10", "attrs": ["bold"] }
|
||||
}
|
||||
}
|
|
@ -1,20 +1,26 @@
|
|||
{
|
||||
"default_module": "powerline.segments.pdb",
|
||||
"segments": {
|
||||
"left": [
|
||||
{
|
||||
"function": "powerline.segments.common.env.virtualenv",
|
||||
"priority": 10
|
||||
"function": "stack_depth"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"contents": "In [",
|
||||
"draw_soft_divider": false,
|
||||
"highlight_groups": ["virtualenv"]
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"contents": "]",
|
||||
"highlight_groups": ["virtualenv"]
|
||||
"type": "segment_list",
|
||||
"function": "powerline.listers.pdb.frame_lister",
|
||||
"segments": [
|
||||
{
|
||||
"function": "current_file",
|
||||
"after": ":"
|
||||
},
|
||||
{
|
||||
"function": "current_line",
|
||||
"after": " "
|
||||
},
|
||||
{
|
||||
"function": "current_code_name"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# vim:fileencoding=utf-8:noet
|
||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||
|
||||
from powerline.theme import requires_segment_info
|
||||
|
||||
|
||||
@requires_segment_info
|
||||
def frame_lister(pl, segment_info, full_stack=False, maxframes=3):
|
||||
'''List all frames in segment_info format
|
||||
|
||||
:param bool full_stack:
|
||||
If true, then all frames in the stack are listed. Normally N first
|
||||
frames are discarded where N is a number of frames present at the first
|
||||
invocation of the prompt minus one.
|
||||
:param int maxframes:
|
||||
Maximum number of frames to display.
|
||||
'''
|
||||
if full_stack:
|
||||
initial_stack_length = 0
|
||||
frames = segment_info['pdb'].stack
|
||||
else:
|
||||
initial_stack_length = segment_info['initial_stack_length']
|
||||
frames = segment_info['pdb'].stack[initial_stack_length:]
|
||||
|
||||
if len(frames) > maxframes:
|
||||
frames = frames[-maxframes:]
|
||||
|
||||
return (
|
||||
(
|
||||
{
|
||||
'curframe': frame[0],
|
||||
'initial_stack_length': initial_stack_length,
|
||||
},
|
||||
{}
|
||||
)
|
||||
for frame in frames
|
||||
)
|
|
@ -9,10 +9,13 @@ class PDBRenderer(ReadlineRenderer):
|
|||
'''PDB-specific powerline renderer
|
||||
'''
|
||||
pdb = None
|
||||
initial_stack_length = None
|
||||
|
||||
def get_segment_info(self, segment_info, mode):
|
||||
r = self.segment_info.copy()
|
||||
r['pdb'] = self.pdb
|
||||
r['initial_stack_length'] = self.initial_stack_length
|
||||
r['curframe'] = self.pdb.curframe
|
||||
return r
|
||||
|
||||
def set_pdb(self, pdb):
|
||||
|
@ -28,6 +31,8 @@ class PDBRenderer(ReadlineRenderer):
|
|||
self.pdb = pdb
|
||||
|
||||
def render(self, **kwargs):
|
||||
if self.initial_stack_length is None:
|
||||
self.initial_stack_length = len(self.pdb.stack) - 1
|
||||
return Renderer.render(self, **kwargs)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,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']))
|
Loading…
Reference in New Issue