;;; dashboard.el --- A grid-based dashboard -*- lexical-binding: t -*- ;; Author: Jakub ;; Maintainer: Jakub ;; Version: 1.0 ;; Package-Requires: (grid straight) ;; This file is not part of GNU Emacs ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; commentary ;;; Code: ;; For layout (require 'grid) (defvar enlight-theurgy-logo (propertize "\n\n\n\n ########### ##### ##### ##### #### ## ### #### ### ### ## ### ## ### ### ## ## ############### ## ### ## ### ### ## ### ## ##### ##### ## ## ## ## ## ## ## ### ### ### ### ## ### ##### # ### ### # ##### ############################# ### ### #### #### ##### ##### ########### " 'face 'font-lock-keyword-face)) (defvar enlight-calendar (progn (calendar) (prog1 (with-current-buffer (buffer-name (current-buffer)) (buffer-string)) (calendar-exit)))) (defun get-weather () "Get the weather JSON for THEURGY-CITY." (let ((buf (url-retrieve-synchronously (concat "https://wttr.in/" theurgy-city "?format=j1")))) (when buf (with-current-buffer buf ;; Skip HTTP headers (goto-char (point-min)) (re-search-forward "\n\n" nil 'move) (delete-region (point-min) (point)) ;; Now display it (switch-to-buffer buf) (buffer-string))))) (defun connected-p () "Are we connected to the host?" (= 0 (call-process-shell-command "ping -W 5 -c 2 wttr.in"))) (defun enlight-weather () (if (connected-p) (progn (let ((weather (aref (gethash "current_condition" (json-parse-string (get-weather) :object-type 'hash-table)) 0))) (concat (propertize "Weather\n\n" 'face 'font-lock-keyword-face) "Currently " (gethash "value" (aref (gethash "weatherDesc" weather) 0)) "\n" "It is " (gethash "temp_C" weather) " degrees, feels like " (gethash "FeelsLikeC" weather) "\n" "Wind speed is " (gethash "windspeedKmph" weather) "km/h\n"))) (concat (propertize "Weather\n\n" 'face 'font-lock-keyword-face) "No connection to weather service :("))) ;; Dashboard screen using enlight (use-package enlight :custom (enlight-content (concat (grid-get-box `(:align center :content ,enlight-theurgy-logo :width 80)) (grid-get-row (list (grid-get-box `(:content ,(concat (grid-get-box `( :content ,(concat (grid-get-box `( :content ,(propertize "Theurgy Emacs" 'face 'variable-pitch-serif-text) :width 80 :align center))) :width 80)) enlight-calendar "\n\n" (grid-get-row (list (grid-get-box `(:content ,(concat (enlight-menu '(("Exobrain" ("Agenda" (org-agenda nil "a") "a") ("Go to Inbox" open-inbox "i") ("Capture" org-capture "c"))))) :align left :width 20)) (grid-get-box `(:content ,(concat (enlight-menu '(("Projects" ("Switch To" theurgy-open-project "p") ("Project List" theurgy-edit-projects-list "l"))))) :align center :width 20)) (grid-get-box `(:content ,(concat (enlight-menu '(("Userland" ("Dired" (dired "~") "d") ("RSS" elfeed "r") ("Terminal" theurgy-bottom-shell "t") ("Weather" theurgy-show-weather "w"))))) :align center :width 20)) (grid-get-box `(:content ,(concat (enlight-menu '(("Meta" ("Elisp Scratch" open-elisp-scratch "s") ("Org Scratch" open-org-scratch "o") ("Init Dir" (dired user-emacs-directory) "e") ("Info" info "h"))))) :align right :width 20))))) )) )) ;(grid-get-box `(:content ,(enlight-weather) :align center)) ))) (setopt initial-buffer-choice #'enlight) (provide 'dashboard) ;;; dashboard.el ends here