git.fiddlerwoaroof.com
Browse code

feat: use zenburn for color theme, reload cl+ssl at startup

Ed Langley authored on 09/04/2020 20:51:21
Showing 3 changed files
... ...
@@ -28,6 +28,7 @@
28 28
                                (:file "utils")
29 29
                                (:file "capi-utils")
30 30
                                (:file "pprint-setup")
31
+                               (:file "editor-color-theme")
31 32
                                (:file "store")
32 33
                                (:file "aws-dispatcher")
33 34
                                (:file "aws-utils")
... ...
@@ -178,6 +178,7 @@
178 178
                                                              'capi:destroy interface))))))
179 179
 
180 180
 (defun run (&optional accounts)
181
+  (cl+ssl:reload)
181 182
   (setf *print-readably* nil
182 183
         *accounts* (reprocess-accounts (load-accounts accounts))
183 184
         aws:*session* (mfa-tool.credential-provider:make-aws-session))
... ...
@@ -206,6 +207,7 @@
206 207
   (abort))
207 208
 
208 209
 (defun main ()
210
+  (mfa-tool.editor-color-theme:color-theme "zenburn" nil)
209 211
   (mfa-tool.credential-provider:setup-default-chain)
210 212
   (mfa-tool.pprint-setup:setup-pprint)
211 213
   (setf *debugger-hook* 'debugging)
212 214
new file mode 100644
... ...
@@ -0,0 +1,441 @@
1
+(cl:in-package #:cl-user)
2
+
3
+(defpackage #:mfa-tool.editor-color-theme
4
+  (:use #:cl)
5
+  (:export #:all-color-themes
6
+           #:color-theme-args
7
+           #:color-theme
8
+           #:define-color-theme
9
+           #:remove-color-theme
10
+           #:zenburn-paren-colors))
11
+
12
+(in-package #:mfa-tool.editor-color-theme)
13
+
14
+;;; Configuration
15
+
16
+(defvar *foreground-color* nil)
17
+
18
+(defvar *background-color* nil)
19
+
20
+(defconstant +default-parenthesis-font-face-colours+ '(:red :black :darkgreen :darkorange3 :blue :purple))
21
+
22
+;;; Implementation
23
+
24
+(defvar *all-color-themes* (make-hash-table :test 'string=))
25
+
26
+(defun all-color-themes ()
27
+  (loop for key being the hash-keys in *all-color-themes*
28
+        collect key))
29
+
30
+(defun color-theme-data (theme-name)
31
+  (multiple-value-bind (color-theme-data found?)
32
+      (gethash theme-name *all-color-themes*)
33
+    (if found?
34
+        color-theme-data
35
+        (error "No color theme named ~s found." theme-name))))
36
+
37
+(defun color-theme-super-theme-names (theme-name)
38
+  (first (color-theme-data theme-name)))
39
+
40
+(defun color-theme-args (theme-name)
41
+  (rest (color-theme-data theme-name)))
42
+
43
+(defvar *all-editor-panes* (make-hash-table :test 'eq
44
+                                            :weak-kind :key))
45
+
46
+(defun update-editor-pane (pane)
47
+  (setf (capi:simple-pane-foreground pane) (or *foreground-color* :color_windowtext))
48
+  (setf (capi:simple-pane-background pane) (or *background-color* :color_window))
49
+
50
+  (let ((recolorize-p (editor::buffer-font-lock-mode-p (capi:editor-pane-buffer pane))))
51
+    (when recolorize-p
52
+      (gp:invalidate-rectangle pane)))
53
+  (values))
54
+
55
+(defun update-editor-panes ()
56
+  (maphash #'(lambda (pane value)
57
+               (declare (ignore value))
58
+               (update-editor-pane pane))
59
+           *all-editor-panes*)
60
+  (values))
61
+
62
+(defvar *editor-face-names*
63
+  '(:region
64
+    :show-point-face
65
+    :interactive-input-face
66
+    :highlight
67
+    :non-focus-complete-face
68
+    :font-lock-function-name-face
69
+    :font-lock-comment-face
70
+    :font-lock-type-face
71
+    :font-lock-variable-name-face
72
+    :font-lock-string-face
73
+    :font-lock-keyword-face
74
+    :font-lock-builtin-face
75
+    :compiler-note-highlight
76
+    :compiler-warning-highlight
77
+    :compiler-error-highlight
78
+    ))
79
+
80
+(defun set-color-theme (theme-name)
81
+  (destructuring-bind (&rest color-theme-args
82
+                       &key foreground background &allow-other-keys)
83
+      (color-theme-args theme-name)
84
+
85
+    (setf *foreground-color* (or foreground :color_windowtext))
86
+    (setf *background-color* (or background :color_window))
87
+
88
+    (lw:when-let (parenthesis-colors
89
+                  (getf color-theme-args :parenthesis-font-face-colours
90
+                        +default-parenthesis-font-face-colours+))
91
+      (editor::set-parenthesis-colours parenthesis-colors))
92
+
93
+    (dolist (name *editor-face-names*)
94
+      (let* ((color-theme-args-for-face (getf color-theme-args name))
95
+             (face-name (intern (string name) '#:editor))
96
+             (face (editor:make-face face-name :if-exists t)))
97
+        (apply 'editor:make-face face-name :if-exists :overwrite
98
+                                           :documentation (or (getf color-theme-args-for-face :documentation)
99
+                                                              (slot-value face 'documentation))
100
+                                           color-theme-args-for-face))))
101
+
102
+  theme-name)
103
+
104
+(defun color-theme (theme-name)
105
+  (mapc 'set-color-theme (color-theme-super-theme-names theme-name))
106
+  (set-color-theme theme-name)
107
+
108
+  (update-editor-panes)
109
+
110
+  theme-name)
111
+
112
+(defun define-color-theme (theme-name super-theme-names
113
+                           &rest color-theme-args &key &allow-other-keys)
114
+  (dolist (super-theme-name super-theme-names)
115
+    (multiple-value-bind (color-theme-data found?)
116
+        (gethash super-theme-name *all-color-themes*)
117
+      (declare (ignore color-theme-data))
118
+      (unless found?
119
+        (warn "Inherited color theme ~s not defined." super-theme-name))))
120
+
121
+  (setf (gethash theme-name *all-color-themes*) (list* super-theme-names color-theme-args))
122
+
123
+  theme-name)
124
+
125
+(defun remove-color-theme (theme-name)
126
+  (remhash theme-name *all-color-themes*))
127
+
128
+(sys::without-warning-on-redefinition
129
+  (defmethod initialize-instance :around ((pane capi:editor-pane) &key &allow-other-keys)
130
+    (multiple-value-prog1
131
+        (call-next-method)
132
+
133
+      (setf (gethash pane *all-editor-panes*) pane)
134
+
135
+      (when *foreground-color*
136
+        (setf (capi:simple-pane-foreground pane) *foreground-color*))
137
+      (when *background-color*
138
+        (setf (capi:simple-pane-background pane) *background-color*))))
139
+  )
140
+
141
+;; This makes it "work" after the podium is launched
142
+(defun is-editor-pane-p (obj)
143
+  (and (typep obj 'capi:editor-pane)
144
+       (not (eq obj (hcl:class-prototype (class-of obj))))))
145
+
146
+(defun cache-existing-pane (pane)
147
+  (setf (gethash pane *all-editor-panes*) pane))
148
+
149
+(defun cache-if-pane (obj)
150
+  (when (is-editor-pane-p obj)
151
+    (cache-existing-pane obj)))
152
+
153
+#+:lispworks-personal-edition
154
+(hcl:sweep-all-objects #'cache-if-pane)
155
+
156
+
157
+;;; Initial color themes
158
+
159
+(define-color-theme "default" ()
160
+  :foreground nil :background nil
161
+  :region '(:foreground :color_highlighttext
162
+            :background :color_highlight)
163
+  :show-point-face '(:background :green)
164
+  :interactive-input-face '(:foreground :red3)
165
+  :highlight '(:bold-p t)
166
+  :non-focus-complete-face '(:background :tweak_background)
167
+  :font-lock-function-name-face '(:foreground :blue)
168
+  :font-lock-comment-face '(:foreground :firebrick)
169
+  :font-lock-type-face '(:foreground :forestgreen)
170
+  :font-lock-variable-name-face '(:foreground :darkgoldenrod)
171
+  :font-lock-string-face '(:foreground :rosybrown)
172
+  :font-lock-keyword-face '(:foreground :purple)
173
+  :font-lock-builtin-face '(:foreground :orchid)
174
+  :compiler-note-highlight '(:foreground :magenta)
175
+  :compiler-warning-highlight '(:foreground :orange3)
176
+  :compiler-error-highlight '(:foreground :red))
177
+
178
+(define-color-theme "plain" ()
179
+  :foreground nil :background nil
180
+  :region '(:foreground :color_highlighttext
181
+            :background :color_highlight)
182
+  :show-point-face '()
183
+  :interactive-input-face '()
184
+  :highlight '(:bold-p t)
185
+  :non-focus-complete-face '(:background :tweak_background)
186
+  :font-lock-function-name-face '()
187
+  :font-lock-comment-face '()
188
+  :font-lock-type-face '()
189
+  :font-lock-variable-name-face '()
190
+  :font-lock-string-face '()
191
+  :font-lock-keyword-face '()
192
+  :font-lock-builtin-face '()
193
+  :compiler-note-highlight '()
194
+  :compiler-warning-highlight '()
195
+  :compiler-error-highlight '())
196
+
197
+(define-color-theme "emacs" ()
198
+  :foreground nil :background nil
199
+  :region '(:foreground :color_highlighttext
200
+            :background :color_highlight)
201
+  :show-point-face '(:background :green)
202
+  :interactive-input-face '(:foreground :red3)
203
+  :highlight '(:bold-p t)
204
+  :non-focus-complete-face '(:background :tweak_background)
205
+  :font-lock-function-name-face '(:foreground :blue)
206
+  :font-lock-comment-face '(:foreground :gray40)
207
+  :font-lock-type-face '(:foreground :forestgreen)
208
+  :font-lock-variable-name-face '(:foreground :darkgoldenrod)
209
+  :font-lock-string-face '(:foreground :rosybrown)
210
+  :font-lock-keyword-face '(:foreground :purple)
211
+  :font-lock-builtin-face '(:foreground :orchid)
212
+  :compiler-note-highlight '(:foreground :magenta)
213
+  :compiler-warning-highlight '(:foreground :orange3)
214
+  :compiler-error-highlight '(:foreground :red))
215
+
216
+(define-color-theme "torte" ()
217
+  :foreground (color:make-rgb 0.8s0 0.8s0 0.8s0)
218
+  :background (color:make-rgb 0.0s0 0.0s0 0.0s0)
219
+  :region '(:foreground :color_highlighttext
220
+            :background :color_highlight)
221
+  :show-point-face `(:background ,(color:make-rgb 0.6275s0 0.1255s0 0.9412s0))
222
+  :interactive-input-face '(:foreground :pink)
223
+  :highlight '(:bold-p t)
224
+  :non-focus-complete-face '(:background :tweak_background)
225
+  :font-lock-function-name-face `(:foreground ,(color:make-rgb 0.0s0 1.0s0 1.0s0))
226
+  :font-lock-comment-face `(:foreground ,(color:make-rgb 0.5s0 0.6275s0 1.0s0))
227
+  :font-lock-type-face `(:foreground ,(color:make-rgb 0.5s0 1.0s0 0.5s0))
228
+  :font-lock-variable-name-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 1.0s0))
229
+  :font-lock-string-face `(:foreground ,(color:make-rgb 1.0s0 0.6275s0 0.6275s0))
230
+  :font-lock-keyword-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0))
231
+  :font-lock-builtin-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0))
232
+  :compiler-note-highlight '(:foreground :magenta)
233
+  :compiler-warning-highlight '(:foreground :orange)
234
+  :compiler-error-highlight '(:foreground :red))
235
+
236
+
237
+(defun make-rgb (red green blue &optional alpha)
238
+  (color:make-rgb (/ red 255s0)
239
+                  (/ green 255s0)
240
+                  (/ blue 255s0)
241
+                  (and alpha (/ alpha 255s0))))
242
+
243
+(defvar *solarized-color-table*
244
+  '(:solarized-base03  (#x00 #x2b #x36)
245
+    :solarized-base02  (#x07 #x36 #x42)
246
+    :solarized-base01  (#x58 #x6e #x75)
247
+    :solarized-base00  (#x65 #x7b #x83)
248
+    :solarized-base0   (#x83 #x94 #x96)
249
+    :solarized-base1   (#x93 #xa1 #xa1)
250
+    :solarized-base2   (#xee #xe8 #xd5)
251
+    :solarized-base3   (#xfd #xf6 #xe3)
252
+    :solarized-yellow  (#xb5 #x89 #x00)
253
+    :solarized-orange  (#xcb #x4b #x16)
254
+    :solarized-red     (#xdc #x32 #x2f)
255
+    :solarized-magenta (#xd3 #x36 #x82)
256
+    :solarized-violet  (#x6c #x71 #xc4)
257
+    :solarized-blue    (#x26 #x8b #xd2)
258
+    :solarized-cyan    (#x2a #xa1 #x98)
259
+    :solarized-green   (#x85 #x99 #x00)))
260
+
261
+(loop for list on *solarized-color-table* by #'cddr
262
+      for name = (first list)
263
+      for rgb = (second list)
264
+      do
265
+         (color:define-color-alias
266
+             name
267
+             (apply #'make-rgb rgb)))
268
+
269
+(define-color-theme "solarized-light" ()
270
+  :foreground :solarized-base00
271
+  :background :solarized-base3
272
+  :region '(:foreground :solarized-base1
273
+            :background :solarized-base3
274
+            :inverse-p t)
275
+  :highlight '(:background :solarized-base2)
276
+  :font-lock-function-name-face '(:foreground :solarized-blue)
277
+  :font-lock-comment-face '(:foreground :solarized-base1 :italic-p t)
278
+  :font-lock-type-face '(:foreground :solarized-yellow)
279
+  :font-lock-variable-name-face '(:foreground :solarized-blue)
280
+  :font-lock-string-face '(:foreground :solarized-cyan)
281
+  :font-lock-keyword-face '(:foreground :solarized-green)
282
+  :font-lock-builtin-face '(:foreground :solarized-green)
283
+  :compiler-note-highlight '(:foreground :solarized-green
284
+                             :bold-p t)
285
+  :compiler-warning-highlight '(:foreground :solarized-orange
286
+                                :bold-p t)
287
+  :compiler-error-highlight '(:foreground :solarized-red
288
+                              :inverse-p t)
289
+  :show-point-face '(:foreground :solarized-cyan
290
+                     :bold-p t :inverse-p t)
291
+  :interactive-input-face '(:foreground :solarized-red)
292
+  :non-focus-complete-face '(:background :solarized-base3)
293
+  :parenthesis-font-face-colours '(:solarized-red
294
+                                   :solarized-base01
295
+                                   :solarized-green
296
+                                   :solarized-orange
297
+                                   :solarized-blue
298
+                                   :solarized-magenta))
299
+
300
+(define-color-theme "solarized-dark" ()
301
+  :foreground :solarized-base0
302
+  :background :solarized-base03
303
+  :region '(:foreground :solarized-base01
304
+            :background :solarized-base03
305
+            :inverse-p t)
306
+  :highlight '(:background :solarized-base02)
307
+  :font-lock-function-name-face '(:foreground :solarized-blue)
308
+  :font-lock-comment-face '(:foreground :solarized-base01 :italic-p t)
309
+  :font-lock-type-face '(:foreground :solarized-yellow)
310
+  :font-lock-variable-name-face '(:foreground :solarized-blue)
311
+  :font-lock-string-face '(:foreground :solarized-cyan)
312
+  :font-lock-keyword-face '(:foreground :solarized-green)
313
+  :font-lock-builtin-face '(:foreground :solarized-green)
314
+  :compiler-note-highlight '(:foreground :solarized-green
315
+                             :bold-p t)
316
+  :compiler-warning-highlight '(:foreground :solarized-orange
317
+                                :bold-p t)
318
+  :compiler-error-highlight '(:foreground :solarized-red
319
+                              :inverse-p t)
320
+  :show-point-face '(:foreground :solarized-cyan
321
+                     :bold-p t :inverse-p t)
322
+  :interactive-input-face '(:foreground :solarized-red)
323
+  :non-focus-complete-face '(:background :solarized-base03)
324
+  :parenthesis-font-face-colours '(:solarized-red
325
+                                   :solarized-base1
326
+                                   :solarized-green
327
+                                   :solarized-orange
328
+                                   :solarized-blue
329
+                                   :solarized-magenta))
330
+
331
+(eval-when (:compile-toplevel :load-toplevel :execute)
332
+  (defun hex->color (hex)
333
+    (declare (optimize (speed 3) (safety 1) (debug 1)))
334
+    (check-type hex (string 7))
335
+    (flet ((extract-digits (string start end)
336
+             (check-type string (simple-string 7))
337
+             (parse-integer string
338
+                            :start start
339
+                            :end end
340
+                            :radix 16)))
341
+      (let* ((hex (coerce hex 'simple-string))
342
+             (r (extract-digits hex 1 3))
343
+             (g (extract-digits hex 3 5))
344
+             (b (extract-digits hex 5 7)))
345
+        (color:make-rgb (/ r 255.0)
346
+                        (/ g 255.0)
347
+                        (/ b 255.0))))))
348
+
349
+(eval-when (:compile-toplevel :load-toplevel :execute)
350
+  (defparameter +zenburn-colors+
351
+    `((zenburn-fg+2 ,(hex->color "#FFFFEF"))
352
+      (zenburn-fg+1 ,(hex->color "#F5F5D6"))
353
+      (zenburn-fg ,(hex->color "#DCDCCC"))
354
+      (zenburn-fg-1 ,(hex->color "#A6A689"))
355
+      (zenburn-fg-2 ,(hex->color "#656555"))
356
+      (zenburn-black ,(hex->color "#000000"))
357
+      (zenburn-bg-2 ,(hex->color "#000000"))
358
+      (zenburn-bg-1 ,(hex->color "#111112"))
359
+      (zenburn-bg-05 ,(hex->color "#383838"))
360
+      (zenburn-bg ,(hex->color "#2A2B2E"))
361
+      (zenburn-bg+05 ,(hex->color "#494949"))
362
+      (zenburn-bg+1 ,(hex->color "#4F4F4F"))
363
+      (zenburn-bg+2 ,(hex->color "#5F5F5F"))
364
+      (zenburn-bg+3 ,(hex->color "#6F6F6F"))
365
+      (zenburn-red+2 ,(hex->color "#ECB3B3"))
366
+      (zenburn-red+1 ,(hex->color "#DCA3A3"))
367
+      (zenburn-red ,(hex->color "#CC9393"))
368
+      (zenburn-red-1 ,(hex->color "#BC8383"))
369
+      (zenburn-red-2 ,(hex->color "#AC7373"))
370
+      (zenburn-red-3 ,(hex->color "#9C6363"))
371
+      (zenburn-red-4 ,(hex->color "#8C5353"))
372
+      (zenburn-red-5 ,(hex->color "#7C4343"))
373
+      (zenburn-red-6 ,(hex->color "#6C3333"))
374
+      (zenburn-orange ,(hex->color "#DFAF8F"))
375
+      (zenburn-yellow ,(hex->color "#F0DFAF"))
376
+      (zenburn-yellow-1 ,(hex->color "#E0CF9F"))
377
+      (zenburn-yellow-2 ,(hex->color "#D0BF8F"))
378
+      (zenburn-green-5 ,(hex->color "#2F4F2F"))
379
+      (zenburn-green-4 ,(hex->color "#3F5F3F"))
380
+      (zenburn-green-3 ,(hex->color "#4F6F4F"))
381
+      (zenburn-green-2 ,(hex->color "#5F7F5F"))
382
+      (zenburn-green-1 ,(hex->color "#6F8F6F"))
383
+      (zenburn-green ,(hex->color "#7F9F7F"))
384
+      (zenburn-green+1 ,(hex->color "#8FB28F"))
385
+      (zenburn-green+2 ,(hex->color "#9FC59F"))
386
+      (zenburn-green+3 ,(hex->color "#AFD8AF"))
387
+      (zenburn-green+4 ,(hex->color "#BFEBBF"))
388
+      (zenburn-cyan ,(hex->color "#93E0E3"))
389
+      (zenburn-blue+3 ,(hex->color "#BDE0F3"))
390
+      (zenburn-blue+2 ,(hex->color "#ACE0E3"))
391
+      (zenburn-blue+1 ,(hex->color "#94BFF3"))
392
+      (zenburn-blue ,(hex->color "#8CD0D3"))
393
+      (zenburn-blue-1 ,(hex->color "#7CB8BB"))
394
+      (zenburn-blue-2 ,(hex->color "#6CA0A3"))
395
+      (zenburn-blue-3 ,(hex->color "#5C888B"))
396
+      (zenburn-blue-4 ,(hex->color "#4C7073"))
397
+      (zenburn-blue-5 ,(hex->color "#366060"))
398
+      (zenburn-magenta ,(hex->color "#DC8CC3")))))
399
+
400
+(defmacro with-zenburn-colors (&body body)
401
+  `(let ,+zenburn-colors+
402
+     (declare (ignorable ,@(mapcar 'car +zenburn-colors+)))
403
+     ,@body))
404
+
405
+(with-zenburn-colors
406
+  (define-color-theme "zenburn" ()
407
+    :foreground zenburn-fg
408
+    :background zenburn-bg
409
+    :region `(:foreground ,zenburn-fg+1
410
+              :background ,zenburn-bg+1)
411
+    :show-point-face `(:background ,zenburn-bg+2)
412
+    :interactive-input-face `(:foreground ,zenburn-red)
413
+    :highlight '(:bold-p t)
414
+    :non-focus-complete-face `(:background :tweak_background)
415
+    :font-lock-function-name-face `(:foreground ,zenburn-blue)
416
+    :font-lock-comment-face `(:foreground ,zenburn-fg-1)
417
+    :font-lock-type-face `(:foreground ,zenburn-green)
418
+    :font-lock-variable-name-face `(:foreground ,zenburn-yellow)
419
+    :font-lock-string-face `(:foreground ,zenburn-orange)
420
+    :font-lock-keyword-face `(:foreground ,zenburn-cyan)
421
+    :font-lock-builtin-face `(:foreground ,zenburn-blue+1)
422
+    :compiler-note-highlight `(:foreground ,zenburn-fg+1)
423
+    :compiler-warning-highlight `(:foreground ,zenburn-orange)
424
+    :compiler-error-highlight `(:foreground ,zenburn-red+1)))
425
+
426
+(defun zenburn-paren-colors ()
427
+  (with-zenburn-colors
428
+    (capi:set-editor-parenthesis-colors
429
+     (list zenburn-red
430
+           zenburn-green
431
+           zenburn-blue-1
432
+           zenburn-green+1
433
+           zenburn-blue+1
434
+           zenburn-green+2
435
+           zenburn-orange
436
+           zenburn-cyan
437
+           zenburn-magenta
438
+           zenburn-yellow))))
439
+
440
+;;; Show presence when loaded
441
+(pushnew :editor-color-theme *features*)