From a739ce985cf14c174a007b8b59db9b89067985f1 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 9 Dec 2024 14:44:05 -0800 Subject: [PATCH] Add indentation to nested entries --- k2t.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/k2t.py b/k2t.py index ce70a5b..5263857 100644 --- a/k2t.py +++ b/k2t.py @@ -11,6 +11,8 @@ from xml.etree import ElementTree DEFAULT_LINESTYLE = 'I0' DEFAULT_DITHER = 'I1' +INDENT = ' ' + def k2t( kfile: str, @@ -187,9 +189,10 @@ class Entry: return el def to_toml(self, depth: int = 0) -> str: + indent = INDENT * depth parts = ('layers',) + ('members',) * depth - s = '[[' + '.'.join(parts) + ']]\n' + s = indent + '[[' + '.'.join(parts) + ']]\n' for field in fields(self): val = getattr(self, field.name) if val == field.default: @@ -205,7 +208,7 @@ class Entry: vstr = str(val) key = field.name.replace('_', '-') - s += f'{key} = {vstr}\n' + s += f'{indent}{key} = {vstr}\n' s += '\n'