diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-06-17 14:57:42 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-06-17 15:42:42 +0200 |
commit | bc88e673952ec1ce6485975183280d1deb21b809 (patch) | |
tree | d03a9fbfed311b314df851720a0f26a9d1307e07 /qutebrowser/keyinput/basekeyparser.py | |
parent | b25c7d5b36a239f8520670390692c96a2812d300 (diff) | |
download | qutebrowser-bc88e673952ec1ce6485975183280d1deb21b809.tar.gz qutebrowser-bc88e673952ec1ce6485975183280d1deb21b809.zip |
Add BindingTrie.__str__
Diffstat (limited to 'qutebrowser/keyinput/basekeyparser.py')
-rw-r--r-- | qutebrowser/keyinput/basekeyparser.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/qutebrowser/keyinput/basekeyparser.py b/qutebrowser/keyinput/basekeyparser.py index d77a4d3c6..d46499a16 100644 --- a/qutebrowser/keyinput/basekeyparser.py +++ b/qutebrowser/keyinput/basekeyparser.py @@ -96,6 +96,22 @@ class BindingTrie: return utils.get_repr(self, children=self.children, command=self.command) + def __str__(self): + return '\n'.join(self.string_lines(blank=True)) + + def string_lines(self, indent=0, blank=False): + lines = [] + if self.command is not None: + lines.append('{}=> {}'.format(' ' * indent, self.command)) + + for key, child in sorted(self.children.items()): + lines.append('{}{}:'.format(' ' * indent, key)) + lines.extend(child.string_lines(indent=indent+1)) + if blank: + lines.append('') + + return lines + def update(self, mapping: typing.Mapping) -> None: """Add data from the given mapping to the trie.""" for key in mapping: |