[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Eshell output filter
From: |
Benjamín Buccianti |
Subject: |
Eshell output filter |
Date: |
Sun, 20 Sep 2020 16:26:00 -0300 |
Hello there!
I've encountered a problem with eshell and apk (package manager of Alpine
Linux).
When running an update, I see some chars that I think are used to delete the
line (behaviour that you can see on any terminal emulator).
For example:
```
~ $ doas apk -U upgrade
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
%1b7 0% %1b8OK: 3694 MiB in 819
packages
```
The expected outcome it's to see only this:
```
~ $ doas apk -U upgrade
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
OK: 3694 MiB in 819 packages
```
I think we don't see the 0% because it occurs really fast. But in some cases,
you can see the progress of the bar changing from 0% to 100%. I think ^[8 it's
used to erase the line because in other cases you can see output like this:
```
~ $ doas apk add emacs
(1/2) Installing emacs-nox (27.1-r1)
%1b7 0% %1b8%1b7 97%
########################################### %1b8%1b7 98%
########################################### %1b8%1b7 99%
########################################### %1b8(2/2) Installing emacs (27.1-r1)
%1b7 99% ########################################### %1b8%1b7100%
############################################%1b8Executing
busybox-1.32.0-r3.trigger
Executing gtk-update-icon-cache-2.24.32-r2.trigger
OK: 3802 MiB in 821 packages
```
(output reduced for the sake of understanding, but you can see the whole
sequence)
So, I figured out that eshell uses a eshell-handle-control-codes to detect
control codes.
This is a proposed alternative but I'm not really that well versed on emacs and
on terminal control codes so, I post here with the intention of see what you
guys think and with the desire of improve with your help.
diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el
index db5fddb2aa..ed5c864eda 100644
--- a/lisp/eshell/esh-mode.el
+++ b/lisp/eshell/esh-mode.el
@@ -999,6 +999,14 @@ eshell-handle-control-codes
(beep))
((eq char ?\C-h)
(delete-region (1- (point)) (1+ (point))))
+ ((and (eq char ?\)
+ (memq (char-after (1+ (point)))
+ '(?\8)))
+ (let ((end (1+ (point))))
+ (beginning-of-line)
+ (delete-region (point) end)
+ (delete-char 1))
+ (forward-char))
(t
(forward-char)))))))
Thanks!
- Eshell output filter,
Benjamín Buccianti <=