Skip to content

Commit 7c3fa5b

Browse files
committed
Add ghostel-default face for per-buffer default fg/bg customization
Previously, ghostel--apply-palette always read default foreground/background from the global 'default face, making it impossible to theme ghostel terminal buffers independently (e.g. dark terminal inside a light Emacs) without resorting to defadvice. Introduce 'ghostel-default' (inherits 'default) as the customization point, following the same idiom as vterm-color-default, term-default-fg-color, etc. Existing users see no change; those who want per-buffer theming can customize the face directly. Closes #178
1 parent 064cbe9 commit 7c3fa5b

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,17 @@ ghostel-color-white ghostel-color-bright-white
556556
Themes that customize `term-color-*` faces automatically apply. Customize
557557
individual faces with `M-x customize-face`.
558558

559+
Default foreground/background are read from the `ghostel-default` face,
560+
which inherits from `default`. Customize it to give ghostel terminals
561+
different default colors than the rest of Emacs (e.g. a dark terminal
562+
inside a light Emacs):
563+
564+
```elisp
565+
(set-face-attribute 'ghostel-default nil
566+
:foreground "#cdd6f4"
567+
:background "#1e1e2e")
568+
```
569+
559570
## Configuration
560571

561572
| Variable | Default | Description |

lisp/ghostel.el

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,6 +2323,13 @@ file:// URL does not match the local machine, construct a TRAMP path."
23232323

23242324
;;; Palette
23252325

2326+
(defface ghostel-default
2327+
'((t :inherit default))
2328+
"Base face used to derive ghostel terminal default fg/bg colors.
2329+
Customize this to give ghostel buffers different default colors than
2330+
the rest of Emacs (e.g. a dark terminal inside a light Emacs)."
2331+
:group 'ghostel)
2332+
23262333
(defun ghostel--face-hex-color (face attr)
23272334
"Extract hex color string from FACE's ATTR (:foreground or :background).
23282335
Falls back to \"#000000\" if the color cannot be resolved."
@@ -2343,8 +2350,8 @@ Falls back to \"#000000\" if the color cannot be resolved."
23432350
(when term
23442351
(ghostel--set-default-colors
23452352
term
2346-
(ghostel--face-hex-color 'default :foreground)
2347-
(ghostel--face-hex-color 'default :background))
2353+
(ghostel--face-hex-color 'ghostel-default :foreground)
2354+
(ghostel--face-hex-color 'ghostel-default :background))
23482355
(when ghostel-color-palette
23492356
(let ((colors
23502357
(mapconcat

test/ghostel-test.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4934,6 +4934,22 @@ rendered by `ghostel--delayed-redraw'. This is the exact real-world path."
49344934
(should-not default-colors-calls)
49354935
(should-not palette-calls))))
49364936

4937+
(ert-deftest ghostel-test-apply-palette-ghostel-default-face ()
4938+
"`ghostel--apply-palette' reads default fg/bg from `ghostel-default', not `default'."
4939+
(let ((looked-up nil))
4940+
(cl-letf (((symbol-function 'ghostel--set-default-colors) #'ignore)
4941+
((symbol-function 'ghostel--set-palette) #'ignore)
4942+
((symbol-function 'ghostel--face-hex-color)
4943+
(lambda (face _attr)
4944+
(push face looked-up)
4945+
"#000000")))
4946+
(ghostel--apply-palette 'fake-term)
4947+
;; The two default-color lookups must target `ghostel-default',
4948+
;; never `default' directly — otherwise buffer-local customization
4949+
;; of the terminal's fg/bg is impossible (issue #178).
4950+
(should (memq 'ghostel-default looked-up))
4951+
(should-not (memq 'default looked-up)))))
4952+
49374953
;; -----------------------------------------------------------------------
49384954
;; OSC 51 elisp eval
49394955
;; -----------------------------------------------------------------------
@@ -7201,6 +7217,7 @@ while :; do sleep 0.1; done'\n")
72017217
ghostel-test-prompt-navigation
72027218
ghostel-test-sync-theme
72037219
ghostel-test-apply-palette-default-colors
7220+
ghostel-test-apply-palette-ghostel-default-face
72047221
ghostel-test-osc51-eval
72057222
ghostel-test-osc51-eval-unknown
72067223
ghostel-test-osc51-eval-catches-errors

0 commit comments

Comments
 (0)