diff options
| author | cashmeredev <cashmeresocial@paranoici.org> | 2026-03-17 11:53:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-17 11:53:37 +0100 |
| commit | 73c3a7eb5d65ec81cc2f43d4a9413544c7e538c6 (patch) | |
| tree | ed5020f3441870f83068790d1b82e1e82c009cde | |
| parent | f18cebbe766a5ccedebf4c07ae9a6f731a926a8d (diff) | |
| parent | 6c0a8bc0a7a25421671dd08c2ffb0115cb09255e (diff) | |
| download | kitty-graphics-73c3a7eb5d65ec81cc2f43d4a9413544c7e538c6.tar.gz | |
Merge pull request #3 from Lenbok/agent-shell-support
feat: support images in agent-shell sessions
| -rw-r--r-- | kitty-graphics.el | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/kitty-graphics.el b/kitty-graphics.el index c4047d4..098de48 100644 --- a/kitty-graphics.el +++ b/kitty-graphics.el @@ -63,6 +63,7 @@ (defvar org-format-latex-options) (declare-function org-combine-plists "org-macs" (&rest plists)) (defvar image-mode-map) +(declare-function markdown-overlays--resolve-image-url "markdown-overlays" (url)) ;;;; Customization @@ -1445,6 +1446,44 @@ Registers `kitty-image' dispatcher and prepends it to the dispatcher list." (assq-delete-all 'kitty-image dirvish--available-preview-dispatchers))) (fmakunbound 'dirvish-kitty-image-dp)) +;;;; markdown-overlays integration (agent-shell) + +(defun kitty-gfx--markdown-overlays-fontify-image-advice (orig-fn start end url-start url-end) + "Around advice for `markdown-overlays--fontify-image'. +Displays markdown images  via Kitty graphics in terminal. +Falls back to ORIG-FN in GUI." + (if (and kitty-graphics-mode (not (display-graphic-p))) + (when-let* ((url (buffer-substring-no-properties url-start url-end)) + (path (markdown-overlays--resolve-image-url url)) + ((file-exists-p path)) + ((kitty-gfx--image-file-p path))) + (kitty-gfx--log "markdown-overlays-image: %s" path) + (condition-case err + (kitty-gfx-display-image + path start end + kitty-gfx-max-width kitty-gfx-max-height) + (error + (kitty-gfx--log "markdown-overlays-image error: %s" (error-message-string err))))) + (funcall orig-fn start end url-start url-end))) + +(defun kitty-gfx--markdown-overlays-fontify-image-file-path-advice (orig-fn start end path-start path-end) + "Around advice for `markdown-overlays--fontify-image-file-path'. +Displays bare image file paths via Kitty graphics in terminal. +Falls back to ORIG-FN in GUI." + (if (and kitty-graphics-mode (not (display-graphic-p))) + (when-let* ((raw (buffer-substring-no-properties path-start path-end)) + (path (markdown-overlays--resolve-image-url raw)) + ((file-exists-p path)) + ((kitty-gfx--image-file-p path))) + (kitty-gfx--log "markdown-overlays-path: %s" path) + (condition-case err + (kitty-gfx-display-image + path start end + kitty-gfx-max-width kitty-gfx-max-height) + (error + (kitty-gfx--log "markdown-overlays-path error: %s" (error-message-string err))))) + (funcall orig-fn start end path-start path-end))) + ;;;; Integration install/uninstall (defun kitty-gfx--install-integrations () @@ -1485,6 +1524,11 @@ Registers `kitty-image' dispatcher and prepends it to the dispatcher list." #'kitty-gfx--doc-view-enlarge-advice) (advice-add 'doc-view-scale-reset :around #'kitty-gfx--doc-view-scale-reset-advice)) + (with-eval-after-load 'markdown-overlays + (advice-add 'markdown-overlays--fontify-image :around + #'kitty-gfx--markdown-overlays-fontify-image-advice) + (advice-add 'markdown-overlays--fontify-image-file-path :around + #'kitty-gfx--markdown-overlays-fontify-image-file-path-advice)) (kitty-gfx--install-dirvish)) (defun kitty-gfx--uninstall-integrations () @@ -1505,6 +1549,8 @@ Registers `kitty-image' dispatcher and prepends it to the dispatcher list." (advice-remove 'doc-view-scale-reset #'kitty-gfx--doc-view-scale-reset-advice) (advice-remove 'image-mode #'kitty-gfx--image-mode-advice) (advice-remove 'shr-put-image #'kitty-gfx--shr-put-image-advice) + (advice-remove 'markdown-overlays--fontify-image #'kitty-gfx--markdown-overlays-fontify-image-advice) + (advice-remove 'markdown-overlays--fontify-image-file-path #'kitty-gfx--markdown-overlays-fontify-image-file-path-advice) (kitty-gfx--uninstall-dirvish)) ;;;; Buffer cleanup |
