Nicely align setting names and values.

This commit is contained in:
Solderpunk 2023-11-17 19:56:47 +01:00
parent bd7c5c2110
commit 4f354ab291
1 changed files with 5 additions and 2 deletions

View File

@ -989,15 +989,18 @@ Slow internet connection? Use 'set timeout' to be more patient.""")
@restricted
def do_set(self, line):
"""View or set various options."""
# Compute some constants for pretty alignment
ljust = max((len(k) for k in self.options.keys()))
rjust = max((len(str(v)) for v in self.options.values()))
if not line.strip():
# Show all current settings
for option in sorted(self.options.keys()):
print("%s %s" % (option, self.options[option]))
print("%s %s" % (option.ljust(ljust+4), str(self.options[option]).rjust(rjust)))
elif len(line.split()) == 1:
# Show current value of one specific setting
option = line.strip()
if option in self.options:
print("%s %s" % (option, self.options[option]))
print("%s %s" % (option.ljust(ljust+4), str(self.options[option]).rjust(rjust)))
else:
print("Unrecognised option %s" % option)
else: