|
4 | 4 |
|
5 | 5 | ;; Author: Alvaro Ramirez https://xenodium.com |
6 | 6 | ;; URL: https://github.com/xenodium/chatgpt-shell |
7 | | -;; Version: 2.29.1 |
| 7 | +;; Version: 2.30.1 |
8 | 8 | ;; Package-Requires: ((emacs "28.1") (shell-maker "0.81.1") (transient "0.9.3")) |
9 | | -(defconst chatgpt-shell--version "2.29.1") |
| 9 | +(defconst chatgpt-shell--version "2.30.1") |
10 | 10 |
|
11 | 11 | ;; This package is free software; you can redistribute it and/or modify |
12 | 12 | ;; it under the terms of the GNU General Public License as published by |
@@ -180,6 +180,13 @@ For example: |
180 | 180 | :type 'hook |
181 | 181 | :group 'shell-maker) |
182 | 182 |
|
| 183 | +(defcustom chatgpt-shell-show-model-icons t |
| 184 | + "When non-nil display model image icons. |
| 185 | +
|
| 186 | +For example, when swapping models." |
| 187 | + :type 'boolean |
| 188 | + :group 'chatgpt-shell) |
| 189 | + |
183 | 190 | (defvaralias 'chatgpt-shell-swap-model-version 'chatgpt-shell-swap-model) |
184 | 191 |
|
185 | 192 | (defvaralias 'chatgpt-shell-display-function 'shell-maker-display-function) |
@@ -588,7 +595,17 @@ non-nil; otherwise `completing-read'." |
588 | 595 | chatgpt-shell-models) |
589 | 596 | width)) |
590 | 597 | (models (seq-map (lambda (model) |
591 | | - (format (format "%%-%ds %%s" width) |
| 598 | + (format (format "%%s%%-%ds %%s" width) |
| 599 | + (if-let* ((show-icon chatgpt-shell-show-model-icons) |
| 600 | + (icon (map-elt model :icon)) |
| 601 | + (icon-filename (chatgpt-shell--fetch-model-icon icon))) |
| 602 | + (with-temp-buffer |
| 603 | + (insert-image (create-image icon-filename nil nil |
| 604 | + :ascent 'center |
| 605 | + :height (frame-char-height))) |
| 606 | + (insert " ") |
| 607 | + (buffer-string)) |
| 608 | + "") |
592 | 609 | (map-elt model :provider) |
593 | 610 | (map-elt model :version))) |
594 | 611 | (if chatgpt-shell-swap-model-filter |
@@ -2991,6 +3008,37 @@ Write solutions in their entirety.") |
2991 | 3008 | (set-mark (map-elt block 'end)) |
2992 | 3009 | (goto-char (map-elt block 'start)))) |
2993 | 3010 |
|
| 3011 | +(defun chatgpt-shell--fetch-model-icon (icon) |
| 3012 | + "Download ICON filename from GitHub, only if it exists and save as binary. |
| 3013 | +
|
| 3014 | +ICON names can be found at https://github.com/lobehub/lobe-icons/tree/master/packages/static-png |
| 3015 | +
|
| 3016 | +ICONs starting with https:// are downloaded directly from that location." |
| 3017 | + (when icon |
| 3018 | + (let* ((mode (if (eq (frame-parameter nil 'background-mode) 'dark) "dark" "light")) |
| 3019 | + (url (if (string-prefix-p "https://" (downcase icon)) |
| 3020 | + icon |
| 3021 | + (concat "https://raw.githubusercontent.com/lobehub/lobe-icons/refs/heads/master/packages/static-png/" |
| 3022 | + mode "/" icon))) |
| 3023 | + (filename (file-name-nondirectory url)) |
| 3024 | + (cache-dir (file-name-concat (temporary-file-directory) "chatgpt-shell" mode)) |
| 3025 | + (cache-path (expand-file-name filename cache-dir))) |
| 3026 | + (unless (file-exists-p cache-path) |
| 3027 | + (make-directory cache-dir t) |
| 3028 | + (let ((buffer (url-retrieve-synchronously url t t 5.0))) |
| 3029 | + (when buffer |
| 3030 | + (with-current-buffer buffer |
| 3031 | + (goto-char (point-min)) |
| 3032 | + (if (re-search-forward "^HTTP/1.1 200 OK" nil t) |
| 3033 | + (progn |
| 3034 | + (re-search-forward "\r?\n\r?\n") |
| 3035 | + (let ((coding-system-for-write 'no-conversion)) |
| 3036 | + (write-region (point) (point-max) cache-path))) |
| 3037 | + (message "Icon fetch failed: %s" url))) |
| 3038 | + (kill-buffer buffer)))) |
| 3039 | + (when (file-exists-p cache-path) |
| 3040 | + cache-path)))) |
| 3041 | + |
2994 | 3042 | ;; pretty smerge start |
2995 | 3043 |
|
2996 | 3044 | (cl-defun chatgpt-shell--pretty-smerge-insert (&key text start end buffer iterate) |
|
0 commit comments