Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_256_colors(server):
myserver = Server(colors=256)
assert myserver.colors == 256
proc = myserver.cmd('list-servers')
assert '-2' in proc.cmd
assert '-8' not in proc.cmd
def test_config(server):
""" ``-f`` file for tmux(1) configuration. """
myserver = Server(config_file='test')
assert myserver.config_file == 'test'
def test_socket_path(server):
""" ``-S`` socket_path (alternative path for server socket). """
myserver = Server(socket_path='test')
assert myserver.socket_path == 'test'
def test_socket_name(server):
""" ``-L`` socket_name.
``-L`` socket_name file name of socket. which will be stored in
env TMUX_TMPDIR or /tmp if unset.)
"""
myserver = Server(socket_name='test')
assert myserver.socket_name == 'test'
def test_88_colors(server):
myserver = Server(colors=88)
assert myserver.colors == 88
proc = myserver.cmd('list-servers')
assert '-8' in proc.cmd
assert '-2' not in proc.cmd
server : :class:`libtmux.Server`
tmux server to build session in
Notes
-----
TODO: Initialize :class:`libtmux.Session` from here, in
``self.session``.
"""
if not sconf:
raise exc.EmptyConfigException('session configuration is empty.')
# config.validate_schema(sconf)
if isinstance(server, Server):
self.server = server
else:
self.server = None
self.sconf = sconf
.. [1] cmd-switch-client.c hook. GitHub repo for tmux.
https://github.com/tmux/tmux/blob/2.6/cmd-switch-client.c#L132.
Accessed April 8th, 2018.
"""
# get the canonical path, eliminating any symlinks
config_file = os.path.realpath(config_file)
# kaptan allows us to open a yaml or json file as a dict
sconfig = kaptan.Kaptan()
sconfig = sconfig.import_config(config_file).get()
# shapes configurations relative to config / profile file location
sconfig = config.expand(sconfig, os.path.dirname(config_file))
# propagate config inheritance (e.g. session -> window, window -> pane)
sconfig = config.trickle(sconfig)
t = Server( # create tmux server object
socket_name=socket_name, socket_path=socket_path, colors=colors
)
which('tmux') # raise exception if tmux not found
try: # load WorkspaceBuilder object for tmuxp config / tmux server
builder = WorkspaceBuilder(sconf=sconfig, server=t)
except exc.EmptyConfigException:
click.echo('%s is empty or parsed no config data' % config_file, err=True)
return
session_name = sconfig['session_name']
# if the session already exists, prompt the user to attach. tmuxp doesn't
# support incremental session building or appending (yet, PR's welcome!)
if builder.session_exists(session_name):
def command_freeze(session_name, socket_name, socket_path):
"""Snapshot a session into a config.
If SESSION_NAME is provided, snapshot that session. Otherwise, use the
current session."""
t = Server(socket_name=socket_name, socket_path=socket_path)
try:
if session_name:
session = t.find_where({'session_name': session_name})
else:
session = t.list_sessions()[0]
if not session:
raise exc.TmuxpException('Session not found.')
except exc.TmuxpException as e:
print(e)
return
sconf = freeze(session)
configparser = kaptan.Kaptan()
newconfig = config.inline(sconf)