Skip to content

Commit 52bad0b

Browse files
committed
types(workspace-imports) Example typings via NotRequried
1 parent a339934 commit 52bad0b

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/tmuxp/_internal/types.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,61 @@ class PluginConfigSchema(TypedDict):
3535
tmuxp_min_version: NotRequired[str]
3636
tmuxp_max_version: NotRequired[str]
3737
tmuxp_version_incompatible: NotRequired[list[str]]
38+
39+
40+
class ShellCommandConfig(TypedDict):
41+
"""Shell command configuration."""
42+
43+
cmd: str
44+
enter: NotRequired[bool]
45+
suppress_history: NotRequired[bool]
46+
47+
48+
ShellCommandValue = t.Union[str, ShellCommandConfig, list[t.Union[str, ShellCommandConfig]]]
49+
50+
51+
class PaneConfig(TypedDict, total=False):
52+
"""Pane configuration."""
53+
54+
shell_command: NotRequired[ShellCommandValue]
55+
shell_command_before: NotRequired[ShellCommandValue]
56+
start_directory: NotRequired[str]
57+
environment: NotRequired[dict[str, str]]
58+
focus: NotRequired[t.Union[str, bool]]
59+
suppress_history: NotRequired[bool]
60+
61+
62+
PaneValue = t.Union[str, PaneConfig]
63+
64+
65+
class WindowConfig(TypedDict, total=False):
66+
"""Window configuration."""
67+
68+
window_name: str
69+
start_directory: NotRequired[str]
70+
shell_command_before: NotRequired[ShellCommandValue]
71+
layout: NotRequired[str]
72+
options: NotRequired[dict[str, t.Any]]
73+
options_after: NotRequired[dict[str, t.Any]]
74+
environment: NotRequired[dict[str, str]]
75+
focus: NotRequired[t.Union[str, bool]]
76+
suppress_history: NotRequired[bool]
77+
panes: NotRequired[list[PaneValue]]
78+
79+
80+
class WorkspaceConfig(TypedDict, total=False):
81+
"""Complete tmuxp workspace configuration."""
82+
83+
session_name: t.Union[str, None] # Can be None during import
84+
start_directory: NotRequired[str]
85+
before_script: NotRequired[str]
86+
shell_command_before: NotRequired[ShellCommandValue]
87+
shell_command: NotRequired[ShellCommandValue] # Used in import
88+
environment: NotRequired[dict[str, str]]
89+
global_options: NotRequired[dict[str, t.Any]]
90+
options: NotRequired[dict[str, t.Any]]
91+
config: NotRequired[str] # tmux config file path
92+
socket_name: NotRequired[str] # tmux socket name
93+
plugins: NotRequired[list[t.Union[str, PluginConfigSchema]]]
94+
suppress_history: NotRequired[bool]
95+
windows: list[WindowConfig]

src/tmuxp/workspace/importers.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import typing as t
66

7+
if t.TYPE_CHECKING:
8+
from tmuxp._internal.types import WorkspaceConfig
9+
710

811
def import_tmuxinator(workspace_dict: dict[str, t.Any]) -> dict[str, t.Any]:
912
"""Return tmuxp workspace from a `tmuxinator`_ yaml workspace.
@@ -18,8 +21,9 @@ def import_tmuxinator(workspace_dict: dict[str, t.Any]) -> dict[str, t.Any]:
1821
Returns
1922
-------
2023
dict
24+
A dictionary conforming to WorkspaceConfig structure.
2125
"""
22-
tmuxp_workspace: dict[str, t.Any] = {}
26+
tmuxp_workspace: dict[str, t.Any] = {} # Will conform to WorkspaceConfig at the end
2327

2428
if "project_name" in workspace_dict:
2529
tmuxp_workspace["session_name"] = workspace_dict.pop("project_name")
@@ -112,6 +116,11 @@ def import_teamocil(workspace_dict: dict[str, t.Any]) -> dict[str, t.Any]:
112116
workspace_dict : dict
113117
python dict for tmuxp workspace
114118
119+
Returns
120+
-------
121+
dict
122+
A dictionary conforming to WorkspaceConfig structure.
123+
115124
Notes
116125
-----
117126
Todos:
@@ -122,7 +131,7 @@ def import_teamocil(workspace_dict: dict[str, t.Any]) -> dict[str, t.Any]:
122131
- clear
123132
- cmd_separator
124133
"""
125-
tmuxp_workspace: dict[str, t.Any] = {}
134+
tmuxp_workspace: dict[str, t.Any] = {} # Will conform to WorkspaceConfig at the end
126135

127136
if "session" in workspace_dict:
128137
workspace_dict = workspace_dict["session"]

0 commit comments

Comments
 (0)