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

Handling carriage return (\r) by justl-exec-recipe #20

Closed
BlankSpruce opened this issue Jun 29, 2022 · 2 comments
Closed

Handling carriage return (\r) by justl-exec-recipe #20

BlankSpruce opened this issue Jun 29, 2022 · 2 comments

Comments

@BlankSpruce
Copy link
Contributor

BlankSpruce commented Jun 29, 2022

Consider the following justfile:

foo:
    #!/bin/bash
    printf "1/5\r"
    sleep 1
    printf "2/5\r"
    sleep 1
    printf "3/5\r"
    sleep 1
    printf "4/5\r"
    sleep 1
    printf "5/5\n"
    sleep 1
    printf "DONE\n"

Consider the outcome of invoking recipe foo in these different approaches:

  • in terminal (in this example zsh opened in vterm):
    image
  • when you invoke M-x compile with just --justfile /tmp/foo/justfile foo:
-*- mode: compilation; default-directory: "/tmp/foo/" -*-
Compilation started at Wed Jun 29 17:24:08

just --justfile /tmp/foo/justfile foo
5/5
DONE

Compilation finished at Wed Jun 29 17:24:13
  • when you invoke justl-exec-eshell on recipe foo
Welcome to the Emacs shell

/tmp/foo $ just foo
5/5
DONE
/tmp/foo $ 
  • when you invoke justl-exec-recipe on recipe foo:
Just target execution started at Wed Jun 29 17:26:59 

1/5^M2/5^M3/5^M4/5^M5/5
DONE

Target execution finished at Wed Jun 29 17:27:04

As far as I understand the filter used with subprocess handling output of just doesn't handle carriage return in special way that's way justl-exec-recipe behaves differently. If you however do the following change:

diff --git a/justl.el b/justl.el
index 89b4dd8..b7694ee 100644
--- a/justl.el
+++ b/justl.el
@@ -349,7 +349,7 @@ ARGS is a plist that affects how the process is run.
 
         (setq-local justl--justfile (justl--justfile-from-arg (elt command 1)))
         (run-hook-with-args 'compilation-start-hook process)
-        (set-process-filter process 'justl--xterm-color-filter)
+        (set-process-filter process 'compilation-filter)
         (set-process-sentinel process sentinel)
         (set-process-coding-system process 'utf-8-emacs-unix 'utf-8-emacs-unix)
         (pop-to-buffer buf)))))

it'll work as other ways to invoke recipe, namely it'll produce:

Just target execution started at Wed Jun 29 17:26:59 

5/5
DONE

Target execution finished at Wed Jun 29 17:27:04

Is there a good reason to not use compilation-filter? If you are worried about handling coloring of the output it can be done with
(add-hook 'compilation-filter-hook 'ansi-color-compilation-filter).

Special handling of carriage return so that the previously printed line is erased makes sense in a lot of practical applications, for instance with recipes invoking rsync --progress.

@psibi
Copy link
Owner

psibi commented Jun 29, 2022

Is there a good reason to not use compilation-filter? If you are worried about handling coloring of the output it can be done with
(add-hook 'compilation-filter-hook 'ansi-color-compilation-filter).

Yeah, you're right. I believe we can drop the whole xterm-color dependency itself. Can you send a PR for the same ?

@BlankSpruce
Copy link
Contributor Author

Here it is #21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants