make list-completers include a brief description

This commit is contained in:
adam j hartz 2016-06-02 11:28:50 -04:00
parent 0bf6aee51f
commit 468eae8340
2 changed files with 23 additions and 1 deletions

View file

@ -2,6 +2,8 @@ import builtins
from collections import OrderedDict
from xonsh.completers.tools import justify
def _add_one_completer(name, func, loc='end'):
new = OrderedDict()
@ -32,7 +34,13 @@ def _add_one_completer(name, func, loc='end'):
def list_completers(args, stdin=None):
o = "Registered Completer Functions: \n"
_comp = builtins.__xonsh_completers__
_strs = (' %s' % c for c in _comp)
ml = max(len(i) for i in _comp)
_strs = []
for c in _comp:
doc = _comp[c].__doc__ or 'No description provided'
doc = justify(doc, 80, 7 + ml)
padding = ' ' * (2 + ml - len(c))
_strs.append('%s%r : %s' % (padding, c, doc))
return o + '\n'.join(_strs) + '\n'

View file

@ -16,3 +16,17 @@ def is_iterable(x):
return True
except:
return False
def justify(s, max_length, left_pad=0):
toks = s.strip().split()
lines = [[]]
for tok in toks:
new_length = (sum(len(i) for i in lines[-1]) +
len(lines[-1]) - 1 +
len(tok) +
left_pad)
if new_length > max_length:
lines.append([])
lines[-1].append(tok)
return "\n".join((((" " * left_pad) if ix != 0 else '') + " ".join(i))
for ix, i in enumerate(lines))