mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 07:44:36 +02:00
Improve visual_range segment
This commit is contained in:
parent
c95b288527
commit
97978eaf77
@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "visual_range",
|
"name": "visual_range",
|
||||||
"exclude_modes": ["nc"],
|
"include_modes": ["v", "V", "^V", "s", "S", "^S"],
|
||||||
"priority": 10
|
"priority": 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,10 @@ def window_cached(func):
|
|||||||
if segment_info['mode'] == 'nc':
|
if segment_info['mode'] == 'nc':
|
||||||
return cache.get(window_id)
|
return cache.get(window_id)
|
||||||
else:
|
else:
|
||||||
r = func(**kwargs)
|
if getattr(func, 'powerline_requires_segment_info', False):
|
||||||
|
r = func(segment_info=segment_info, **kwargs)
|
||||||
|
else:
|
||||||
|
r = func(**kwargs)
|
||||||
cache[window_id] = r
|
cache[window_id] = r
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@ -99,29 +102,57 @@ def mode(pl, segment_info, override=None):
|
|||||||
return vim_modes[mode]
|
return vim_modes[mode]
|
||||||
|
|
||||||
|
|
||||||
|
@window_cached
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def visual_range(pl, segment_info):
|
def visual_range(pl, segment_info, CTRL_V_text='{rows} × {vcols}', v_text_oneline='{vcols} cols', v_text_multiline='{rows} rows', V_text='{rows} rows'):
|
||||||
'''Return the current visual selection range.
|
'''Return the current visual selection range.
|
||||||
|
|
||||||
Returns a value similar to `showcmd`.
|
:param str CTRL_V_text:
|
||||||
|
Text to display when in block visual or select mode.
|
||||||
|
:param str v_text_oneline:
|
||||||
|
Text to display when in charaterwise visual or select mode, assuming
|
||||||
|
selection occupies only one line.
|
||||||
|
:param str v_text_multiline:
|
||||||
|
Text to display when in charaterwise visual or select mode, assuming
|
||||||
|
selection occupies more then one line.
|
||||||
|
:param str V_text:
|
||||||
|
Text to display when in linewise visual or select mode.
|
||||||
|
|
||||||
|
All texts are format strings which are passed the following parameters:
|
||||||
|
|
||||||
|
========= =============================================================
|
||||||
|
Parameter Description
|
||||||
|
========= =============================================================
|
||||||
|
sline Line number of the first line of the selection
|
||||||
|
eline Line number of the last line of the selection
|
||||||
|
scol Column number of the first character of the selection
|
||||||
|
ecol Column number of the last character of the selection
|
||||||
|
svcol Virtual column number of the first character of the selection
|
||||||
|
secol Virtual column number of the last character of the selection
|
||||||
|
rows Number of lines in the selection
|
||||||
|
cols Number of columns in the selection
|
||||||
|
vcols Number of virtual columns in the selection
|
||||||
|
========= =============================================================
|
||||||
'''
|
'''
|
||||||
if segment_info['mode'] not in ('v', 'V', '^V'):
|
sline, scol, soff = vim_funcs['getpos']("v")[1:]
|
||||||
return None
|
eline, ecol, eoff = vim_funcs['getpos'](".")[1:]
|
||||||
pos_start = vim_funcs['getpos']('v')
|
svcol = vim_funcs['virtcol']([sline, scol, soff])
|
||||||
pos_end = vim_funcs['getpos']('.')
|
evcol = vim_funcs['virtcol']([eline, ecol, eoff])
|
||||||
# Workaround for vim's "excellent" handling of multibyte characters and display widths
|
rows = abs(eline - sline) + 1
|
||||||
pos_start[2] = vim_funcs['virtcol']([pos_start[1], pos_start[2], pos_start[3]])
|
cols = abs(ecol - scol) + 1
|
||||||
pos_end[2] = vim_funcs['virtcol']([pos_end[1], pos_end[2], pos_end[3]])
|
vcols = abs(evcol - svcol) + 1
|
||||||
visual_start = (int(pos_start[1]), int(pos_start[2]))
|
return {
|
||||||
visual_end = (int(pos_end[1]), int(pos_end[2]))
|
'^': CTRL_V_text,
|
||||||
diff_rows = abs(visual_end[0] - visual_start[0]) + 1
|
's': v_text_oneline if rows == 1 else v_text_multiline,
|
||||||
diff_cols = abs(visual_end[1] - visual_start[1]) + 1
|
'S': V_text,
|
||||||
if segment_info['mode'] == '^V':
|
'v': v_text_oneline if rows == 1 else v_text_multiline,
|
||||||
return '{0} × {1}'.format(diff_rows, diff_cols)
|
'V': V_text,
|
||||||
elif segment_info['mode'] == 'V' or diff_rows > 1:
|
}.get(segment_info['mode'][0], '').format(
|
||||||
return '{0} rows'.format(diff_rows)
|
sline=sline, eline=eline,
|
||||||
else:
|
scol=scol, ecol=ecol,
|
||||||
return '{0} cols'.format(diff_cols)
|
svcol=svcol, evcol=evcol,
|
||||||
|
rows=rows, cols=cols, vcols=vcols,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user