Add visual_range segment
Returns a value similar to `showcmd`. TODO: Make proper test case.
This commit is contained in:
parent
aa05f22652
commit
ab6140136d
|
@ -4,6 +4,7 @@
|
||||||
"background": { "fg": "white", "bg": "gray2" },
|
"background": { "fg": "white", "bg": "gray2" },
|
||||||
"background:divider": { "fg": "gray6", "bg": "gray2" },
|
"background:divider": { "fg": "gray6", "bg": "gray2" },
|
||||||
"mode": { "fg": "darkestgreen", "bg": "brightgreen", "attr": ["bold"] },
|
"mode": { "fg": "darkestgreen", "bg": "brightgreen", "attr": ["bold"] },
|
||||||
|
"visual_range": { "fg": "brightestorange", "bg": "darkorange", "attr": ["bold"] },
|
||||||
"modified_indicator": { "fg": "brightyellow", "bg": "gray4", "attr": ["bold"] },
|
"modified_indicator": { "fg": "brightyellow", "bg": "gray4", "attr": ["bold"] },
|
||||||
"paste_indicator": { "fg": "white", "bg": "mediumorange", "attr": ["bold"] },
|
"paste_indicator": { "fg": "white", "bg": "mediumorange", "attr": ["bold"] },
|
||||||
"readonly_indicator": { "fg": "brightestred", "bg": "gray4" },
|
"readonly_indicator": { "fg": "brightestred", "bg": "gray4" },
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
"background": { "fg": "oldlace", "bg": "royalblue5" },
|
"background": { "fg": "oldlace", "bg": "royalblue5" },
|
||||||
"background:divider": { "fg": "lightskyblue4", "bg": "royalblue5" },
|
"background:divider": { "fg": "lightskyblue4", "bg": "royalblue5" },
|
||||||
"mode": { "fg": "oldlace", "bg": "green", "attr": ["bold"] },
|
"mode": { "fg": "oldlace", "bg": "green", "attr": ["bold"] },
|
||||||
|
"visual_range": { "fg": "green", "bg": "oldlace", "attr": ["bold"] },
|
||||||
"modified_indicator": { "fg": "yellow", "bg": "darkgreencopper", "attr": ["bold"] },
|
"modified_indicator": { "fg": "yellow", "bg": "darkgreencopper", "attr": ["bold"] },
|
||||||
"paste_indicator": { "fg": "oldlace", "bg": "orange", "attr": ["bold"] },
|
"paste_indicator": { "fg": "oldlace", "bg": "orange", "attr": ["bold"] },
|
||||||
"readonly_indicator": { "fg": "red", "bg": "darkgreencopper" },
|
"readonly_indicator": { "fg": "red", "bg": "darkgreencopper" },
|
||||||
|
|
|
@ -20,6 +20,11 @@
|
||||||
"name": "mode",
|
"name": "mode",
|
||||||
"exclude_modes": ["nc"]
|
"exclude_modes": ["nc"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "visual_range",
|
||||||
|
"exclude_modes": ["nc"],
|
||||||
|
"priority": 10
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "paste_indicator",
|
"name": "paste_indicator",
|
||||||
"exclude_modes": ["nc"],
|
"exclude_modes": ["nc"],
|
||||||
|
|
|
@ -18,6 +18,7 @@ from collections import defaultdict
|
||||||
|
|
||||||
vim_funcs = {
|
vim_funcs = {
|
||||||
'virtcol': vim_get_func('virtcol', rettype=int),
|
'virtcol': vim_get_func('virtcol', rettype=int),
|
||||||
|
'getpos': vim_get_func('getpos'),
|
||||||
'fnamemodify': vim_get_func('fnamemodify', rettype=str),
|
'fnamemodify': vim_get_func('fnamemodify', rettype=str),
|
||||||
'expand': vim_get_func('expand', rettype=str),
|
'expand': vim_get_func('expand', rettype=str),
|
||||||
'bufnr': vim_get_func('bufnr', rettype=int),
|
'bufnr': vim_get_func('bufnr', rettype=int),
|
||||||
|
@ -87,6 +88,31 @@ def mode(pl, segment_info, override=None):
|
||||||
return vim_modes[mode]
|
return vim_modes[mode]
|
||||||
|
|
||||||
|
|
||||||
|
@requires_segment_info
|
||||||
|
def visual_range(pl, segment_info):
|
||||||
|
'''Return the current visual selection range.
|
||||||
|
|
||||||
|
Returns a value similar to `showcmd`.
|
||||||
|
'''
|
||||||
|
if segment_info['mode'] not in ('v', 'V', '^V'):
|
||||||
|
return None
|
||||||
|
pos_start = vim_funcs['getpos']('v')
|
||||||
|
pos_end = vim_funcs['getpos']('.')
|
||||||
|
# Workaround for vim's "excellent" handling of multibyte characters and display widths
|
||||||
|
pos_start[2] = vim_funcs['virtcol']([pos_start[1], pos_start[2], pos_start[3]])
|
||||||
|
pos_end[2] = vim_funcs['virtcol']([pos_end[1], pos_end[2], pos_end[3]])
|
||||||
|
visual_start = (int(pos_start[1]), int(pos_start[2]))
|
||||||
|
visual_end = (int(pos_end[1]), int(pos_end[2]))
|
||||||
|
diff_rows = abs(visual_end[0] - visual_start[0]) + 1
|
||||||
|
diff_cols = abs(visual_end[1] - visual_start[1]) + 1
|
||||||
|
if segment_info['mode'] == '^V':
|
||||||
|
return '{0} × {1}'.format(diff_rows, diff_cols)
|
||||||
|
elif segment_info['mode'] == 'V' or diff_rows > 1:
|
||||||
|
return '{0} rows'.format(diff_rows)
|
||||||
|
else:
|
||||||
|
return '{0} cols'.format(diff_cols)
|
||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def modified_indicator(pl, segment_info, text='+'):
|
def modified_indicator(pl, segment_info, text='+'):
|
||||||
'''Return a file modified indicator.
|
'''Return a file modified indicator.
|
||||||
|
|
|
@ -399,6 +399,10 @@ class TestVim(TestCase):
|
||||||
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info), 'V·BLCK')
|
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info), 'V·BLCK')
|
||||||
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')
|
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')
|
||||||
|
|
||||||
|
def test_visual_range(self):
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
def test_modified_indicator(self):
|
def test_modified_indicator(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
|
|
|
@ -228,11 +228,18 @@ def _emul_setwinvar(winnr, varname, value):
|
||||||
|
|
||||||
@_vim
|
@_vim
|
||||||
def _emul_virtcol(expr):
|
def _emul_virtcol(expr):
|
||||||
if expr == '.':
|
if expr == '.' or isinstance(expr, list):
|
||||||
return windows[_window - 1].cursor[1] + 1
|
return windows[_window - 1].cursor[1] + 1
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
@_vim
|
||||||
|
def _emul_getpos(expr):
|
||||||
|
if expr == '.' or expr == 'v':
|
||||||
|
return [0, windows[_window - 1].cursor[0] + 1, windows[_window - 1].cursor[1] + 1, 0]
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
@_vim
|
@_vim
|
||||||
@_str_func
|
@_str_func
|
||||||
def _emul_fnamemodify(path, modstring):
|
def _emul_fnamemodify(path, modstring):
|
||||||
|
|
Loading…
Reference in New Issue