Skip to content
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

Added unified parsing #53

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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: 2 additions & 1 deletion catmux/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import libtmux
import yaml

from catmux.utils import parse_commands

Check warning on line 31 in catmux/session.py

View check run for this annotation

Codecov / codecov/patch

catmux/session.py#L31

Added line #L31 was not covered by tests
from catmux.window import Window
import catmux.exceptions as cme

Expand Down Expand Up @@ -101,7 +102,7 @@
if "common" in self.__yaml_data and self.__yaml_data["common"]:
common = self.__yaml_data["common"]
if "before_commands" in common and common["before_commands"]:
self._before_commands = common["before_commands"]
self._before_commands = parse_commands(common, "before_commands")

Check warning on line 105 in catmux/session.py

View check run for this annotation

Codecov / codecov/patch

catmux/session.py#L105

Added line #L105 was not covered by tests

if "default_window" in common and common["default_window"]:
self._default_window = common["default_window"]
Expand Down
12 changes: 7 additions & 5 deletions catmux/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@

import libtmux

from catmux.utils import parse_commands

Check warning on line 30 in catmux/split.py

View check run for this annotation

Codecov / codecov/patch

catmux/split.py#L30

Added line #L30 was not covered by tests


class Split(object):

"""A split is a pane where commands can be executed"""

def __init__(self, **kwargs):
def __init__(self, commands):

Check warning on line 37 in catmux/split.py

View check run for this annotation

Codecov / codecov/patch

catmux/split.py#L37

Added line #L37 was not covered by tests
"""TODO: to be defined1."""
self.commands = list()

Check warning on line 39 in catmux/split.py

View check run for this annotation

Codecov / codecov/patch

catmux/split.py#L39

Added line #L39 was not covered by tests

if kwargs is not None:
for (key, value) in kwargs.items():
setattr(self, key, value)
if commands is not None:
self.commands = commands

Check warning on line 42 in catmux/split.py

View check run for this annotation

Codecov / codecov/patch

catmux/split.py#L41-L42

Added lines #L41 - L42 were not covered by tests

def debug(self, name="", prefix=""):
"""Prints all information about this window"""
Expand All @@ -48,5 +50,5 @@

def run(self, parent_pane: libtmux.Pane):
"Executes all configured commands" ""
for command in getattr(self, "commands"):
for command in self.commands:

Check warning on line 53 in catmux/split.py

View check run for this annotation

Codecov / codecov/patch

catmux/split.py#L53

Added line #L53 was not covered by tests
parent_pane.send_keys(command)
30 changes: 30 additions & 0 deletions catmux/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -- BEGIN LICENSE BLOCK ----------------------------------------------

# catmux
# Copyright (C) 2025 Felix Exner
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -- END LICENSE BLOCK ------------------------------------------------

"""General utility functions for catmux"""


def parse_commands(command_dict, key):
return command_dict[key]

Check warning on line 30 in catmux/utils.py

View check run for this annotation

Codecov / codecov/patch

catmux/utils.py#L29-L30

Added lines #L29 - L30 were not covered by tests
29 changes: 16 additions & 13 deletions catmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from catmux.split import Split
from catmux.exceptions import InvalidConfig
from catmux.utils import parse_commands

Check warning on line 33 in catmux/window.py

View check run for this annotation

Codecov / codecov/patch

catmux/window.py#L33

Added line #L33 was not covered by tests


class Window(object):
Expand All @@ -40,21 +41,23 @@
"""TODO: to be defined1."""

split_list = kwargs.pop("splits", None)
if not split_list:
if "commands" in kwargs:
split_dict = dict()
split_dict["commands"] = kwargs.pop("commands")
split_list = [split_dict]
else:
raise InvalidConfig(
f"No splits and no commands given for window '{kwargs['name']}'."
)

print(split_list)
split_command_list = list()
if split_list:
for split_data in split_list:
split_command_list.append(parse_commands(split_data, "commands"))
elif not split_list and "commands" in kwargs:
split_command_list.append(parse_commands(kwargs, "commands"))

Check warning on line 49 in catmux/window.py

View check run for this annotation

Codecov / codecov/patch

catmux/window.py#L44-L49

Added lines #L44 - L49 were not covered by tests
else:
raise InvalidConfig(

Check warning on line 51 in catmux/window.py

View check run for this annotation

Codecov / codecov/patch

catmux/window.py#L51

Added line #L51 was not covered by tests
f"No splits and no commands given for window '{kwargs['name']}'."
)

self.splits = list()
for split_data in split_list:
self.splits.append(Split(**split_data))
for split_data in split_command_list:
if hasattr(split_data, "__iter__"):
self.splits.append(Split(split_data))

Check warning on line 58 in catmux/window.py

View check run for this annotation

Codecov / codecov/patch

catmux/window.py#L56-L58

Added lines #L56 - L58 were not covered by tests
else:
print("Split is empty, dropping")

Check warning on line 60 in catmux/window.py

View check run for this annotation

Codecov / codecov/patch

catmux/window.py#L60

Added line #L60 was not covered by tests

if kwargs is not None:
for (key, value) in kwargs.items():
Expand Down