Skip to content

Commit 6870528

Browse files
committed
build(deps): Typings for Freezer
1 parent 15b1ae3 commit 6870528

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

src/tmuxp/workspace/freezer.py

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from libtmux.pane import Pane
2+
from libtmux.session import Session
3+
import typing as t
4+
5+
16
def inline(workspace_dict):
27
"""Return workspace with inlined shorthands. Opposite of :meth:`loader.expand`.
38
@@ -40,7 +45,7 @@ def inline(workspace_dict):
4045
return workspace_dict
4146

4247

43-
def freeze(session):
48+
def freeze(session: Session) -> t.Dict[str, t.Any]:
4449
"""Freeze live tmux session into a tmuxp workspacee.
4550
4651
Parameters
@@ -53,53 +58,61 @@ def freeze(session):
5358
dict
5459
tmuxp compatible workspace
5560
"""
56-
sconf = {"session_name": session.session_name, "windows": []}
57-
58-
for w in session.windows:
59-
wconf = {
60-
"options": w.show_window_options(),
61-
"window_name": w.name,
62-
"layout": w.window_layout,
61+
session_config: t.Dict[str, t.Any] = {
62+
"session_name": session.session_name,
63+
"windows": [],
64+
}
65+
66+
for window in session.windows:
67+
window_config: t.Dict[str, t.Any] = {
68+
"options": window.show_window_options(),
69+
"window_name": window.name,
70+
"layout": window.window_layout,
6371
"panes": [],
6472
}
65-
if getattr(w, "window_active", "0") == "1":
66-
wconf["focus"] = "true"
73+
74+
if getattr(window, "window_active", "0") == "1":
75+
window_config["focus"] = "true"
6776

6877
# If all panes have same path, set 'start_directory' instead
6978
# of using 'cd' shell commands.
70-
def pane_has_same_path(p):
71-
return w.panes[0].pane_current_path == p.pane_current_path
79+
def pane_has_same_path(pane: Pane) -> bool:
80+
return window.panes[0].pane_current_path == pane.pane_current_path
7281

73-
if all(pane_has_same_path(p) for p in w.panes):
74-
wconf["start_directory"] = w.panes[0].pane_current_path
82+
if all(pane_has_same_path(pane=pane) for pane in window.panes):
83+
window_config["start_directory"] = window.panes[0].pane_current_path
7584

76-
for p in w.panes:
77-
pconf = {"shell_command": []}
85+
for pane in window.panes:
86+
pane_config: t.Union[str, t.Dict[str, t.Any]] = {"shell_command": []}
87+
assert isinstance(pane_config, dict)
7888

79-
if "start_directory" not in wconf:
80-
pconf["shell_command"].append("cd " + p.pane_current_path)
89+
if "start_directory" not in window_config and pane.pane_current_path:
90+
pane_config["shell_command"].append("cd " + pane.pane_current_path)
8191

82-
if getattr(p, "pane_active", "0") == "1":
83-
pconf["focus"] = "true"
92+
if getattr(pane, "pane_active", "0") == "1":
93+
pane_config["focus"] = "true"
8494

85-
current_cmd = p.pane_current_command
95+
current_cmd = pane.pane_current_command
8696

87-
def filter_interpretters_and_shells():
88-
return current_cmd.startswith("-") or any(
89-
current_cmd.endswith(cmd) for cmd in ["python", "ruby", "node"]
97+
def filter_interpretters_and_shells() -> bool:
98+
return current_cmd is not None and (
99+
current_cmd.startswith("-")
100+
or any(
101+
current_cmd.endswith(cmd) for cmd in ["python", "ruby", "node"]
102+
)
90103
)
91104

92105
if filter_interpretters_and_shells():
93106
current_cmd = None
94107

95108
if current_cmd:
96-
pconf["shell_command"].append(current_cmd)
109+
pane_config["shell_command"].append(current_cmd)
97110
else:
98-
if not len(pconf["shell_command"]):
99-
pconf = "pane"
111+
if not len(pane_config["shell_command"]):
112+
pane_config = "pane"
100113

101-
wconf["panes"].append(pconf)
114+
window_config["panes"].append(pane_config)
102115

103-
sconf["windows"].append(wconf)
116+
session_config["windows"].append(window_config)
104117

105-
return sconf
118+
return session_config

0 commit comments

Comments
 (0)