adding profile to the layout file
fix layout examples - adding profile refactor - changing layoutfile to configjson
This commit is contained in:
parent
69c8a3f1d9
commit
130b0a0af1
|
@ -1,30 +1,36 @@
|
||||||
{
|
{
|
||||||
"tab1": [
|
"layout": {
|
||||||
{
|
"tab1": [
|
||||||
"children": [
|
{
|
||||||
{
|
"children": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
]
|
}
|
||||||
},
|
]
|
||||||
{
|
},
|
||||||
"children": [
|
{
|
||||||
{
|
"children": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"profile": {
|
||||||
|
"background_color": "#170717",
|
||||||
|
"foreground_color": "#f5c0b7"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
{
|
{
|
||||||
"vertical": false,
|
"layout": {
|
||||||
"tab1": [
|
"vertical": false,
|
||||||
{
|
"tab1": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
{
|
{
|
||||||
"tab1": [
|
"layout": {
|
||||||
{
|
"tab1": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,28 @@
|
||||||
{
|
{
|
||||||
"tab1": [
|
"layout": {
|
||||||
{
|
"tab1": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
],
|
}
|
||||||
"tab2": [
|
],
|
||||||
{
|
"tab2": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
],
|
}
|
||||||
"tab3": [
|
],
|
||||||
{
|
"tab3": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,38 @@
|
||||||
{
|
{
|
||||||
"vertical": false,
|
"layout": {
|
||||||
"tab1": [
|
"vertical": false,
|
||||||
{
|
"tab1": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
],
|
}
|
||||||
"tab2": [
|
],
|
||||||
{
|
"tab2": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
],
|
}
|
||||||
"tab3": [
|
],
|
||||||
{
|
"tab3": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,75 @@
|
||||||
{
|
{
|
||||||
"tab1": [
|
"layout": {
|
||||||
{
|
"tab1": [
|
||||||
"children": [
|
{
|
||||||
{
|
"children": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"command": "bash"
|
{
|
||||||
}
|
"command": "bash"
|
||||||
]
|
},
|
||||||
},
|
{
|
||||||
{
|
"command": "bash"
|
||||||
"children": [
|
}
|
||||||
{
|
]
|
||||||
"command": "bash"
|
},
|
||||||
},
|
{
|
||||||
{
|
"children": [
|
||||||
"command": "bash"
|
{
|
||||||
},
|
"command": "bash"
|
||||||
{
|
},
|
||||||
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ from terminatorlib.factory import Factory
|
||||||
from terminatorlib.version import APP_NAME, APP_VERSION
|
from terminatorlib.version import APP_NAME, APP_VERSION
|
||||||
from terminatorlib.util import dbg, err
|
from terminatorlib.util import dbg, err
|
||||||
from terminatorlib.layoutlauncher import LayoutLauncher
|
from terminatorlib.layoutlauncher import LayoutLauncher
|
||||||
|
from terminatorlib.configjson import ConfigJson
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Workaround for IBus intefering with broadcast when using dead keys
|
# Workaround for IBus intefering with broadcast when using dead keys
|
||||||
|
@ -68,6 +69,11 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
OPTIONS,dbus_options = terminatorlib.optionparse.parse_options()
|
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 = Terminator()
|
||||||
TERMINATOR.set_origcwd(ORIGCWD)
|
TERMINATOR.set_origcwd(ORIGCWD)
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,15 @@ from .util import dbg, err
|
||||||
from os import path
|
from os import path
|
||||||
import sys
|
import sys
|
||||||
import json
|
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):
|
def build_single_tab_layout(self, layoutjson, vertical):
|
||||||
dbg ('Budiling a single tab layout from json: %s ' % layoutjson)
|
dbg ('Budiling a single tab layout from json: %s ' % layoutjson)
|
||||||
|
|
||||||
|
@ -50,6 +56,7 @@ class LayoutFile(object):
|
||||||
'type': 'Terminal',
|
'type': 'Terminal',
|
||||||
'order': order,
|
'order': order,
|
||||||
'parent': parent,
|
'parent': parent,
|
||||||
|
'profile': self.profile_to_use,
|
||||||
'command': layoutjson['command']
|
'command': layoutjson['command']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,21 +94,7 @@ class LayoutFile(object):
|
||||||
|
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
def get_layout_file(self, layoutname):
|
def get_layout(self, layoutjson):
|
||||||
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:
|
try:
|
||||||
vertical = True
|
vertical = True
|
||||||
if "vertical" in layoutjson:
|
if "vertical" in layoutjson:
|
||||||
|
@ -119,6 +112,57 @@ class LayoutFile(object):
|
||||||
dbg('Json layout is: %s' % result)
|
dbg('Json layout is: %s' % result)
|
||||||
return result
|
return result
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
err('Error building a layout from file %s (%s)' % (layoutname, ex))
|
err('Error building a layout from file %s' % ex)
|
||||||
traceback.print_exc(ex)
|
|
||||||
return None
|
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
|
|
@ -74,6 +74,8 @@ def parse_options():
|
||||||
'execute inside the terminal, and its arguments'))
|
'execute inside the terminal, and its arguments'))
|
||||||
parser.add_option('-g', '--config', dest='config',
|
parser.add_option('-g', '--config', dest='config',
|
||||||
help=_('Specify a config file'))
|
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',
|
parser.add_option('-x', '--execute', dest='execute', action='callback',
|
||||||
callback=execute_cb,
|
callback=execute_cb,
|
||||||
help=_('Use the rest of the command line as a command to execute '
|
help=_('Use the rest of the command line as a command to execute '
|
||||||
|
|
|
@ -16,7 +16,6 @@ from .keybindings import Keybindings
|
||||||
from .util import dbg, err, enumerate_descendants
|
from .util import dbg, err, enumerate_descendants
|
||||||
from .factory import Factory
|
from .factory import Factory
|
||||||
from .version import APP_NAME, APP_VERSION
|
from .version import APP_NAME, APP_VERSION
|
||||||
from .layoutfile import LayoutFile
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from gi.repository import GdkX11
|
from gi.repository import GdkX11
|
||||||
|
@ -50,6 +49,7 @@ class Terminator(Borg):
|
||||||
keybindings = None
|
keybindings = None
|
||||||
style_providers = None
|
style_providers = None
|
||||||
last_focused_term = None
|
last_focused_term = None
|
||||||
|
layout_file = None
|
||||||
|
|
||||||
origcwd = None
|
origcwd = None
|
||||||
dbus_path = None
|
dbus_path = None
|
||||||
|
@ -227,14 +227,12 @@ class Terminator(Borg):
|
||||||
self.prelayout_windows = self.windows[:]
|
self.prelayout_windows = self.windows[:]
|
||||||
|
|
||||||
layout = copy.deepcopy(self.config.layout_get_config(layoutname))
|
layout = copy.deepcopy(self.config.layout_get_config(layoutname))
|
||||||
|
|
||||||
if not layout:
|
if not layout:
|
||||||
layoutfile = LayoutFile()
|
# User specified a non-existent layout. default to one Terminal
|
||||||
layout = layoutfile.get_layout_file(layoutname)
|
err('layout %s not defined' % layout)
|
||||||
if not layout:
|
self.new_window()
|
||||||
# User specified a non-existent layout. default to one Terminal
|
return
|
||||||
err('layout %s not defined' % layout)
|
|
||||||
self.new_window()
|
|
||||||
return
|
|
||||||
|
|
||||||
# Wind the flat objects into a hierarchy
|
# Wind the flat objects into a hierarchy
|
||||||
hierarchy = {}
|
hierarchy = {}
|
||||||
|
@ -425,6 +423,7 @@ class Terminator(Borg):
|
||||||
background-color: alpha(%s, %s); }
|
background-color: alpha(%s, %s); }
|
||||||
"""
|
"""
|
||||||
profiles = self.config.base.profiles
|
profiles = self.config.base.profiles
|
||||||
|
|
||||||
for profile in list(profiles.keys()):
|
for profile in list(profiles.keys()):
|
||||||
if profiles[profile]['use_theme_colors']:
|
if profiles[profile]['use_theme_colors']:
|
||||||
# Create a dummy window/vte and realise it so it has correct
|
# Create a dummy window/vte and realise it so it has correct
|
||||||
|
|
Loading…
Reference in New Issue