caesar0301 / treelib

An efficient implementation of tree data structure in python 2/3.
http://treelib.readthedocs.io/en/latest/
Other
816 stars 188 forks source link

[proposal] add vt100 #115

Open jorndoe opened 5 years ago

jorndoe commented 5 years ago

I "patched" the following snippet elsewhere, in order to render vt100 in a shell (plus using ` instead of + for bottom nodes, akin to Linux pstree). Other changes were just to make the linter happy (well, happier). Would it be worthwhile incorporating into the master branch?

    def __get(self, nid, level, filter_, key, reverse, line_type):
        # default filter
        if filter_ is None:
            def filter_(_):
                return True
        # render characters
        dt_ = {
            'ascii': ('|', '|-- ', '`-- '),
            'ascii-ex': (
                '\u2502', '\u251c\u2500\u2500 ', '\u2514\u2500\u2500 '
            ),
            'ascii-exr': (
                '\u2502', '\u251c\u2500\u2500 ', '\u2570\u2500\u2500 '
            ),
            'ascii-em': (
                '\u2551', '\u2560\u2550\u2550 ', '\u255a\u2550\u2550 '
            ),
            'ascii-emv': (
                '\u2551', '\u255f\u2500\u2500 ', '\u2559\u2500\u2500 '
            ),
            'ascii-emh': (
                '\u2502', '\u255e\u2550\u2550 ', '\u2558\u2550\u2550 '
            ),
            'vt100': (
                '\033(0x' + '\033(B',
                '\033(0t' + '\033(0q' + '\033(0q' + '\033(B ',
                '\033(0m' + '\033(0q' + '\033(0q' + '\033(B '
            )
        }[line_type]
        return self.__get_iter(nid, level, filter_, key, reverse, dt_, [])
leonardbinet commented 4 years ago

@jorndoe feel free to submit a PR :)