diff --git a/py3status/constants.py b/py3status/constants.py index fd426e8350..749db6519d 100644 --- a/py3status/constants.py +++ b/py3status/constants.py @@ -7,6 +7,7 @@ 'color_separator': '#333333', 'colors': False, 'interval': 5, + 'max_size': False, 'output_format': 'i3bar' } diff --git a/py3status/core.py b/py3status/core.py index 69a498f9c2..d1d7553a05 100644 --- a/py3status/core.py +++ b/py3status/core.py @@ -889,6 +889,7 @@ def create_output_modules(self): output_modules[name]['module'] = self.modules[name] output_modules[name]['type'] = 'py3status' output_modules[name]['color'] = self.mappings_color.get(name) + output_modules[name]['max_size'] = self.mappings_max_size.get(name) # i3status modules for name in i3modules: if name not in output_modules: @@ -897,6 +898,7 @@ def create_output_modules(self): output_modules[name]['module'] = i3modules[name] output_modules[name]['type'] = 'i3status' output_modules[name]['color'] = self.mappings_color.get(name) + output_modules[name]['max_size'] = self.mappings_max_size.get(name) self.output_modules = output_modules @@ -913,21 +915,44 @@ def create_mappings(self, config): if hasattr(color, 'none_setting'): color = None mappings[name] = color + + max_size = self.get_config_attribute(name, 'max_size') + if hasattr(max_size, 'none_setting'): + max_size = None + mappings[name] = max_size + # Store mappings for later use. + self.mappings_max_size = mappings self.mappings_color = mappings def process_module_output(self, module): """ Process the output for a module and return a json string representing it. Color processing occurs here. + Shortened text 'short_text' processing occurs here. """ outputs = module['module'].get_latest() color = module['color'] - if color: - for output in outputs: + max_size = module['max_size'] + + for output in outputs: + if color: # Color: substitute the config defined color if 'color' not in output: output['color'] = color + + if 'short_text' not in output: + full_text = output['full_text'] + if int(max_size) >= 1: + short = full_text[:max_size] if len(full_text) > int(max_size) else full_text + short = short + '..' if len(short + '..') < len(full_text) else short + output['short_text'] = short + elif max_size is True: + size = int((len(full_text) + 1) / 2) + short = full_text[:size] + short = short + '..' if len(short + '..') < len(full_text) else short + output['short_text'] = short + # Create the json string output. return ','.join([dumps(x) for x in outputs]) diff --git a/py3status/module.py b/py3status/module.py index 290d8b2c9b..d7476d8184 100644 --- a/py3status/module.py +++ b/py3status/module.py @@ -658,6 +658,15 @@ def deprecation_log(item): param = True self.allow_urgent = param + # max_size + # get the value form the config or use the module default if + # supplied. + fn = self._py3_wrapper.get_config_attribute + param = fn(self.module_full_name, 'max_size') + if hasattr(param, 'none_setting'): + param = True + self.max_size = param + # get the available methods for execution for method in sorted(dir(class_inst)): if method.startswith('_'):