summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-09-02 10:06:14 +0300
committerThanos Apollo <[email protected]>2024-09-02 10:42:23 +0300
commit02a4e1352025e023d4345cd7dd71ae063d396538 (patch)
treeb43ee1a8d0c04c154f527a89e732ea3882206544 /gnosis.el
parent1e8e5fc529ad7dd1f1ca0fb8988cd309e3e24bd8 (diff)
[fix] display-images: Display images only on graphical envs.
* Fix issues for running gnosis on tty & termux.
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el28
1 files changed, 15 insertions, 13 deletions
diff --git a/gnosis.el b/gnosis.el
index caef741..db5a6f4 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -484,19 +484,21 @@ or =extra-image'. Instead of using =extra-image' post review, prefer
=gnosis-display-extra' which displays the =extra-image' as well.
Refer to =gnosis-db-schema-extras' for informations on images stored."
- (let* ((img (gnosis-get image 'extras `(= id ,id)))
- (path-to-image (expand-file-name (or img "") (file-name-as-directory gnosis-images-dir)))
- (image (create-image path-to-image 'png nil :width gnosis-image-width :height gnosis-image-height))
- (image-width (car (image-size image t)))
- (frame-width (window-text-width))) ;; Width of the current window in columns
- (cond ((or (not img) (string-empty-p img))
- (insert "\n\n"))
- ((and img (file-exists-p path-to-image))
- (let* ((padding-cols (/ (- frame-width (floor (/ image-width (frame-char-width)))) 2))
- (padding (make-string (max 0 padding-cols) ?\s)))
- (insert "\n\n" padding) ;; Insert padding before the image
- (insert-image image)
- (insert "\n\n"))))))
+ ;; Only display images on graphical env
+ (when (display-graphic-p)
+ (let* ((img (gnosis-get image 'extras `(= id ,id)))
+ (path-to-image (expand-file-name (or img "") (file-name-as-directory gnosis-images-dir)))
+ (image (create-image path-to-image 'png nil :width gnosis-image-width :height gnosis-image-height))
+ (image-width (car (image-size image t)))
+ (frame-width (window-text-width))) ;; Width of the current window in columns
+ (cond ((or (not img) (string-empty-p img))
+ (insert "\n\n"))
+ ((and img (file-exists-p path-to-image))
+ (let* ((padding-cols (/ (- frame-width (floor (/ image-width (frame-char-width)))) 2))
+ (padding (make-string (max 0 padding-cols) ?\s)))
+ (insert "\n\n" padding) ;; Insert padding before the image
+ (insert-image image)
+ (insert "\n\n")))))))
(defun gnosis-display-mcq-options (id)
"Display answer options for mcq note ID."