mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 07:44:36 +02:00
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
|
.. automodule:: powerline.listers.vim
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
Pdb listers
|
||||||
|
-----------
|
||||||
|
|
||||||
|
.. automodule:: powerline.listers.pdb
|
||||||
|
:members:
|
||||||
|
7
docs/source/configuration/segments/pdb.rst
Normal file
7
docs/source/configuration/segments/pdb.rst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
************
|
||||||
|
PDB segments
|
||||||
|
************
|
||||||
|
|
||||||
|
.. automodule:: powerline.segments.pdb
|
||||||
|
:members:
|
||||||
|
|
@ -475,6 +475,15 @@ Pdb
|
|||||||
``pdb``
|
``pdb``
|
||||||
Currently active :py:class:`pdb.Pdb` instance.
|
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
|
Segment class
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
5
powerline/config_files/colorschemes/pdb/__main__.json
Normal file
5
powerline/config_files/colorschemes/pdb/__main__.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"groups": {
|
||||||
|
"current_context": "current_code_name"
|
||||||
|
}
|
||||||
|
}
|
8
powerline/config_files/colorschemes/pdb/default.json
Normal file
8
powerline/config_files/colorschemes/pdb/default.json
Normal file
@ -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": {
|
"segments": {
|
||||||
"left": [
|
"left": [
|
||||||
{
|
{
|
||||||
"function": "powerline.segments.common.env.virtualenv",
|
"function": "stack_depth"
|
||||||
"priority": 10
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "segment_list",
|
||||||
"contents": "In [",
|
"function": "powerline.listers.pdb.frame_lister",
|
||||||
"draw_soft_divider": false,
|
"segments": [
|
||||||
"highlight_groups": ["virtualenv"]
|
{
|
||||||
|
"function": "current_file",
|
||||||
|
"after": ":"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "string",
|
"function": "current_line",
|
||||||
"contents": "]",
|
"after": " "
|
||||||
"highlight_groups": ["virtualenv"]
|
},
|
||||||
|
{
|
||||||
|
"function": "current_code_name"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
37
powerline/listers/pdb.py
Normal file
37
powerline/listers/pdb.py
Normal file
@ -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-specific powerline renderer
|
||||||
'''
|
'''
|
||||||
pdb = None
|
pdb = None
|
||||||
|
initial_stack_length = None
|
||||||
|
|
||||||
def get_segment_info(self, segment_info, mode):
|
def get_segment_info(self, segment_info, mode):
|
||||||
r = self.segment_info.copy()
|
r = self.segment_info.copy()
|
||||||
r['pdb'] = self.pdb
|
r['pdb'] = self.pdb
|
||||||
|
r['initial_stack_length'] = self.initial_stack_length
|
||||||
|
r['curframe'] = self.pdb.curframe
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def set_pdb(self, pdb):
|
def set_pdb(self, pdb):
|
||||||
@ -28,6 +31,8 @@ class PDBRenderer(ReadlineRenderer):
|
|||||||
self.pdb = pdb
|
self.pdb = pdb
|
||||||
|
|
||||||
def render(self, **kwargs):
|
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)
|
return Renderer.render(self, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
61
powerline/segments/pdb.py
Normal file
61
powerline/segments/pdb.py
Normal file
@ -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…
x
Reference in New Issue
Block a user