branch: elpa/gptel
commit 447d5cedd1862a45d8b821ceec04f61d6e2b4bd3
Author: Allen Li <[email protected]>
Commit: Karthik Chikmagalur <[email protected]>

    gptel: Use string-pixel-width only on graphic display
    
    When right aligning text for use in gptel's banners,
    string-pixel-width returns the string-width on non-graphic
    displays.  This means we need the +1/+5 offset so it doesn't
    overflow.  Fix #1406.
    
    * gptel-rewrite.el (gptel--rewrite-update-wait):
    * gptel.el (gptel--header-line-info):
---
 gptel-rewrite.el | 3 ++-
 gptel.el         | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gptel-rewrite.el b/gptel-rewrite.el
index 12e0c30735..b3ad5be694 100644
--- a/gptel-rewrite.el
+++ b/gptel-rewrite.el
@@ -216,7 +216,8 @@ which see."
            (propertize " Waiting..." 'face '(warning default)) ;status element 
1
            (propertize                                         ;status element 
2
             " " 'display
-            (if (fboundp 'string-pixel-width)
+            (if (and (fboundp 'string-pixel-width)
+                     (display-graphic-p))
                 `(space :align-to (- right (,(string-pixel-width hint-str))))
               `(space :align-to (- right ,(+ 1 (string-width hint-str))))))
            (propertize hint-str 'face '(warning default)))) ;status element 3
diff --git a/gptel.el b/gptel.el
index d7463d0542..e51b366562 100644
--- a/gptel.el
+++ b/gptel.el
@@ -933,7 +933,8 @@ Search between BEG and END."
         (concat
          (propertize
           " " 'display
-          (if (fboundp 'string-pixel-width)
+          (if (and (fboundp 'string-pixel-width)
+                   (display-graphic-p))
               `(space :align-to (- right (,(string-pixel-width rhs))))
             `(space :align-to (- right ,(+ 5 (string-width rhs))))))
          rhs))))

Reply via email to