vimtk._dirty module¶
This is a module for quick and dirty ports from other codebases that I’d like to include, but need to be cleaned up and integrated into vimtk properly.
This is a staging ground where I can use them, but also keep them separate.
Port Logic¶
# Liberator makes porting dirty code pretty easy
import liberator import utool as ut
lib = liberator.Liberator() lib.add_dynamic(ut.format_multiple_paragraph_sentences) lib.expand([‘utool’]) source = lib.current_sourcecode() print(source)
lib = liberator.Liberator() lib.add_dynamic(ut.remove_doublspaces) lib.add_dynamic(ut.flatten_textlines) lib.add_dynamic(ut.get_minimum_indentation) lib.add_dynamic(ut.regex_or) lib.add_dynamic(ut.interleave) lib.expand([‘utool’]) source = lib.current_sourcecode() print(source)
- vimtk._dirty.get_minimum_indentation(text)[source]¶
returns the number of preceding spaces
- Parameters:
text (str) – unicode text
- Returns:
indentation
- Return type:
Example
>>> # ENABLE_DOCTEST >>> text = ' foo\n bar' >>> result = get_minimum_indentation(text) >>> print(result) 3
- vimtk._dirty.interleave(args)[source]¶
zip followed by flatten
- Parameters:
args (tuple) – tuple of lists to interleave
Example
>>> args = ([1, 2, 3, 4, 5], ['A', 'B', 'C', 'D', 'E', 'F', 'G']) >>> genresult = interleave(args) >>> result = ub.repr2(list(genresult), nl=False) >>> print(result) [1, 'A', 2, 'B', 3, 'C', 4, 'D', 5, 'E']
- vimtk._dirty.format_single_paragraph_sentences(text, debug=False, myprefix=True, sentence_break=True, max_width=73, sepcolon=True)[source]¶
helps me separatate sentences grouped in paragraphs that I have a difficult time reading due to dyslexia
- Parameters:
text (str)
- Returns:
wrapped_text
- Return type:
Example
>>> # DISABLE_DOCTEST >>> text = ' lorium ipsum doloar dolar dolar dolar erata man foobar is this there yet almost man not quit ate 80 chars yet hold out almost there? dolar erat. sau.ltum. fds.fd... . . fd oob fd. list: (1) abcd, (2) foobar (4) 123456789 123456789 123456789 123456789 123 123 123 123 123456789 123 123 123 123 123456789 123456789 123456789 123456789 123456789 123 123 123 123 123 123456789 123456789 123456789 123456789 123456789 123456789 (3) spam.' >>> #text = 'list: (1) abcd, (2) foobar (3) spam.' >>> #text = 'foo. when: (1) there is a new individual,' >>> #text = 'when: (1) there is a new individual,' >>> #text = '? ? . lorium. ipsum? dolar erat. saultum. fds.fd... fd oob fd. ? ' # causes breakdown >>> print('text = %r' % (text,)) >>> sentence_break = not ub.argflag('--nobreak') >>> wrapped_text = format_single_paragraph_sentences(text, debug=True, sentence_break=sentence_break) >>> result = ('wrapped_text =\n%s' % (str(wrapped_text),)) >>> print(result)
- vimtk._dirty.format_multiple_paragraph_sentences(text, debug=False, **kwargs)[source]¶
FIXME: funky things happen when multiple newlines in the middle of paragraphs
Example
>>> text = ub.codeblock( ''' Test paragraph. Far out in the uncharted backwaters of the unfashionable end of the western spiral arm of the Galaxy lies a small unregarded yellow sun. Orbiting this at a distance of roughly ninety-two million miles is an utterly insignificant little blue green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea. % --- one. two three. four. ''') >>> #text = testdata_text(2) >>> formated_text = format_multiple_paragraph_sentences(text, debug=True) >>> print('+--- Text ---') >>> print(text) >>> print('+--- Formated Text ---') >>> print(formated_text) >>> print('L_____')