3

GitHub - Hugo-Heagren/svg-battery-indicator: Simple battery indicator

 1 year ago
source link: https://github.com/Hugo-Heagren/svg-battery-indicator
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

svg-battery-indicator.el

This is a simple package for generating an SVG battery indicator for us in the mode-line or tab-bar. It’s not on MELPA or Gnu Elpa, so you’ll have to install it manually, or using a GitHub helper like straight. See the top right of the screen-shot below:

./svg-battery-indicator.jpg

This package requires Emacs to be built with SVG support. You can test this by running (image-type-available-p 'svg). If you get t, you have SVG support.

Usage

The indicator takes advantage of display-battery-mode (and the battery.el library generally). It uses advice to add an extra expando to battery-mode-line-format. To use, add svg-battery-indicator-status-advice as :filter-return advice to battery-status-function (whatever battery-status-function is on your machine). The expando %i will then be available in battery-mode-line-format, and expands to an a battery SVG.

You might have something like this in your init.el:

(advice-add
 ;; NOTE that `battery-status-function' is UNQUOTED. It's a variable,
 ;; which battery.el requires to point at a function, with a return
 ;; value which `svg-battery-indicator-status-advice' can handle.
 battery-status-function
 :filter-return
 #'svg-battery-indicator-status-advice)

(display-battery-mode)

(setq battery-mode-line-format "%p%% %i")

;; To display in the mode-line
(add-to-list 'mode-line-format
	       'battery-mode-line-string)

;; To display in the tab-bar
(add-to-list 'tab-bar-format
	       'battery-mode-line-string)

Customization

The variable svg-battery-indicator-length sets the length of the indicator. Otherwise all customization is through battery.el. The indicator uses the threshholds set in battery-load-low and battery-load-critical, and represents them with the foreground colours from the faces battery-load-low and battery-load-critical.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK