aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-06-29 21:33:26 +0100
committerGravatar jesopo2019-06-29 21:33:26 +0100
commitb4c762eb4ea1a83556dac95d6b248e6bcf220843 (patch)
tree28cd655dcfdc45a48b72399f7a5c2241600def57 /src
parentOnly accept highlight-commands when they have "," or ":" (diff)
signature
Automatically format `example` text for OptionsSetting (showing options)
Diffstat (limited to 'src')
-rw-r--r--src/utils/__init__.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index cc3ca689..887e8ab2 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -230,13 +230,23 @@ def is_main_thread() -> bool:
return threading.current_thread() is threading.main_thread()
class Setting(object):
+ example: str = None
def __init__(self, name: str, help: str=None, example: str=None):
self.name = name
self.help = help
- self.example = example
+ if not example == None:
+ self.example = example
def parse(self, value: str) -> typing.Any:
return value
+ def get_example(self):
+ if not self.example == None:
+ return "Example: %s" % self.example
+ else:
+ return self._format_example()
+ def _format_example(self):
+ return None
+
SETTING_TRUE = ["true", "yes", "on", "y"]
SETTING_FALSE = ["false", "no", "off", "n"]
class BoolSetting(Setting):
@@ -269,3 +279,7 @@ class OptionsSetting(Setting):
if option.lower() == value_lower:
return option
return None
+
+ def _format_example(self):
+ options = ["'%s'" % option for option in self._options]
+ return "Options: %s" % ", ".join(options)