From 51dbc1258ca31aa0481b36a09f230a5d799f71a6 Mon Sep 17 00:00:00 2001 From: Steven Joseph Date: Sun, 31 Oct 2021 11:07:01 +1100 Subject: [PATCH 1/4] fix: use `|` instead of `\t` for format sepatator - for some reason on my arch install tmux does not print back tabs I'm not sure if it affects other but just puttin this out there --- libtmux/formats.py | 4 ++++ libtmux/server.py | 25 +++++++++++++++++-------- libtmux/session.py | 6 ++++-- libtmux/window.py | 4 ++-- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/libtmux/formats.py b/libtmux/formats.py index 9887162fb..76550c536 100644 --- a/libtmux/formats.py +++ b/libtmux/formats.py @@ -7,6 +7,10 @@ """ +from __future__ import absolute_import, unicode_literals, with_statement + +FORMAT_SEPERATOR = "|" + SESSION_FORMATS = [ 'session_name', 'session_windows', diff --git a/libtmux/server.py b/libtmux/server.py index 99f11c346..ccbff1fd0 100644 --- a/libtmux/server.py +++ b/libtmux/server.py @@ -142,7 +142,7 @@ def _list_sessions(self): sformats = formats.SESSION_FORMATS tmux_formats = ['#{%s}' % f for f in sformats] - tmux_args = ('-F%s' % '$@$'.join(tmux_formats),) # output + tmux_args = ('-F%s' % formats.FORMAT_SEPERATOR.join(tmux_formats),) # output proc = self.cmd('list-sessions', *tmux_args) @@ -154,7 +154,10 @@ def _list_sessions(self): sessions = proc.stdout # combine format keys with values returned from ``tmux list-sessions`` - sessions = [dict(zip(sformats, session.split('$@$'))) for session in sessions] + sessions = [ + dict(zip(sformats, session.split(formats.FORMAT_SEPERATOR))) + for session in sessions + ] # clear up empty dict sessions = [ @@ -208,7 +211,7 @@ def _list_windows(self): proc = self.cmd( 'list-windows', # ``tmux list-windows`` '-a', - '-F%s' % '$@$'.join(tmux_formats), # output + '-F%s' % formats.FORMAT_SEPERATOR.join(tmux_formats), # output ) if proc.stderr: @@ -219,7 +222,10 @@ def _list_windows(self): wformats = ['session_name', 'session_id'] + formats.WINDOW_FORMATS # combine format keys with values returned from ``tmux list-windows`` - windows = [dict(zip(wformats, window.split('$@$'))) for window in windows] + windows = [ + dict(zip(wformats, window.split(formats.FORMAT_SEPERATOR))) + for window in windows + ] # clear up empty dict windows = [dict((k, v) for k, v in window.items() if v) for window in windows] @@ -268,7 +274,7 @@ def _list_panes(self): 'window_id', 'window_name', ] + formats.PANE_FORMATS - tmux_formats = ['#{%s}$@$' % f for f in pformats] + tmux_formats = [('#{%%s}%s' % formats.FORMAT_SEPERATOR) % f for f in pformats] proc = self.cmd('list-panes', '-a', '-F%s' % ''.join(tmux_formats)) # output @@ -286,7 +292,10 @@ def _list_panes(self): ] + formats.PANE_FORMATS # combine format keys with values returned from ``tmux list-panes`` - panes = [dict(zip(pformats, window.split('$@$'))) for window in panes] + panes = [ + dict(zip(pformats, window.split(formats.FORMAT_SEPERATOR))) + for window in panes + ] # clear up empty dict panes = [ @@ -527,7 +536,7 @@ def new_session( tmux_args = ( '-s%s' % session_name, '-P', - '-F%s' % '$@$'.join(tmux_formats), # output + '-F%s' % formats.FORMAT_SEPERATOR.join(tmux_formats), # output ) if not attach: @@ -558,7 +567,7 @@ def new_session( os.environ['TMUX'] = env # combine format keys with values returned from ``tmux list-windows`` - session = dict(zip(sformats, session.split('$@$'))) + session = dict(zip(sformats, session.split(formats.FORMAT_SEPERATOR))) # clear up empty dict session = dict((k, v) for k, v in session.items() if v) diff --git a/libtmux/session.py b/libtmux/session.py index 0c1db3f16..8d09f98e2 100644 --- a/libtmux/session.py +++ b/libtmux/session.py @@ -217,7 +217,9 @@ def new_window( start_directory = os.path.expanduser(start_directory) window_args += ('-c%s' % start_directory,) - window_args += ('-F"%s"' % '$@$'.join(tmux_formats),) # output + window_args += ( + '-F"%s"' % formats.FORMAT_SEPERATOR.join(tmux_formats), + ) # output if window_name: window_args += ('-n%s' % window_name,) @@ -237,7 +239,7 @@ def new_window( window = proc.stdout[0] - window = dict(zip(wformats, window.split('$@$'))) + window = dict(zip(wformats, window.split(formats.FORMAT_SEPERATOR))) # clear up empty dict window = dict((k, v) for k, v in window.items() if v) diff --git a/libtmux/window.py b/libtmux/window.py index 1c885bda3..dd412fad8 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -434,7 +434,7 @@ def split_window( 'window_index', 'window_id', ] + formats.PANE_FORMATS - tmux_formats = ['#{%s}$@$' % f for f in pformats] + tmux_formats = [('#{%%s}%s' % formats.FORMAT_SEPERATOR) % f for f in pformats] # '-t%s' % self.attached_pane.get('pane_id'), # 2013-10-18 LOOK AT THIS, rm'd it.. @@ -478,7 +478,7 @@ def split_window( else: pane = pane.stdout[0] - pane = dict(zip(pformats, pane.split('$@$'))) + pane = dict(zip(pformats, pane.split(formats.FORMAT_SEPERATOR))) # clear up empty dict pane = dict((k, v) for k, v in pane.items() if v) From cd918d583bc0dcf3cb7faf60689ddd4dda676feb Mon Sep 17 00:00:00 2001 From: Steven Joseph Date: Sun, 31 Oct 2021 11:17:09 +1100 Subject: [PATCH 2/4] Changed get seperator from env variable if available --- libtmux/formats.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libtmux/formats.py b/libtmux/formats.py index 76550c536..6399a3c18 100644 --- a/libtmux/formats.py +++ b/libtmux/formats.py @@ -9,7 +9,9 @@ from __future__ import absolute_import, unicode_literals, with_statement -FORMAT_SEPERATOR = "|" +from os import environ + +FORMAT_SEPERATOR = environ.get("TMUX_SEPERATOR", "|") SESSION_FORMATS = [ 'session_name', From fc235bae2794e20e6890e62028fa1e168c807731 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 26 Feb 2022 10:20:24 -0600 Subject: [PATCH 3/4] chore(window.split_window): Move to f-string --- libtmux/window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtmux/window.py b/libtmux/window.py index dd412fad8..8aa95c140 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -434,7 +434,7 @@ def split_window( 'window_index', 'window_id', ] + formats.PANE_FORMATS - tmux_formats = [('#{%%s}%s' % formats.FORMAT_SEPERATOR) % f for f in pformats] + tmux_formats = [(f'#{{{f}}}{formats.FORMAT_SEPERATOR}') for f in pformats] # '-t%s' % self.attached_pane.get('pane_id'), # 2013-10-18 LOOK AT THIS, rm'd it.. From 9411cc1de3b35dae87e024fcb3bcc04e7192262d Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 26 Feb 2022 10:22:57 -0600 Subject: [PATCH 4/4] chore(formats): Import tweak --- libtmux/formats.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libtmux/formats.py b/libtmux/formats.py index 6399a3c18..1dd64ec80 100644 --- a/libtmux/formats.py +++ b/libtmux/formats.py @@ -6,12 +6,9 @@ For reference: https://github.com/tmux/tmux/blob/master/format.c """ +import os -from __future__ import absolute_import, unicode_literals, with_statement - -from os import environ - -FORMAT_SEPERATOR = environ.get("TMUX_SEPERATOR", "|") +FORMAT_SEPERATOR = os.environ.get("TMUX_SEPERATOR", "|") SESSION_FORMATS = [ 'session_name',