summaryrefslogtreecommitdiff
path: root/src/caelestia/subcommands/shell.py
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-14 22:50:55 +1000
committerGitHub <noreply@github.com>2025-06-14 22:50:55 +1000
commitee7291b7f64a359d17eb1d050086ef5357d79055 (patch)
treef1c200d8c8ba81030cbb2113a2be122db6508c8f /src/caelestia/subcommands/shell.py
parentMerge pull request #5 from dalpax/patch-1 (diff)
parentMerge branch 'main' into python-rework (diff)
downloadcaelestia-cli-ee7291b7f64a359d17eb1d050086ef5357d79055.tar.gz
caelestia-cli-ee7291b7f64a359d17eb1d050086ef5357d79055.tar.bz2
caelestia-cli-ee7291b7f64a359d17eb1d050086ef5357d79055.zip
Merge pull request #6 from caelestia-dots/python-rework
feat: rewrite in python
Diffstat (limited to 'src/caelestia/subcommands/shell.py')
-rw-r--r--src/caelestia/subcommands/shell.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/caelestia/subcommands/shell.py b/src/caelestia/subcommands/shell.py
new file mode 100644
index 0000000..25a39d8
--- /dev/null
+++ b/src/caelestia/subcommands/shell.py
@@ -0,0 +1,41 @@
+import subprocess
+from argparse import Namespace
+
+from caelestia.utils import paths
+
+
+class Command:
+ args: Namespace
+
+ def __init__(self, args: Namespace) -> None:
+ self.args = args
+
+ def run(self) -> None:
+ if self.args.show:
+ # Print the ipc
+ self.print_ipc()
+ elif self.args.log:
+ # Print the log
+ self.print_log()
+ elif self.args.message:
+ # Send a message
+ self.message(*self.args.message)
+ else:
+ # Start the shell
+ self.shell()
+
+ def shell(self, *args: list[str]) -> str:
+ return subprocess.check_output(["qs", "-p", paths.c_data_dir / "shell", *args], text=True)
+
+ def print_ipc(self) -> None:
+ print(self.shell("ipc", "show"), end="")
+
+ def print_log(self) -> None:
+ log = self.shell("log")
+ # FIXME: remove when logging rules are added/warning is removed
+ for line in log.splitlines():
+ if "QProcess: Destroyed while process" not in line:
+ print(line)
+
+ def message(self, *args: list[str]) -> None:
+ print(self.shell("ipc", "call", *args), end="")