-
Notifications
You must be signed in to change notification settings - Fork 5
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
Translate ANSI characters #16
Comments
Update with (let ((process (uiop:launch-program "foo.sh" :output :stream :error-output :output)))
(labels ((decode-process-output-to-stream (process output-stream)
(alex:when-let ((line (read-line (uiop:process-info-output process) nil nil)))
(setf line (string-right-trim '(#\return) line))
(write-string
(sera:ensure-suffix
(reduce (lambda (&optional string char)
(match char
(#\backspace
(subseq string 0 (max 0 (1- (length string)))))
(#\return
"")
(char (str:concat string (string char)))))
line
:initial-value "")
(string #\newline))
output-stream)
(decode-process-output-to-stream process output-stream))))
(decode-process-output-to-stream process t))) |
I think that stripping out special characters is a great idea. Do you think it would be worth having a mode like |
Sorry, I'm not familiar with `less - R`, what do you mean?
Anyways, true that I didn't take coloring into account in this draft,
although I'm not completely sure how prevalent it is considering that
_well-behaved_ command line programs are supposed to check if they write
to a PTY, and if not, disable ANSI coloring.
That said, the same could be said about progress bars and all kind of
input rewriting, but in practice it's not always done.
So... Yes, it's a good idea! There are some CL libs for ANSI coloring
out there (like https://github.com/raydeejay/ansi-color), we can use it
as a test bed.
|
Should I send a patch? |
Please do. |
I won't have time to send this before a while, so if anyone feels like
giving it a shot, please go ahead :)
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many shell commands leverage the terminal processing of special characters like
^H
(backspace) and^M
(newline) to perform some special formatting, like rewriting text in place.This is often seen when a progress bar is displayed by the command. Try
rsync
,wget
,curl
, your package manager...Running these commands in a Lisp REPL often makes for pages of garbage output, making them practically un-runnable.
An easy way around this is to ask
uiop:launch-program
to write the output to a stream, then to process the stream for special characters.Here is an example that processes
^H
and^M
:with
foo.sh
:It would be super useful to integrate this to CMD. I suggest adding a dynamic variable where the user could specify the output translators. When NIL, no translation would happen.
Thoughts?
The text was updated successfully, but these errors were encountered: