commit 51541d1e6597cba730f8d316e50479797e7c99d0 parent 9c419d795de8b087d353edfb0f7c61bffccad1fa Author: Tomas Hlavaty <tom@logand.com> Date: Sat, 27 Feb 2021 22:23:21 +0100 view pdf and videos as graphics on the console under suspended emacs Diffstat:
M | emacs-framebuffer.el | | | 31 | ++++++++++++++++++++++++++++++- |
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -652,6 +652,34 @@ (call-process "convert" nil nil nil "-rotate" "180" f f)) (framebuffer-image-mode-draw-image (current-buffer))) +(defun framebuffer-fbpdf (filename) + (suspend-emacs + (format "fbpdf -w %s; fg" + (shell-quote-argument (expand-file-name filename))))) + +(defun framebuffer-hh:mm:ss (sec) + (etypecase sec + (string sec) + (integer + (let* ((m (mod sec 3600)) + (s (mod m 60))) + (format "%d:%02d:%02d" (floor position 3600) (floor (- m s) 60) s))))) + +(defun framebuffer-fbmpv (filename &optional position) + (suspend-emacs + (format "mpv --vo=drm --osd-level=3 %s%s %s; fg" + (if position "--start=" "") + (if position (framebuffer-hh:mm:ss position) "") + (shell-quote-argument (expand-file-name filename))))) + +(defun framebuffer-fbview () + (interactive) + (let* ((filename (dired-file-name-at-point)) + (x (file-name-extension filename))) + (cond + ((member x '("pdf")) (framebuffer-fbpdf filename)) + ((member x '("mkv" "mp4" "ogg" "webm")) (framebuffer-fbmpv filename))))) + (add-hook 'framebuffer-image-mode-hook (lambda () @@ -691,7 +719,8 @@ (with-eval-after-load 'dired (define-key dired-mode-map "I" 'framebuffer-image-file-dired) (define-key dired-mode-map "N" 'framebuffer-image-file-dired-next) - (define-key dired-mode-map "P" 'framebuffer-image-file-dired-previous))) + (define-key dired-mode-map "P" 'framebuffer-image-file-dired-previous) + (define-key dired-mode-map "V" 'framebuffer-fbview))) (defun framebuffer-draw-test () (interactive)