Source code for examples.print_styles

"""This example shows different ways of printing the contents of a `Folder` instance
to the terminal.
"""

import msgspec

from magpie.data.testdata import simple_folder
from magpie.util import pprint, rprint


[docs] def boxed_message(m: str) -> str: n = len(m) + 2 lines = [ '', f'╭{"─" * n}╮', f'│ {m} │', f'╰{"─" * n}╯', ] result = '\n'.join(lines) print(result)
[docs] def main(): """ Prints twigs and folders using the available print styles """ data = simple_folder() twig = data[0][1][0] boxed_message('Printing twig using `pprint` function') pprint(twig) boxed_message('Printing folder using `pprint` function') pprint(data) boxed_message('Printing folder using `rprint` function') rprint(data) boxed_message('Printing folder as JSON object') pprint(msgspec.json.encode(data)) boxed_message('Printing folder as dictionary') pprint(data.to_dict())
if __name__ == '__main__': main()