diff --git a/README.md b/README.md index 1e88a97..bf3b879 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,13 @@ $ terminator-split --help usage: terminator-split [-h] [-d] [-e COMMAND] [-g CONFIG] [-t TERMINATOR] + [-f TEXT_SIZE] [TERMINATOR_OPTIONS] hostname [hostname ...] terminator-split [-h] [-d] [-g CONFIG] [-t TERMINATOR] [-s SHELL] + [-f TEXT_SIZE] [TERMINATOR_OPTIONS] number @@ -25,6 +27,14 @@ optional arguments: -g CONFIG, --config CONFIG Use this terminator config file -s SHELL, --shell SHELL Specify the shell to be loaded -t TERMINATOR, --terminator TERMINATOR + -f TEXT_SIZE, --text-size TEXT_SIZE + terminal font size in points +``` + +Example with a larger font: + +```shell +terminator-split -f 14 -m server1 server2 server3 server4 ``` ```shell diff --git a/terminator-split b/terminator-split index bd4c681..2f23282 100755 --- a/terminator-split +++ b/terminator-split @@ -9,6 +9,7 @@ https://github.com/AlekseyChudov/terminator-split import argparse import logging import os +import re import resource import tempfile @@ -16,7 +17,7 @@ import configobj __author__ = 'Aleksey Chudov ' __date__ = '23 Nov 2018' -__version__ = '1.0.4' +__version__ = '1.0.5' class TerminatorSplit(object): @@ -25,7 +26,8 @@ class TerminatorSplit(object): 'config': os.path.expanduser('~/.config/terminator/config'), 'command': "ssh '{}'", 'shell': 'bash -l', - 'terminator': '/usr/bin/terminator' + 'terminator': '/usr/bin/terminator', + 'text_size': None, } def __init__(self): @@ -40,11 +42,13 @@ class TerminatorSplit(object): usage = """ terminator-split [-h] [-d] [-e COMMAND] [-g CONFIG] [-t TERMINATOR] + [-f TEXT_SIZE] [TERMINATOR_OPTIONS] hostname [hostname ...] terminator-split [-h] [-d] [-g CONFIG] [-t TERMINATOR] [-s SHELL] + [-f TEXT_SIZE] [TERMINATOR_OPTIONS] number """ @@ -55,6 +59,7 @@ class TerminatorSplit(object): parser.add_argument('-g', '--config', help='Use this terminator config file') parser.add_argument('-s', '--shell', help='Specify the shell to be loaded') parser.add_argument('-t', '--terminator') + parser.add_argument('-f', '--font-size', dest='text_size', help='terminal font size') parser.add_argument('hostname', nargs='+') namespace = argparse.Namespace(**self.DEFAULT) args, unknown_args = parser.parse_known_args(namespace=namespace) @@ -71,8 +76,43 @@ class TerminatorSplit(object): logging.debug('args:{}'.format(self._args)) logging.debug('unknown_args:{}'.format(self._unknown_args)) + @staticmethod + def _config_bool(value, default=False): + if isinstance(value, bool): + return value + if value is None: + return default + return str(value).lower() in ('true', 'yes', '1', 'on') + + @staticmethod + def _replace_font_size(font, size): + font = font.strip() + match = re.match(r'^(.*?)\s+(\d+(?:\.\d+)?)\s*$', font) + if match: + return '{} {}'.format(match.group(1), size) + return '{} {}'.format(font, size) + + def _apply_text_size(self, config): + size = self._args.text_size + profiles = config.get('profiles') + if not profiles: + profiles = config['profiles'] = {} + + for profile in profiles.values(): + if not hasattr(profile, 'get'): + continue + if self._config_bool(profile.get('use_system_font'), default=True): + font = 'Monospace {}'.format(size) + else: + font = profile.get('font', 'Monospace 10') + font = self._replace_font_size(font, size) + profile['font'] = font + profile['use_system_font'] = False + def _write_config(self): config = configobj.ConfigObj(self._args.config) + if self._args.text_size is not None: + self._apply_text_size(config) self._update_layout(config) with tempfile.NamedTemporaryFile(delete=False) as tmp: config.filename = tmp.name