emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/detached 9a00a50971 1/6: Introduce usage of tail for de


From: ELPA Syncer
Subject: [elpa] externals/detached 9a00a50971 1/6: Introduce usage of tail for degraded sessions
Date: Fri, 3 Jun 2022 03:57:32 -0400 (EDT)

branch: externals/detached
commit 9a00a50971671ae2e64c4692ff1bbdf845fcc680
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Introduce usage of tail for degraded sessions
---
 detached-compile.el |  5 ++--
 detached-eshell.el  |  7 ++---
 detached-shell.el   | 11 ++++----
 detached-vterm.el   |  4 +--
 detached.el         | 80 ++++++++++++++++++++++++++++++++++++++++-------------
 5 files changed, 73 insertions(+), 34 deletions(-)

diff --git a/detached-compile.el b/detached-compile.el
index 0c737bf6d4..cba80eb6ae 100644
--- a/detached-compile.el
+++ b/detached-compile.el
@@ -108,13 +108,12 @@ Optionally EDIT-COMMAND."
   (if detached-enabled
       (pcase-let ((`(,command ,mode ,_ ,highlight-regexp) args)
                   (buffer-name "*detached-compilation*"))
-        (if (and (not (eq detached-session-mode 'attach))
-                 (not (detached-attachable-command-p command)))
+        (if (eq detached-session-mode 'create)
             (detached-start-session command t)
           (cl-letf* ((name-function (lambda (_) buffer-name))
                      (detached--current-session (or detached--current-session
                                                     (detached-create-session 
command))))
-            (apply compilation-start `(,(detached-dtach-command 
detached--current-session t)
+            (apply compilation-start `(,(detached--shell-command 
detached--current-session t)
                                        ,(or mode 'detached-compilation-mode)
                                        ,name-function
                                        ,highlight-regexp)))))
diff --git a/detached-eshell.el b/detached-eshell.el
index 4c6c758ac1..adc0ca11ce 100644
--- a/detached-eshell.el
+++ b/detached-eshell.el
@@ -80,11 +80,10 @@ If prefix-argument directly DETACH from the session."
   (interactive
    (list (detached-eshell-select-session)))
   (when (detached-valid-session session)
-    (if (and (eq 'active (detached--determine-session-state session))
-             (detached--session-attachable session))
+    (if (eq 'active (detached--determine-session-state session))
         (cl-letf* ((detached-session-mode 'attach)
                    (input
-                    (detached-dtach-command session t))
+                    (detached--shell-command session t))
                    ((symbol-function #'eshell-add-to-history) #'ignore))
           (let ((kill-ring nil))
             (eshell-kill-input))
@@ -111,7 +110,7 @@ If prefix-argument directly DETACH from the session."
                               (flatten-list args)
                               " ")))
          (session (detached-create-session command))
-         (command (detached-dtach-command session)))
+         (command (detached--shell-command session)))
     (advice-remove #'eshell-external-command 
#'detached-eshell-external-command)
     (setq detached--buffer-session session)
     (setq detached-enabled nil)
diff --git a/detached-shell.el b/detached-shell.el
index 58a13c38a5..e3b9e5bfff 100644
--- a/detached-shell.el
+++ b/detached-shell.el
@@ -70,8 +70,7 @@ cluttering the comint-history with dtach commands."
   (interactive
    (list (detached-shell-select-session)))
   (when (detached-valid-session session)
-    (if (and (eq 'active (detached--determine-session-state session))
-             (detached--session-attachable session))
+    (if (eq 'active (detached--determine-session-state session))
         (cl-letf ((detached--current-session session)
                   (comint-input-sender #'detached-shell--attach-input-sender)
                   ((symbol-function 'comint-add-to-input-history) (lambda (_) 
t)))
@@ -88,15 +87,15 @@ cluttering the comint-history with dtach commands."
   "Attach to `detached--session' and send the attach command to PROC."
   (let* ((detached-session-mode 'attach)
          (input
-          (detached-dtach-command detached--current-session t)))
+          (detached--shell-command detached--current-session t)))
     (comint-simple-send proc input)))
 
 (defun detached-shell--create-input-sender (proc string)
   "Create a detached session based on STRING and send to PROC."
   (with-connection-local-variables
-   (let* ((command (substring-no-properties string))
-          (dtach-command (detached-dtach-command command t)))
-     (comint-simple-send proc dtach-command))))
+   (let* ((command (detached--shell-command
+                    (substring-no-properties string) t)))
+     (comint-simple-send proc command))))
 
 (defun detached-shell--comint-read-input-ring-advice (orig-fun &rest args)
   "Set `comint-input-ring-file-name' before calling ORIG-FUN with ARGS."
diff --git a/detached-vterm.el b/detached-vterm.el
index daff21faa4..71357d247a 100644
--- a/detached-vterm.el
+++ b/detached-vterm.el
@@ -53,7 +53,7 @@ Optionally DETACH from it."
          (detached-session-mode
           (if detach 'create 'create-and-attach)))
     (vterm-send-C-k)
-    (process-send-string vterm--process (detached-dtach-command input t))
+    (process-send-string vterm--process (detached--shell-command input t))
     (vterm-send-C-e)
     (vterm-send-return)))
 
@@ -70,7 +70,7 @@ Optionally DETACH from it."
                          (seq-filter (lambda (it) (eq 'active 
(detached--determine-session-state it)))))))
       (detached-completing-read sessions))))
   (let ((detached-session-mode 'attach))
-    (process-send-string vterm--process (detached-dtach-command session t))
+    (process-send-string vterm--process (detached--shell-command session t))
     (vterm-send-return)))
 
 ;;;###autoload
diff --git a/detached.el b/detached.el
index e3ae6f1a5a..2a427be677 100644
--- a/detached.el
+++ b/detached.el
@@ -379,8 +379,7 @@ The session is compiled by opening its output and enabling
   (interactive
    (list (detached-completing-read (detached-get-sessions))))
   (when (detached-valid-session session)
-    (if (or (eq 'inactive (detached--session-state session))
-            (not (detached--session-attachable session)))
+    (if (eq 'inactive (detached--session-state session))
         (detached-open-session session)
       (if-let ((attach-fun (plist-get (detached--session-action session) 
:attach)))
           (funcall attach-fun session)
@@ -587,9 +586,8 @@ Optionally SUPPRESS-OUTPUT."
          (or detached--current-session
              (detached-create-session command))))
     (if-let ((run-in-background
-              (and (or suppress-output
-                       (eq detached-session-mode 'create)
-                       (not (detached--session-attachable 
detached--current-session)))))
+              (or suppress-output
+                  (eq detached-session-mode 'create)))
              (detached-session-mode 'create))
         (progn (setq detached-enabled nil)
                (if detached-local-session
@@ -599,11 +597,12 @@ Optionally SUPPRESS-OUTPUT."
                         `("detached" nil ,(detached-dtach-command 
detached--current-session t)))))
       (cl-letf* ((detached-session-mode 'create-and-attach)
                  ((symbol-function #'set-process-sentinel) #'ignore)
-                 (buffer (get-buffer-create detached--shell-command-buffer)))
+                 (buffer (get-buffer-create detached--shell-command-buffer))
+                 (command (detached--shell-command detached--current-session 
t)))
         (when (get-buffer-process buffer)
           (setq buffer (generate-new-buffer (buffer-name buffer))))
         (setq detached-enabled nil)
-        (funcall #'async-shell-command (detached-dtach-command 
detached--current-session t) buffer)
+        (funcall #'async-shell-command command buffer)
         (with-current-buffer buffer (setq detached--buffer-session 
detached--current-session))))))
 
 (defun detached-session-candidates (sessions)
@@ -753,19 +752,64 @@ This function uses the `notifications' library."
   (let* ((detached--current-session session)
          (detached-session-mode 'attach)
          (inhibit-message t))
-    (if (not (detached--session-attachable session))
-        (detached-view-session session)
-      (cl-letf* (((symbol-function #'set-process-sentinel) #'ignore)
-                 (buffer (get-buffer-create detached--shell-command-buffer))
-                 (default-directory (detached--session-working-directory 
session))
-                 (dtach-command (detached-dtach-command session t)))
-        (when (get-buffer-process buffer)
-          (setq buffer (generate-new-buffer (buffer-name buffer))))
-        (funcall #'async-shell-command dtach-command buffer)
-        (with-current-buffer buffer (setq detached--buffer-session 
detached--current-session))))))
+    (cl-letf* (((symbol-function #'set-process-sentinel) #'ignore)
+               (buffer (get-buffer-create detached--shell-command-buffer))
+               (default-directory (detached--session-working-directory 
session))
+               (command (detached--shell-command session t)))
+      (when (get-buffer-process buffer)
+        (setq buffer (generate-new-buffer (buffer-name buffer))))
+      (funcall #'async-shell-command command buffer)
+      (with-current-buffer buffer (setq detached--buffer-session 
detached--current-session)))))
 
 ;;;;; Other
 
+(cl-defgeneric detached--shell-command (entity &optional concat)
+  "Return shell command for ENTITY optionally CONCAT.")
+
+(cl-defmethod detached--shell-command ((command string) &optional concat)
+  "Return shell command for COMMAND.
+
+Optionally CONCAT the command return command into a string."
+  (detached--shell-command (detached-create-session command) concat))
+
+(cl-defmethod detached--shell-command ((session detached-session) &optional 
concat)
+  "Return shell command for SESSION.
+
+Optionally CONCAT the command return command into a string."
+  (if (detached--session-attachable session)
+      (detached-dtach-command session concat)
+    (detached-tail-command session concat)))
+
+(cl-defgeneric detached-tail-command (entity &optional concat)
+  "Return tail command for ENTITY optionally CONCAT.")
+
+(cl-defmethod detached-tail-command ((command string) &optional concat)
+  "Return tail command for COMMAND.
+
+Optionally CONCAT the command return command into a string."
+  (detached-tail-command (detached-create-session command) concat))
+
+(cl-defmethod detached-tail-command ((session detached-session) &optional 
concat)
+  "Return tail command for SESSION.
+
+Optionally CONCAT the command return command into a string."
+  (detached-connection-local-variables
+   (let* ((log (detached--session-file session 'log t))
+          (tail-command `("tail" "--follow=name" "--retry" "--lines=50" ,log)))
+     (cond ((eq 'create detached-session-mode)
+            (detached-dtach-command session))
+           ((eq 'create-and-attach detached-session-mode)
+            (let ((detached-session-mode 'create)
+                  (detached--current-session session))
+              (detached-start-session (detached--session-command session))
+              (if concat
+                  (mapconcat #'identity tail-command " ")
+                tail-command)))
+           ((eq 'attach detached-session-mode)
+            (if concat
+                (mapconcat #'identity tail-command " ")
+              tail-command))))))
+
 (cl-defgeneric detached-dtach-command (entity &optional concat)
   "Return dtach command for ENTITY optionally CONCAT.")
 
@@ -1396,8 +1440,6 @@ If event is cased by an update to the `detached' 
database, re-initialize
 (defvar detached-log-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd detached-detach-key) #'detached-detach-session)
-    ;; TODO(Niklas Eklund, 20220530): Add refresh command (g), good
-    ;; for manual tailing
     map)
   "Keymap for `detached-log-mode'.")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]