Rework the splash screen to be minimal, and sassy

This commit is contained in:
TEC 2021-03-27 19:03:45 +08:00
parent 13d014f38b
commit 68530a28bf
Signed by: tec
GPG Key ID: 779591AFDB81F06C
3 changed files with 133 additions and 30 deletions

View File

@ -810,6 +810,16 @@ I'd like some slightly nicer default buffer names
(setq doom-fallback-buffer-name "► Doom"
+doom-dashboard-name "► Doom")
#+end_src
Lastly, the doom dashboard "useful commands" are no longer useful to me.
So, we'll disable them and then for a particularly /clean/ look disable
~hl-line-mode~ and hide the cursor.
#+begin_src emacs-lisp
(remove-hook '+doom-dashboard-functions #'doom-dashboard-widget-shortmenu)
(add-hook! '+doom-dashboard-functions (hl-line-mode -1))
(setq-hook! '+doom-dashboard-mode-hook evil-normal-state-cursor (list nil))
#+end_src
*** Some helper macros
There are a few handy macros added by doom, namely
- ~load!~ for loading external ~.el~ files relative to this one
@ -867,41 +877,34 @@ For example when I open my config file it the window will be titled =config.org
doom= then as soon as I make a change it will become =config.org ◉ doom=.
*** Splash screen
Emacs can render an image as the splash screen, and [[https://github.com/MarioRicalde][@MarioRicalde]] came up with a
cracker! He's also provided me with a nice Emacs-style /E/, which is good for
smaller windows. *@MarioRicalde* you have my sincere thanks, you're great!
[[file:misc/splash-images/blackhole-lines.svg]]
cracker! He's also provided me with a nice Emacs-style /E/. I was using the
blackhole image, but as I've stripped down the splash screen I've switched to
just using the /E/.
#+attr_latex: :width 0.2\linewidth
#+attr_html: :style width:20% :alt Fancy Emacs "E"
[[file:misc/splash-images/emacs-e.svg]]
Now we just make it theme-appropriate, and resize with the frame.
By incrementally stripping away the outer layers of the logo one can obtain
quite a nice resizing effect.
#+begin_src emacs-lisp
(defvar fancy-splash-image-template
(expand-file-name "misc/splash-images/blackhole-lines-template.svg" doom-private-dir)
(expand-file-name "misc/splash-images/emacs-e-template.svg" doom-private-dir)
"Default template svg used for the splash image, with substitutions from ")
(defvar fancy-splash-image-nil
(expand-file-name "misc/splash-images/transparent-pixel.png" doom-private-dir)
"An image to use at minimum size, usually a transparent pixel")
(setq fancy-splash-sizes
`((:height 500 :min-height 50 :padding (0 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-0.svg" doom-private-dir))
(:height 440 :min-height 42 :padding (1 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-0.svg" doom-private-dir))
(:height 400 :min-height 38 :padding (1 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-1.svg" doom-private-dir))
(:height 350 :min-height 36 :padding (1 . 3) :template ,(expand-file-name "misc/splash-images/blackhole-lines-2.svg" doom-private-dir))
(:height 300 :min-height 34 :padding (1 . 3) :template ,(expand-file-name "misc/splash-images/blackhole-lines-3.svg" doom-private-dir))
(:height 250 :min-height 32 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/blackhole-lines-4.svg" doom-private-dir))
(:height 200 :min-height 30 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/blackhole-lines-5.svg" doom-private-dir))
(:height 100 :min-height 24 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/emacs-e-template.svg" doom-private-dir))
(:height 0 :min-height 0 :padding (0 . 0) :file ,fancy-splash-image-nil)))
(defvar fancy-splash-sizes
`((:height 500 :min-height 50 :padding (0 . 2))
(:height 440 :min-height 42 :padding (1 . 4))
(:height 330 :min-height 35 :padding (1 . 3))
(:height 200 :min-height 30 :padding (1 . 2))
(:height 0 :min-height 0 :padding (0 . 0) :file ,fancy-splash-image-nil))
`((:height 300 :min-height 50 :padding (0 . 2))
(:height 250 :min-height 42 :padding (2 . 4))
(:height 200 :min-height 35 :padding (3 . 3))
(:height 150 :min-height 28 :padding (3 . 3))
(:height 100 :min-height 20 :padding (2 . 2))
(:height 75 :min-height 15 :padding (2 . 1))
(:height 50 :min-height 10 :padding (1 . 0))
(:height 1 :min-height 0 :padding (0 . 0)))
"list of plists with the following properties
:height the height of the image
:min-height minimum `frame-height' for image
:padding `+doom-dashboard-banner-padding' to apply
:padding `+doom-dashboard-banner-padding' (top . bottom) to apply
:template non-default template file
:file file to use instead of template")
@ -942,8 +945,7 @@ quite a nice resizing effect.
"Perform `fancy-splash-generate-image' in bulk"
(dolist (size fancy-splash-sizes)
(unless (plist-get size :file)
(fancy-splash-generate-image (or (plist-get size :file)
(plist-get size :template)
(fancy-splash-generate-image (or (plist-get size :template)
fancy-splash-image-template)
(plist-get size :height)))))
@ -979,6 +981,103 @@ quite a nice resizing effect.
(add-hook 'doom-load-theme-hook #'set-appropriate-splash)
#+end_src
Now the only thing missing is a an extra interesting line, whether that be some
corporate BS, an developer excuse, or a fun (useless) fact.
The following is rather long, but it essentially
+ fetches a phrase from an API
+ inserts it into the dashboard (asynchronously)
+ moves ~point~ to the phrase
+ re-uses the last phrase for requests within a few seconds of it being fetched
#+begin_src emacs-lisp
(defvar phrase-api-url
(nth (random 3)
'(("https://corporatebs-generator.sameerkumar.website/" :phrase)
("https://useless-facts.sameerkumar.website/api" :data)
("https://dev-excuses-api.herokuapp.com/" :text))))
(defmacro phrase-generate-callback (token &optional format-fn ignore-read-only callback buffer-name)
`(lambda (status)
(unless (plist-get status :error)
(goto-char url-http-end-of-headers)
(let ((phrase (plist-get (json-parse-buffer :object-type 'plist) (cadr phrase-api-url)))
(inhibit-read-only ,(when (eval ignore-read-only) t)))
(setq phrase-last (cons phrase (float-time)))
(with-current-buffer ,(or (eval buffer-name) (buffer-name (current-buffer)))
(save-excursion
(goto-char (point-min))
(when (search-forward ,token nil t)
(with-silent-modifications
(replace-match "")
(insert ,(if format-fn format-fn 'phrase)))))
,callback)))))
(defvar phrase-last nil)
(defvar phrase-timeout 5)
(defmacro phrase-insert-async (&optional format-fn token ignore-read-only callback buffer-name)
`(let ((inhibit-message t))
(if (and phrase-last
(> phrase-timeout (- (float-time) (cdr phrase-last))))
(let ((phrase (car phrase-last)))
,(if format-fn format-fn 'phrase))
(url-retrieve (car phrase-api-url)
(phrase-generate-callback ,(or token "\ufeff") ,format-fn ,ignore-read-only ,callback ,buffer-name))
;; For reference, \ufeff = Zero-width no-break space / BOM
,(or token "\ufeff"))))
(defun doom-dashboard-phrase ()
(phrase-insert-async
(progn
(setq-local phrase-position (point))
(mapconcat
(lambda (line)
(+doom-dashboard--center
+doom-dashboard--width
(with-temp-buffer
(insert-text-button
line
'action
(lambda (_)
(setq phrase-last nil)
(+doom-dashboard-reload t))
'face 'doom-dashboard-menu-title
'mouse-face 'doom-dashboard-menu-title
'help-echo "Random phrase"
'follow-link t)
(buffer-string))))
(split-string
(with-temp-buffer
(insert phrase)
(setq fill-column (min 70 (/ (* 2 (window-width)) 3)))
(fill-region (point-min) (point-max))
(buffer-string))
"\n")
"\n"))
nil t
(progn
(goto-char phrase-position)
(forward-whitespace 1))
+doom-dashboard-name))
(defadvice! doom-dashboard-widget-loaded-with-phrase ()
:override #'doom-dashboard-widget-loaded
(setq line-spacing 0.2)
(insert
"\n\n"
(propertize
(+doom-dashboard--center
+doom-dashboard--width
(doom-display-benchmark-h 'return))
'face 'doom-dashboard-loaded)
"\n"
(doom-dashboard-phrase)
"\n"))
#+end_src
At the end, we have a minimal but rather nice splash screen.
#+attr_html: :class invertible :alt The splash screen, just loaded.
[[https://tecosaur.com/lfs/emacs-config/screenshots/splash-screen.png]]

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7645955045fc2b345fbfc31f768ff4cc784eb2e4c1a9fe0dbd74ee10ba7f50b1
size 47290
oid sha256:f9d7d6cdb50908ebd11113871d302c06530a9e89d993ff030f0e96ddbd1934e2
size 14293

View File

@ -0,0 +1,4 @@
<svg height="100" viewBox="0 0 86 107" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M 35.684432,2.414371 C 51.596051,6.4730319 61.046468,12.37858 63.185587,16.938833 65.790075,22.491175 58.1583,26.21135 40.2224,22.7325 30.956,20.9349 26.2183,22.203 24.6233,24.3817 17.569,34.0071 42.023,50.4654 53.3936,57.1938 -1.82031,43.4302 -27.0365,81.1662 44.5521,96.697 c 6.1236,1.3288 17.8718,1.8044 17.8415,3.568 -0.0034,1.896 -30.1831,2.054 -46.1025,2.54 10.858,2.904 36.9642,4.88 53.9391,3.271 16.4994,-1.561 23.7055,-7.1632 2.8966,-12.2828 C 62.3868,91.1525 20.2969,83.1695 24.7312,74.6638 31.2089,62.2426 59.2036,65.234 75.5142,63.5376 35.4138,35.97 26.316,29.4744 80.7341,36.5703 94.9709,39.7305 74.712649,16.562009 53.473749,6.8725691 48.485702,4.8931821 41.839525,3.3641875 35.684432,2.414371"
fill="#61afee" />
</svg>

After

Width:  |  Height:  |  Size: 834 B