From b595bec775ecb3299bd3f603aca45e712ae71472 Mon Sep 17 00:00:00 2001 From: David Levanon Date: Sat, 19 Sep 2020 22:27:21 +0300 Subject: [PATCH 1/9] layout file - initial commit - work in progress --- layout-files-examples/2-3-grid.json | 30 +++++ layout-files-examples/2-columns.json | 11 ++ layout-files-examples/3-rows.json | 13 ++ layout-files-examples/3-tabs-2-rows.json | 26 ++++ layout-files-examples/3-tabs-3-columns.json | 36 ++++++ layout-files-examples/4-4-grid.json | 30 +++++ terminatorlib/layoutfile.py | 124 ++++++++++++++++++++ terminatorlib/terminator.py | 12 +- 8 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 layout-files-examples/2-3-grid.json create mode 100644 layout-files-examples/2-columns.json create mode 100644 layout-files-examples/3-rows.json create mode 100644 layout-files-examples/3-tabs-2-rows.json create mode 100644 layout-files-examples/3-tabs-3-columns.json create mode 100644 layout-files-examples/4-4-grid.json create mode 100644 terminatorlib/layoutfile.py diff --git a/layout-files-examples/2-3-grid.json b/layout-files-examples/2-3-grid.json new file mode 100644 index 00000000..5266aa36 --- /dev/null +++ b/layout-files-examples/2-3-grid.json @@ -0,0 +1,30 @@ +{ + "tab1": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } + ] +} diff --git a/layout-files-examples/2-columns.json b/layout-files-examples/2-columns.json new file mode 100644 index 00000000..8030d45a --- /dev/null +++ b/layout-files-examples/2-columns.json @@ -0,0 +1,11 @@ +{ + "vertical": false, + "tab1": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] +} diff --git a/layout-files-examples/3-rows.json b/layout-files-examples/3-rows.json new file mode 100644 index 00000000..560857ab --- /dev/null +++ b/layout-files-examples/3-rows.json @@ -0,0 +1,13 @@ +{ + "tab1": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] +} diff --git a/layout-files-examples/3-tabs-2-rows.json b/layout-files-examples/3-tabs-2-rows.json new file mode 100644 index 00000000..0dc7f9bd --- /dev/null +++ b/layout-files-examples/3-tabs-2-rows.json @@ -0,0 +1,26 @@ +{ + "tab1": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "tab2": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "tab3": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] +} diff --git a/layout-files-examples/3-tabs-3-columns.json b/layout-files-examples/3-tabs-3-columns.json new file mode 100644 index 00000000..ae9e103c --- /dev/null +++ b/layout-files-examples/3-tabs-3-columns.json @@ -0,0 +1,36 @@ +{ + "vertical": false, + "tab1": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "tab2": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "tab3": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] +} diff --git a/layout-files-examples/4-4-grid.json b/layout-files-examples/4-4-grid.json new file mode 100644 index 00000000..5266aa36 --- /dev/null +++ b/layout-files-examples/4-4-grid.json @@ -0,0 +1,30 @@ +{ + "tab1": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } + ] +} diff --git a/terminatorlib/layoutfile.py b/terminatorlib/layoutfile.py new file mode 100644 index 00000000..ff25933b --- /dev/null +++ b/terminatorlib/layoutfile.py @@ -0,0 +1,124 @@ +from .util import dbg, err +from os import path +import sys +import json +import traceback + +class LayoutFile(object): + def build_single_tab_layout(self, layoutjson, vertical): + dbg ('Budiling a single tab layout from json: %s ' % layoutjson) + + result = { + 'root': { + 'type': 'Window' + } + } + + if len(layoutjson) == 1: + self.build_terminal_layout(layoutjson, result, 'root', 0) + else: + self.build_container_layout(layoutjson, result, 'root', 0, vertical) + + return result + + def build_multi_tab_layout(self, layoutjson, vertical): + dbg ('Budiling multi tabs layout from json: %s ' % layoutjson) + + tabs = { + 'type': 'Notebook', + 'parent': 'root', + 'labels': [] + } + + result = { + 'root': { + 'type': 'Window' + }, + 'tabs': tabs + } + + counter = 0 + + for tab in layoutjson: + tabs['labels'].append(tab) + if len(layoutjson[tab]) == 1: + self.build_terminal_layout(layoutjson[tab][0], result, 'tabs', counter) + else: + self.build_container_layout(layoutjson[tab], result, 'tabs', counter, vertical) + counter += 1 + + return result + + def build_terminal_layout(self, layoutjson, children, parent, order): + dbg ('Building a terminal from json: %s' % layoutjson) + + children[parent + "." + str(order)] = { + 'type': 'Terminal', + 'order': order, + 'parent': parent, + 'command': layoutjson['command'] + } + + def build_container_layout(self, layoutjson, children, parent, order, vertical): + dbg ('Building %s layout from json: %s' % ("vertical" if vertical else "horizental", layoutjson)) + + counter = 0 + actualparent = parent + + for pane in layoutjson: + if counter < (len(layoutjson) - 1): + containername = parent + "." + str(order) + "." + str(counter) + ratio = (100 / (len(layoutjson) - counter)) / 100 + children[containername] = { + 'type': 'VPaned' if vertical else 'HPaned', + 'order': order + counter, + 'ratio': round(ratio, 2), + 'parent': actualparent + } + actualparent = containername + + if 'children' in pane: + if len(pane['children']) == 1: + self.build_terminal_layout(pane, pane['children'], containername, counter) + else: + self.build_container_layout(pane['children'], children, containername, counter, False if vertical else True) + else: + self.build_terminal_layout(pane, children, containername, counter) + + counter += 1 + + def get_layout_file(self, layoutname): + if (not path.exists(layoutname)): + return None + + dbg('Loading layout from a file: %s' % layoutname) + + layoutjson = None + + try: + with open(layoutname) as json_file: + layoutjson = json.load(json_file) + except Exception as ex: + err('Error loading layout file %s (%s)' % (layoutname, ex)) + return None + + try: + vertical = True + if "vertical" in layoutjson: + vertical = layoutjson["vertical"] + del layoutjson["vertical"] + + result = None + + if len(layoutjson) == 1: + firstitem = next(iter(layoutjson.values())) + result = self.build_single_tab_layout(firstitem, vertical) + else: + result = self.build_multi_tab_layout(layoutjson, vertical) + + dbg('Json layout is: %s' % result) + return result + except Exception as ex: + err('Error building a layout from file %s (%s)' % (layoutname, ex)) + traceback.print_exc(ex) + return None diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index c634f98e..1ba97332 100644 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -16,6 +16,7 @@ from .keybindings import Keybindings from .util import dbg, err, enumerate_descendants from .factory import Factory from .version import APP_NAME, APP_VERSION +from .layoutfile import LayoutFile try: from gi.repository import GdkX11 @@ -227,10 +228,13 @@ class Terminator(Borg): layout = copy.deepcopy(self.config.layout_get_config(layoutname)) if not layout: - # User specified a non-existent layout. default to one Terminal - err('layout %s not defined' % layout) - self.new_window() - return + layoutfile = LayoutFile() + layout = layoutfile.get_layout_file(layoutname) + if not layout: + # User specified a non-existent layout. default to one Terminal + err('layout %s not defined' % layout) + self.new_window() + return # Wind the flat objects into a hierarchy hierarchy = {} From 69c8a3f1d94b9d3337645347e83f00b32b2f41f9 Mon Sep 17 00:00:00 2001 From: David Levanon Date: Sun, 20 Sep 2020 21:15:14 +0300 Subject: [PATCH 2/9] fix some complicated layouts --- terminatorlib/layoutfile.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/terminatorlib/layoutfile.py b/terminatorlib/layoutfile.py index ff25933b..add0b529 100644 --- a/terminatorlib/layoutfile.py +++ b/terminatorlib/layoutfile.py @@ -14,10 +14,7 @@ class LayoutFile(object): } } - if len(layoutjson) == 1: - self.build_terminal_layout(layoutjson, result, 'root', 0) - else: - self.build_container_layout(layoutjson, result, 'root', 0, vertical) + self.build_container_layout(layoutjson, result, 'root', 0, vertical) return result @@ -41,10 +38,7 @@ class LayoutFile(object): for tab in layoutjson: tabs['labels'].append(tab) - if len(layoutjson[tab]) == 1: - self.build_terminal_layout(layoutjson[tab][0], result, 'tabs', counter) - else: - self.build_container_layout(layoutjson[tab], result, 'tabs', counter, vertical) + self.build_container_layout(layoutjson[tab], result, 'tabs', counter, vertical) counter += 1 return result @@ -60,6 +54,15 @@ class LayoutFile(object): } def build_container_layout(self, layoutjson, children, parent, order, vertical): + if len(layoutjson) == 1: + layoutjson = layoutjson[0] + + if 'children' in layoutjson: + self.build_container_layout(layoutjson['children'], children, parent, order, False if vertical else True) + else: + self.build_terminal_layout(layoutjson, children, parent, order) + return + dbg ('Building %s layout from json: %s' % ("vertical" if vertical else "horizental", layoutjson)) counter = 0 @@ -78,10 +81,7 @@ class LayoutFile(object): actualparent = containername if 'children' in pane: - if len(pane['children']) == 1: - self.build_terminal_layout(pane, pane['children'], containername, counter) - else: - self.build_container_layout(pane['children'], children, containername, counter, False if vertical else True) + self.build_container_layout(pane['children'], children, containername, counter, False if vertical else True) else: self.build_terminal_layout(pane, children, containername, counter) From 130b0a0af1f2d7b42e58cfe09830ed78f79b33d1 Mon Sep 17 00:00:00 2001 From: David Levanon Date: Sun, 20 Sep 2020 23:54:10 +0300 Subject: [PATCH 3/9] adding profile to the layout file fix layout examples - adding profile refactor - changing layoutfile to configjson --- layout-files-examples/2-3-grid.json | 62 ++++++----- layout-files-examples/2-columns.json | 20 ++-- layout-files-examples/3-rows.json | 24 +++-- layout-files-examples/3-tabs-2-rows.json | 50 ++++----- layout-files-examples/3-tabs-3-columns.json | 70 ++++++------ layout-files-examples/4-4-grid.json | 101 +++++++++++++----- terminator | 6 ++ .../{layoutfile.py => configjson.py} | 82 ++++++++++---- terminatorlib/optionparse.py | 2 + terminatorlib/terminator.py | 15 ++- 10 files changed, 271 insertions(+), 161 deletions(-) rename terminatorlib/{layoutfile.py => configjson.py} (67%) diff --git a/layout-files-examples/2-3-grid.json b/layout-files-examples/2-3-grid.json index 5266aa36..5d6c9d21 100644 --- a/layout-files-examples/2-3-grid.json +++ b/layout-files-examples/2-3-grid.json @@ -1,30 +1,36 @@ { - "tab1": [ - { - "children": [ - { - "command": "bash" - }, - { - "command": "bash" - }, - { - "command": "bash" - } - ] - }, - { - "children": [ - { - "command": "bash" - }, - { - "command": "bash" - }, - { - "command": "bash" - } - ] - } - ] + "layout": { + "tab1": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } + ] + }, + "profile": { + "background_color": "#170717", + "foreground_color": "#f5c0b7" + } } diff --git a/layout-files-examples/2-columns.json b/layout-files-examples/2-columns.json index 8030d45a..1524f19e 100644 --- a/layout-files-examples/2-columns.json +++ b/layout-files-examples/2-columns.json @@ -1,11 +1,13 @@ { - "vertical": false, - "tab1": [ - { - "command": "bash" - }, - { - "command": "bash" - } - ] + "layout": { + "vertical": false, + "tab1": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } } diff --git a/layout-files-examples/3-rows.json b/layout-files-examples/3-rows.json index 560857ab..aaf4fd91 100644 --- a/layout-files-examples/3-rows.json +++ b/layout-files-examples/3-rows.json @@ -1,13 +1,15 @@ { - "tab1": [ - { - "command": "bash" - }, - { - "command": "bash" - }, - { - "command": "bash" - } - ] + "layout": { + "tab1": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } } diff --git a/layout-files-examples/3-tabs-2-rows.json b/layout-files-examples/3-tabs-2-rows.json index 0dc7f9bd..e0d2d2c8 100644 --- a/layout-files-examples/3-tabs-2-rows.json +++ b/layout-files-examples/3-tabs-2-rows.json @@ -1,26 +1,28 @@ { - "tab1": [ - { - "command": "bash" - }, - { - "command": "bash" - } - ], - "tab2": [ - { - "command": "bash" - }, - { - "command": "bash" - } - ], - "tab3": [ - { - "command": "bash" - }, - { - "command": "bash" - } - ] + "layout": { + "tab1": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "tab2": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "tab3": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } } diff --git a/layout-files-examples/3-tabs-3-columns.json b/layout-files-examples/3-tabs-3-columns.json index ae9e103c..86792074 100644 --- a/layout-files-examples/3-tabs-3-columns.json +++ b/layout-files-examples/3-tabs-3-columns.json @@ -1,36 +1,38 @@ { - "vertical": false, - "tab1": [ - { - "command": "bash" - }, - { - "command": "bash" - }, - { - "command": "bash" - } - ], - "tab2": [ - { - "command": "bash" - }, - { - "command": "bash" - }, - { - "command": "bash" - } - ], - "tab3": [ - { - "command": "bash" - }, - { - "command": "bash" - }, - { - "command": "bash" - } - ] + "layout": { + "vertical": false, + "tab1": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "tab2": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "tab3": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } } diff --git a/layout-files-examples/4-4-grid.json b/layout-files-examples/4-4-grid.json index 5266aa36..789c0810 100644 --- a/layout-files-examples/4-4-grid.json +++ b/layout-files-examples/4-4-grid.json @@ -1,30 +1,75 @@ { - "tab1": [ - { - "children": [ - { - "command": "bash" - }, - { - "command": "bash" - }, - { - "command": "bash" - } - ] - }, - { - "children": [ - { - "command": "bash" - }, - { - "command": "bash" - }, - { - "command": "bash" - } - ] - } - ] + "layout": { + "tab1": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } + ] + }, + "profile": { + "background_color": "#070717", + "foreground_color": "#f5c0b7", + "font": "Monospace 16" + } } diff --git a/terminator b/terminator index 9727a9ed..89e6b5c9 100755 --- a/terminator +++ b/terminator @@ -51,6 +51,7 @@ from terminatorlib.factory import Factory from terminatorlib.version import APP_NAME, APP_VERSION from terminatorlib.util import dbg, err from terminatorlib.layoutlauncher import LayoutLauncher +from terminatorlib.configjson import ConfigJson if __name__ == '__main__': # Workaround for IBus intefering with broadcast when using dead keys @@ -68,6 +69,11 @@ if __name__ == '__main__': OPTIONS,dbus_options = terminatorlib.optionparse.parse_options() + if OPTIONS.configjson: + layoutname = ConfigJson().extend_config(OPTIONS.configjson) + if layoutname and ((not OPTIONS.layout) or OPTIONS.layout == 'default'): + OPTIONS.layout = layoutname + TERMINATOR = Terminator() TERMINATOR.set_origcwd(ORIGCWD) diff --git a/terminatorlib/layoutfile.py b/terminatorlib/configjson.py similarity index 67% rename from terminatorlib/layoutfile.py rename to terminatorlib/configjson.py index add0b529..fe92434f 100644 --- a/terminatorlib/layoutfile.py +++ b/terminatorlib/configjson.py @@ -2,9 +2,15 @@ from .util import dbg, err from os import path import sys import json -import traceback +import copy +from .config import Config -class LayoutFile(object): +class ConfigJson(object): + JSON_PROFILE_NAME = "__internal_json_profile__" + JSON_LAYOUT_NAME = "__internal_json_layout__" + + profile_to_use = 'default' + def build_single_tab_layout(self, layoutjson, vertical): dbg ('Budiling a single tab layout from json: %s ' % layoutjson) @@ -50,6 +56,7 @@ class LayoutFile(object): 'type': 'Terminal', 'order': order, 'parent': parent, + 'profile': self.profile_to_use, 'command': layoutjson['command'] } @@ -87,21 +94,7 @@ class LayoutFile(object): counter += 1 - def get_layout_file(self, layoutname): - if (not path.exists(layoutname)): - return None - - dbg('Loading layout from a file: %s' % layoutname) - - layoutjson = None - - try: - with open(layoutname) as json_file: - layoutjson = json.load(json_file) - except Exception as ex: - err('Error loading layout file %s (%s)' % (layoutname, ex)) - return None - + def get_layout(self, layoutjson): try: vertical = True if "vertical" in layoutjson: @@ -119,6 +112,57 @@ class LayoutFile(object): dbg('Json layout is: %s' % result) return result except Exception as ex: - err('Error building a layout from file %s (%s)' % (layoutname, ex)) - traceback.print_exc(ex) + err('Error building a layout from file %s' % ex) return None + + def get_profile(self, profilejson, baseprofile): + try: + result = copy.deepcopy(baseprofile) + + result.update(profilejson) + + dbg('Json profile is: %s' % result) + return result + except Exception as ex: + err('Error building a profile from json file %s' % ex) + return None + + def read_config(self, jsonfile): + if not path.exists(jsonfile): + dbg("Json config file is missing %s" % jsonfile) + return None + + dbg('Loading config json from a file: %s' % jsonfile) + + layoutjson = None + + try: + with open(jsonfile) as json_file: + layoutjson = json.load(json_file) + except Exception as ex: + err('Error loading config json file %s (%s)' % (jsonfile, ex)) + return None + + return layoutjson + + def extend_config(self, jsonfile): + configjson = self.read_config(jsonfile) + + if not configjson: + return None + + config = Config() + + if 'profile' in configjson: + profile = self.get_profile(configjson['profile'], config.base.profiles['default']) + if profile: + config.base.profiles[self.JSON_PROFILE_NAME] = profile + self.profile_to_use = self.JSON_PROFILE_NAME + + if 'layout' in configjson: + layout = self.get_layout(configjson['layout']) + if layout: + config.base.layouts[self.JSON_LAYOUT_NAME] = layout + return self.JSON_LAYOUT_NAME + + return None diff --git a/terminatorlib/optionparse.py b/terminatorlib/optionparse.py index 63a6f625..8efd242b 100644 --- a/terminatorlib/optionparse.py +++ b/terminatorlib/optionparse.py @@ -74,6 +74,8 @@ def parse_options(): 'execute inside the terminal, and its arguments')) parser.add_option('-g', '--config', dest='config', help=_('Specify a config file')) + parser.add_option('-j', '--config-json', dest='configjson', + help=_('Specify a partial config json file')) parser.add_option('-x', '--execute', dest='execute', action='callback', callback=execute_cb, help=_('Use the rest of the command line as a command to execute ' diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 1ba97332..fea5009c 100644 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -16,7 +16,6 @@ from .keybindings import Keybindings from .util import dbg, err, enumerate_descendants from .factory import Factory from .version import APP_NAME, APP_VERSION -from .layoutfile import LayoutFile try: from gi.repository import GdkX11 @@ -50,6 +49,7 @@ class Terminator(Borg): keybindings = None style_providers = None last_focused_term = None + layout_file = None origcwd = None dbus_path = None @@ -227,14 +227,12 @@ class Terminator(Borg): self.prelayout_windows = self.windows[:] layout = copy.deepcopy(self.config.layout_get_config(layoutname)) + if not layout: - layoutfile = LayoutFile() - layout = layoutfile.get_layout_file(layoutname) - if not layout: - # User specified a non-existent layout. default to one Terminal - err('layout %s not defined' % layout) - self.new_window() - return + # User specified a non-existent layout. default to one Terminal + err('layout %s not defined' % layout) + self.new_window() + return # Wind the flat objects into a hierarchy hierarchy = {} @@ -425,6 +423,7 @@ class Terminator(Borg): background-color: alpha(%s, %s); } """ profiles = self.config.base.profiles + for profile in list(profiles.keys()): if profiles[profile]['use_theme_colors']: # Create a dummy window/vte and realise it so it has correct From 0151c68abeb508b400aa69cd77b42e3b3320869c Mon Sep 17 00:00:00 2001 From: David Levanon Date: Mon, 21 Sep 2020 01:04:59 +0300 Subject: [PATCH 4/9] revert terminator.py back --- terminatorlib/terminator.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index fea5009c..d8d76b4d 100644 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -49,7 +49,6 @@ class Terminator(Borg): keybindings = None style_providers = None last_focused_term = None - layout_file = None origcwd = None dbus_path = None @@ -227,7 +226,6 @@ class Terminator(Borg): self.prelayout_windows = self.windows[:] layout = copy.deepcopy(self.config.layout_get_config(layoutname)) - if not layout: # User specified a non-existent layout. default to one Terminal err('layout %s not defined' % layout) @@ -423,7 +421,6 @@ class Terminator(Borg): background-color: alpha(%s, %s); } """ profiles = self.config.base.profiles - for profile in list(profiles.keys()): if profiles[profile]['use_theme_colors']: # Create a dummy window/vte and realise it so it has correct @@ -634,4 +631,4 @@ class Terminator(Borg): return(layout) -# vim: set expandtab ts=4 sw=4: +# vim: set expandtab ts=4 sw=4: \ No newline at end of file From 42b19150656eb91dd79e17fee63256f3024e8b14 Mon Sep 17 00:00:00 2001 From: David Levanon Date: Thu, 24 Sep 2020 13:12:23 +0300 Subject: [PATCH 5/9] support ratio for terminals --- terminatorlib/configjson.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/terminatorlib/configjson.py b/terminatorlib/configjson.py index fe92434f..02872791 100644 --- a/terminatorlib/configjson.py +++ b/terminatorlib/configjson.py @@ -79,10 +79,12 @@ class ConfigJson(object): if counter < (len(layoutjson) - 1): containername = parent + "." + str(order) + "." + str(counter) ratio = (100 / (len(layoutjson) - counter)) / 100 + if 'ratio' in pane: + ratio = pane['ratio'] children[containername] = { 'type': 'VPaned' if vertical else 'HPaned', 'order': order + counter, - 'ratio': round(ratio, 2), + 'ratio': ratio, 'parent': actualparent } actualparent = containername From b66999618067c314d16e0d0f6d7cad2ed6dfe0f0 Mon Sep 17 00:00:00 2001 From: David Levanon Date: Thu, 24 Sep 2020 13:39:42 +0300 Subject: [PATCH 6/9] prevent json layout and profile from being saved to the global config file --- terminatorlib/config.py | 6 ++++++ terminatorlib/configjson.py | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 4abc564b..371e534a 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -696,14 +696,20 @@ class ConfigBase(Borg): section = getattr(self, section_name) parser[section_name] = dict_diff(DEFAULTS[section_name], section) + from .configjson import JSON_PROFILE_NAME, JSON_LAYOUT_NAME + parser['profiles'] = {} for profile in self.profiles: + if profile == JSON_PROFILE_NAME: + continue dbg('ConfigBase::save: Processing profile: %s' % profile) parser['profiles'][profile] = dict_diff( DEFAULTS['profiles']['default'], self.profiles[profile]) parser['layouts'] = {} for layout in self.layouts: + if layout == JSON_LAYOUT_NAME: + continue dbg('ConfigBase::save: Processing layout: %s' % layout) parser['layouts'][layout] = self.layouts[layout] diff --git a/terminatorlib/configjson.py b/terminatorlib/configjson.py index 02872791..d6b5972b 100644 --- a/terminatorlib/configjson.py +++ b/terminatorlib/configjson.py @@ -5,9 +5,10 @@ import json import copy from .config import Config +JSON_PROFILE_NAME = "__internal_json_profile__" +JSON_LAYOUT_NAME = "__internal_json_layout__" + class ConfigJson(object): - JSON_PROFILE_NAME = "__internal_json_profile__" - JSON_LAYOUT_NAME = "__internal_json_layout__" profile_to_use = 'default' @@ -158,13 +159,13 @@ class ConfigJson(object): if 'profile' in configjson: profile = self.get_profile(configjson['profile'], config.base.profiles['default']) if profile: - config.base.profiles[self.JSON_PROFILE_NAME] = profile - self.profile_to_use = self.JSON_PROFILE_NAME + config.base.profiles[JSON_PROFILE_NAME] = profile + self.profile_to_use = JSON_PROFILE_NAME if 'layout' in configjson: layout = self.get_layout(configjson['layout']) if layout: - config.base.layouts[self.JSON_LAYOUT_NAME] = layout - return self.JSON_LAYOUT_NAME + config.base.layouts[JSON_LAYOUT_NAME] = layout + return JSON_LAYOUT_NAME return None From f387f4886c068e610eaf45cba92fa09f6de8024d Mon Sep 17 00:00:00 2001 From: David Levanon Date: Thu, 24 Sep 2020 15:19:58 +0300 Subject: [PATCH 7/9] set default profile from the json file --- terminator | 5 ++++- terminatorlib/configjson.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/terminator b/terminator index 89e6b5c9..808888c7 100755 --- a/terminator +++ b/terminator @@ -70,9 +70,12 @@ if __name__ == '__main__': OPTIONS,dbus_options = terminatorlib.optionparse.parse_options() if OPTIONS.configjson: - layoutname = ConfigJson().extend_config(OPTIONS.configjson) + configjson = ConfigJson() + layoutname = configjson.extend_config(OPTIONS.configjson) if layoutname and ((not OPTIONS.layout) or OPTIONS.layout == 'default'): OPTIONS.layout = layoutname + if not OPTIONS.profile: + OPTIONS.profile = configjson.get_profile_to_use() TERMINATOR = Terminator() TERMINATOR.set_origcwd(ORIGCWD) diff --git a/terminatorlib/configjson.py b/terminatorlib/configjson.py index d6b5972b..48c6ab5a 100644 --- a/terminatorlib/configjson.py +++ b/terminatorlib/configjson.py @@ -9,8 +9,10 @@ JSON_PROFILE_NAME = "__internal_json_profile__" JSON_LAYOUT_NAME = "__internal_json_layout__" class ConfigJson(object): - profile_to_use = 'default' + + def get_profile_to_use(self): + return self.profile_to_use def build_single_tab_layout(self, layoutjson, vertical): dbg ('Budiling a single tab layout from json: %s ' % layoutjson) From 231c9fb210a15f7c29607b9f7581938ef7ffe261 Mon Sep 17 00:00:00 2001 From: David Levanon Date: Sun, 4 Oct 2020 13:38:45 +0300 Subject: [PATCH 8/9] move json layout example files to data --- .../layout-files-examples}/2-3-grid.json | 0 .../layout-files-examples}/2-columns.json | 0 .../layout-files-examples}/3-rows.json | 0 .../layout-files-examples}/3-tabs-2-rows.json | 0 .../3-tabs-3-columns.json | 0 .../layout-files-examples}/4-4-grid.json | 0 data/layout-files-examples/README | 8 + data/layout-files-examples/complex.json | 224 ++++++++++++++++++ 8 files changed, 232 insertions(+) rename {layout-files-examples => data/layout-files-examples}/2-3-grid.json (100%) rename {layout-files-examples => data/layout-files-examples}/2-columns.json (100%) rename {layout-files-examples => data/layout-files-examples}/3-rows.json (100%) rename {layout-files-examples => data/layout-files-examples}/3-tabs-2-rows.json (100%) rename {layout-files-examples => data/layout-files-examples}/3-tabs-3-columns.json (100%) rename {layout-files-examples => data/layout-files-examples}/4-4-grid.json (100%) create mode 100644 data/layout-files-examples/README create mode 100644 data/layout-files-examples/complex.json diff --git a/layout-files-examples/2-3-grid.json b/data/layout-files-examples/2-3-grid.json similarity index 100% rename from layout-files-examples/2-3-grid.json rename to data/layout-files-examples/2-3-grid.json diff --git a/layout-files-examples/2-columns.json b/data/layout-files-examples/2-columns.json similarity index 100% rename from layout-files-examples/2-columns.json rename to data/layout-files-examples/2-columns.json diff --git a/layout-files-examples/3-rows.json b/data/layout-files-examples/3-rows.json similarity index 100% rename from layout-files-examples/3-rows.json rename to data/layout-files-examples/3-rows.json diff --git a/layout-files-examples/3-tabs-2-rows.json b/data/layout-files-examples/3-tabs-2-rows.json similarity index 100% rename from layout-files-examples/3-tabs-2-rows.json rename to data/layout-files-examples/3-tabs-2-rows.json diff --git a/layout-files-examples/3-tabs-3-columns.json b/data/layout-files-examples/3-tabs-3-columns.json similarity index 100% rename from layout-files-examples/3-tabs-3-columns.json rename to data/layout-files-examples/3-tabs-3-columns.json diff --git a/layout-files-examples/4-4-grid.json b/data/layout-files-examples/4-4-grid.json similarity index 100% rename from layout-files-examples/4-4-grid.json rename to data/layout-files-examples/4-4-grid.json diff --git a/data/layout-files-examples/README b/data/layout-files-examples/README new file mode 100644 index 00000000..98ce6592 --- /dev/null +++ b/data/layout-files-examples/README @@ -0,0 +1,8 @@ +The JSONs files in this directory are example config files used by `--config-json` option. + +Once this feature would be documented officialy this directoy can be removed. + +Example: +``` +./terminator --config-json data/layout-files-examples/2-3-grid.json +``` diff --git a/data/layout-files-examples/complex.json b/data/layout-files-examples/complex.json new file mode 100644 index 00000000..f92e83d3 --- /dev/null +++ b/data/layout-files-examples/complex.json @@ -0,0 +1,224 @@ +{ + "layout":{ + "columns": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } + ], + "rows": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ], + "grid": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } + ], + "border": [ + { + "command": "bash", + "ratio": 0.2 + }, + { + "ratio": 0.8, + "children": [ + { + "command": "bash", + "ratio": 0.2 + }, + { + "command": "bash", + "ratio": 0.8 + }, + { + "command": "bash" + } + ] + }, + { + "command": "bash" + } + ], + "nested": [ + { + "children": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "children": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } + ] + }, + { + "children": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] + }, + { + "children": [ + { + "command": "bash" + }, + { + "command": "bash" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + "profile":{ + "background_color": "#170717", + "foreground_color": "#f5c0b7", + "font": "Monospace 16", + "scrollback_infinite":"True" + } +} \ No newline at end of file From cca9ee3e909fffec57ba10a2d3c61dcda37b1e7c Mon Sep 17 00:00:00 2001 From: David Levanon Date: Sun, 4 Oct 2020 13:40:20 +0300 Subject: [PATCH 9/9] rename readme to readme.md --- data/layout-files-examples/{README => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename data/layout-files-examples/{README => README.md} (100%) diff --git a/data/layout-files-examples/README b/data/layout-files-examples/README.md similarity index 100% rename from data/layout-files-examples/README rename to data/layout-files-examples/README.md