Skip to content

Fix format seperator #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libtmux/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
For reference: https://github.com/tmux/tmux/blob/master/format.c

"""
import os

FORMAT_SEPERATOR = os.environ.get("TMUX_SEPERATOR", "|")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astonishingly, despite "seperator" being used everywhere (and it feels right to me) apparently its separator

I will make a change for that and also give it a namespaced env name LIBTMUX_TMUX_FORMAT_SEPARATOR to avoid any ambiguity

Copy link
Member

@tony tony Feb 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24393a3, 76faeb1

(side notes: FYI these refs are subject to break pending change #350)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. I opened #355 to discuss a default formatting string


SESSION_FORMATS = [
'session_name',
Expand Down
25 changes: 17 additions & 8 deletions libtmux/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 = [
Expand Down Expand Up @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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

Expand All @@ -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 = [
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions libtmux/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions libtmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def split_window(
'window_index',
'window_id',
] + formats.PANE_FORMATS
tmux_formats = ['#{%s}$@$' % 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..
Expand Down Expand Up @@ -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)
Expand Down