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

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

[elpa] externals/dtache 7311bcaac8 09/14: Update dtache-env-mode impleme


From: ELPA Syncer
Subject: [elpa] externals/dtache 7311bcaac8 09/14: Update dtache-env-mode implementation
Date: Fri, 13 May 2022 11:57:48 -0400 (EDT)

branch: externals/dtache
commit 7311bcaac88260745cb79766641a6155189e8cb3
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Update dtache-env-mode implementation
---
 README.md           |  9 +++------
 dtache.el           | 21 +++++++++++----------
 test/dtache-test.el | 15 +++++++--------
 3 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/README.md b/README.md
index 601d817174..06b782fde5 100644
--- a/README.md
+++ b/README.md
@@ -325,7 +325,6 @@ Next add the annotation function to the 
`dtache-metadata-annotators-alist` toget
 To be able to both attach to a dtach session as well as logging its output 
`dtache` relies on the usage of `tee`. However it is possible that the user 
tries to run a command which involves a program that doesn't integrate well 
with tee. In those situations the output could be delayed until the session 
ends, which is not preferable.
 
 For these situations `dtache` provides the `dtache-nonattachable-commands` 
variable. This is a list of regular expressions. Any command that matches any 
of the strings will be getting the property `attachable` set to false.
-
 ``` emacs-lisp
 (setq dtache-nonattachable-commands '("^ls"))
 ```
@@ -334,14 +333,12 @@ Here a command beginning with `ls` would from now on be 
considered nonattachable
 
 ## Colors in sessions
 
-Many programs such as `git` or `grep` don't show colors in dtache unless they 
are forced to. This is because these commands only use colors and ansi 
sequences if they are being run in a terminal, as opposed to a pipe. This 
seting lets you get color output when you are running these programs 
interactively, while still getting readable output when you are piping them or 
redirecting them to a logfile. `Dtache` does not run programs in interactive 
terminal, though, so these commands turn off [...]
-
-*WARNING:* =Dtache= only supports a few basic escape sequences, so this fix 
/will/ mess up the output for some commands.
+Dtache needs to use a trick to get programs programs such as `git` or `grep` 
to show color in their outputs. This is because these commands only use colors 
and ansi sequences if they are being run in a terminal, as opposed to a pipe. 
The `dtache-env` therefore has two different modes. The mode can be either 
`plain-text` or `terminal-data`, the latter is now the default. The 
`dtache-env` program then uses the `script` command to make programs run in 
`dtache` think they are inside of a ful [...]
 
-First, put the following script into an executable file:
+The drawback is that there can be commands which generates escape sequences 
that `dtache` supports and will therefore mess up the output for some commands. 
If you detect such an incompatible command you can add a regexp that matches 
that command to the list `dtache-env-plain-text-commands`. By doing so `dtache` 
will instruct `dtache-env` to run those commands in plain-text mode.
 
 ``` emacs-lisp
-(setq dtache-env-smart-mode-block-list '(".*"))
+(setq dtache-env-plain-text-commands '(".*"))
 ```
 
 # Tips & Tricks
diff --git a/dtache.el b/dtache.el
index 236a95d14e..f4c0820d52 100644
--- a/dtache.el
+++ b/dtache.el
@@ -92,8 +92,8 @@
   :type 'string
   :group 'dtache)
 
-(defcustom dtache-env-smart-mode-block-list nil
-  "A list of regexps for commands that should be run in dumb mode in 
`dtache-env'."
+(defcustom dtache-env-plain-text-commands nil
+  "A list of regexps for commands to run in plain-text mode."
   :type 'list
   :group 'dtache)
 
@@ -181,7 +181,7 @@ Valid values are: create, new and attach")
 (defvar dtache-metadata-annotators-alist nil
   "An alist of annotators for metadata.")
 
-(defconst dtache-session-version "0.6.0"
+(defconst dtache-session-version "0.6.1"
   "The version of `dtache-session'.
 This version is encoded as [package-version].[revision].")
 
@@ -282,6 +282,7 @@ This version is encoded as [package-version].[revision].")
   (metadata nil :read-only t)
   (host nil :read-only t)
   (attachable nil :read-only t)
+  (env-mode nil :read-only t)
   (action nil :read-only t)
   (time nil)
   (status nil)
@@ -588,6 +589,7 @@ nil before closing."
                                   :size 0
                                   :directory (if dtache-local-session 
dtache-session-directory
                                                (concat (file-remote-p 
default-directory) dtache-session-directory))
+                                  :env-mode (dtache--env-mode command)
                                   :host (dtache--host)
                                   :metadata (dtache-metadata)
                                   :state 'unknown)))
@@ -1131,19 +1133,18 @@ If SESSION is nonattachable fallback to a command that 
doesn't rely on tee."
          (env (if dtache-env dtache-env (format "%s -c" dtache-shell-program)))
          (command
           (if dtache-env
-              (concat (format "%s " (dtache--env-mode (dtache--session-command 
session)))
+              (concat (format "%s " (dtache--session-env-mode session))
                       (shell-quote-argument (dtache--session-command session)))
             (shell-quote-argument (dtache--session-command session)))))
     (format "%s %s %s; %s %s" begin-shell-group env command end-shell-group 
redirect)))
 
 (defun dtache--env-mode (command)
   "Return mode to run in `dtache-env' based on COMMAND."
-  (if-let ((blocked-command
-            (seq-find (lambda (regexp)
-                        (string-match-p regexp command))
-                      dtache-env-smart-mode-block-list)))
-     'dumb
-    'smart))
+  (if (seq-find (lambda (regexp)
+                  (string-match-p regexp command))
+                dtache-env-plain-text-commands)
+      'plain-text
+    'terminal-data))
 
 (defun dtache--host ()
   "Return a cons with (host . type)."
diff --git a/test/dtache-test.el b/test/dtache-test.el
index e752e2b65c..ea7bc48e42 100644
--- a/test/dtache-test.el
+++ b/test/dtache-test.el
@@ -81,14 +81,14 @@
                         "-c" ,(dtache--session-file session 'socket t)
                         "-z" ,dtache-shell-program
                         "-c"
-                        ,(format "{ dtache-env smart ls\\ -la; } 2>&1 | tee %s"
+                        ,(format "{ dtache-env terminal-data ls\\ -la; } 2>&1 
| tee %s"
                                  (dtache--session-file session 'log t))))
             (expected-concat (format "%s -c %s -z %s -c %s"
                                      dtache-dtach-program
                                      (dtache--session-file session 'socket t)
                                      dtache-shell-program
                                      (shell-quote-argument
-                                      (format "{ dtache-env smart ls\\ -la; } 
2>&1 | tee %s"
+                                      (format "{ dtache-env terminal-data ls\\ 
-la; } 2>&1 | tee %s"
                                               (dtache--session-file session 
'log t))))))
        (should (equal expected (dtache-dtach-command session)))
        (should (equal expected-concat (dtache-dtach-command session t))))
@@ -226,21 +226,20 @@
                                                 :working-directory 
"/home/user/"
                                                 :command "ls -la"
                                                 :attachable t
+                                                :env-mode 'terminal-data
                                                 :id 'foo123))
         (nonattachable-session (dtache--session-create :directory 
"/tmp/dtache/"
                                                 :working-directory 
"/home/user/"
                                                 :command "ls -la"
                                                 :attachable nil
+                                                :env-mode 'plain-text
                                                 :id 'foo123)))
     ;; With dtache-env
     (let ((dtache-env "dtache-env"))
-      (should (string= "{ dtache-env smart ls\\ -la; } 2>&1 | tee 
/tmp/dtache/foo123.log"
+      (should (string= "{ dtache-env terminal-data ls\\ -la; } 2>&1 | tee 
/tmp/dtache/foo123.log"
                        (dtache--dtache-command attachable-session)))
-      (should (string= "{ dtache-env smart ls\\ -la; } &> 
/tmp/dtache/foo123.log"
-                       (dtache--dtache-command nonattachable-session)))
-      (let ((dtache-env-smart-mode-block-list '("ls -la")))
-        (should (string= "{ dtache-env dumb ls\\ -la; } 2>&1 | tee 
/tmp/dtache/foo123.log"
-                       (dtache--dtache-command attachable-session)))))
+      (should (string= "{ dtache-env plain-text ls\\ -la; } &> 
/tmp/dtache/foo123.log"
+                       (dtache--dtache-command nonattachable-session))))
 
     ;; Without dtache-env
     (let ((dtache-env nil)



reply via email to

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