|
10 | 10 | 'detect_mime', 'bunzip', 'loads', 'loads_multi', 'dumps', 'untar_dir', 'repo_details', 'shell', 'ssh', |
11 | 11 | 'rsync_multi', 'run', 'open_file', 'save_pickle', 'load_pickle', 'parse_env', 'expand_wildcards', |
12 | 12 | 'atomic_save', 'dict2obj', 'obj2dict', 'repr_dict', 'is_listy', 'mapped', 'IterLen', 'ReindexCollection', |
13 | | - 'SaveReturn', 'trim_wraps', 'save_iter', 'asave_iter', 'unqid', 'rtoken_hex', 'friendly_name', |
14 | | - 'n_friendly_names', 'exec_eval', 'get_source_link', 'sparkline', 'modify_exception', 'round_multiple', |
15 | | - 'set_num_threads', 'join_path_file', 'autostart', 'EventTimer', 'stringfmt_names', 'PartialFormatter', |
16 | | - 'partial_format', 'truncstr', 'utc2local', 'local2utc', 'trace', 'modified_env', 'ContextManagers', |
17 | | - 'shufflish', 'console_help', 'hl_md', 'type2str', 'dataclass_src', 'Unset', 'nullable_dc', 'make_nullable', |
18 | | - 'flexiclass', 'asdict', 'vars_pub', 'is_typeddict', 'is_namedtuple', 'CachedIter', 'CachedAwaitable', |
19 | | - 'reawaitable', 'is_async_callable', 'maybe_await', 'noopa', 'flexicache', 'time_policy', 'mtime_policy', |
20 | | - 'timed_cache'] |
| 13 | + 'SaveReturn', 'trim_wraps', 'save_iter', 'asave_iter', 'clean_cli_output', 'unqid', 'rtoken_hex', |
| 14 | + 'friendly_name', 'n_friendly_names', 'exec_eval', 'get_source_link', 'sparkline', 'modify_exception', |
| 15 | + 'round_multiple', 'set_num_threads', 'join_path_file', 'autostart', 'EventTimer', 'stringfmt_names', |
| 16 | + 'PartialFormatter', 'partial_format', 'truncstr', 'utc2local', 'local2utc', 'trace', 'modified_env', |
| 17 | + 'ContextManagers', 'shufflish', 'console_help', 'hl_md', 'type2str', 'dataclass_src', 'Unset', 'nullable_dc', |
| 18 | + 'make_nullable', 'flexiclass', 'asdict', 'vars_pub', 'is_typeddict', 'is_namedtuple', 'CachedIter', |
| 19 | + 'CachedAwaitable', 'reawaitable', 'is_async_callable', 'maybe_await', 'noopa', 'flexicache', 'time_policy', |
| 20 | + 'mtime_policy', 'timed_cache'] |
21 | 21 |
|
22 | 22 | # %% ../nbs/03_xtras.ipynb #3401d507 |
23 | 23 | from .imports import * |
24 | 24 | from .foundation import * |
25 | 25 | from .basics import * |
| 26 | +from .ansi import strip_ansi |
| 27 | + |
26 | 28 | from importlib import import_module |
27 | 29 | from functools import wraps |
28 | 30 | import string,time,dataclasses |
@@ -594,6 +596,16 @@ def asave_iter(g): |
594 | 596 | def _(*args, **kwargs): return _save_iter(g, *args, **kwargs) |
595 | 597 | return _ |
596 | 598 |
|
| 599 | +# %% ../nbs/03_xtras.ipynb #45eb5141 |
| 600 | +def clean_cli_output(txt:str, strip:bool=True): |
| 601 | + "Clean CLI output by handling alternate screen, carriage returns, and ANSI escapes" |
| 602 | + if '\x1b[?1049h' in txt: |
| 603 | + if '\x1b[?1049l' not in txt: return '' |
| 604 | + txt = txt.rsplit('\x1b[?1049l', 1)[-1] |
| 605 | + txt = txt.replace('\r\n', '\n') |
| 606 | + res = '\n'.join(l.rsplit('\r', 1)[-1] for l in txt.split('\n')) |
| 607 | + return strip_ansi(res, term_queries=True) if strip else res |
| 608 | + |
597 | 609 | # %% ../nbs/03_xtras.ipynb #35368de5 |
598 | 610 | def unqid(seeded=False): |
599 | 611 | "Generate a unique id suitable for use as a Python identifier" |
|
0 commit comments