Refactor dashboard banner display & centering

This commit is contained in:
Henrik Lissner 2018-08-10 12:34:17 +02:00
parent 87c8f6e18e
commit e33cb446aa
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -12,13 +12,15 @@
dashboard. These functions take no arguments and the dashboard buffer is current dashboard. These functions take no arguments and the dashboard buffer is current
while they run.") while they run.")
;; (defvar +doom-dashboard-banner-file "e.png" (defvar +doom-dashboard-banner-file "default.png"
;; "The path to the image file to be used in on the dashboard. The path is "The path to the image file to be used in on the dashboard. The path is
;; relative to modules/ui/doom-dashboard/banners/. If nil, always use the ASCII relative to `+doom-dashboard-banner-dir'. If nil, always use the ASCII banner.")
;; banner.")
;; (defvar +doom-dashboard-banner-dir (concat (DIR!) "banners/") (defvar +doom-dashboard-banner-dir (concat (DIR!) "banners/")
;; "Where to look for `+doom-dashboard-banner-file'.") "Where to look for `+doom-dashboard-banner-file'.")
(defvar +doom-dashboard-banner-padding '(4 . 4)
"Number of newlines to pad the banner with, above and below, respectively.")
(defvar +doom-dashboard-inhibit-refresh nil (defvar +doom-dashboard-inhibit-refresh nil
"If non-nil, the doom buffer won't be refreshed.") "If non-nil, the doom buffer won't be refreshed.")
@ -88,7 +90,6 @@ PLIST can have the following properties:
;; ;;
(defvar +doom-dashboard--last-cwd nil) (defvar +doom-dashboard--last-cwd nil)
(defvar +doom-dashboard--width 80) (defvar +doom-dashboard--width 80)
(defvar +doom-dashboard--hoffset 2)
(defvar +doom-dashboard--old-fringe-indicator fringe-indicator-alist) (defvar +doom-dashboard--old-fringe-indicator fringe-indicator-alist)
(defvar +doom-dashboard--pwd-alist ()) (defvar +doom-dashboard--pwd-alist ())
@ -235,11 +236,10 @@ whose dimensions may not be fully initialized by the time this is run."
(point))) (point)))
(insert (make-string (insert (make-string
(max 0 (- (/ (window-height (get-buffer-window)) 2) (max 0 (- (/ (window-height (get-buffer-window)) 2)
(truncate (/ (+ (count-lines (point-min) (point-max)) (round (/ (+ (count-lines (point-min) (point-max))
+doom-dashboard--hoffset) (car +doom-dashboard-banner-padding))
2)))) 2))))
?\n) ?\n))))))))
"\n")))))))
(defun +doom-dashboard|detect-project (&rest _) (defun +doom-dashboard|detect-project (&rest _)
"Check for a `last-project-root' parameter in the perspective, and set the "Check for a `last-project-root' parameter in the perspective, and set the
@ -300,7 +300,6 @@ controlled by `+doom-dashboard-pwd-policy'."
(unless (eq major-mode '+doom-dashboard-mode) (unless (eq major-mode '+doom-dashboard-mode)
(+doom-dashboard-mode)) (+doom-dashboard-mode))
(erase-buffer) (erase-buffer)
(insert "\n")
(run-hooks '+doom-dashboard-functions))) (run-hooks '+doom-dashboard-functions)))
(+doom-dashboard|resize) (+doom-dashboard|resize)
(+doom-dashboard|detect-project) (+doom-dashboard|detect-project)
@ -365,22 +364,21 @@ controlled by `+doom-dashboard-pwd-policy'."
"==' _-' E M A C S \\/ `==" "==' _-' E M A C S \\/ `=="
"\\ _-' `-_ /" "\\ _-' `-_ /"
" `'' ``'")) " `'' ``'"))
;; TODO Add Doom logo (when (and (stringp +doom-dashboard-banner-file)
;; (when (and +doom-dashboard-banner-file (display-graphic-p)) (display-graphic-p)
;; (let* ((image (create-image (expand-file-name +doom-dashboard-banner-file (file-exists-p! +doom-dashboard-banner-file +doom-dashboard-banner-dir))
;; +doom-dashboard-banner-dir) (let* ((image (create-image (expand-file-name +doom-dashboard-banner-file
;; 'png nil)) +doom-dashboard-banner-dir)
;; (size (image-size image)) 'png nil))
;; (margin (+ 1 (/ (- +doom-dashboard--width (car size)) 2)))) (size (image-size image nil))
;; (setq +doom-dashboard--hoffset (- (cdr size) 2)) (margin (+ 1 (/ (- +doom-dashboard--width (car size)) 2))))
;; (add-text-properties (add-text-properties
;; point (point) `(display ,image rear-nonsticky (display))) point (point) `(display ,image rear-nonsticky (display)))
;; (when (> margin 0) (when (> margin 0)
;; (save-excursion (save-excursion
;; (goto-char point) (goto-char point)
;; (insert (make-string (truncate margin) ? ))))) (insert (make-string (truncate margin) ? )))))
;; (insert "\n\n\n\n")) (insert (make-string (or (cdr +doom-dashboard-banner-padding) 0) ?\n)))))
))
(defun doom-dashboard-widget-loaded () (defun doom-dashboard-widget-loaded ()
(insert (insert