justinhj / battery.nvim Goto Github PK
View Code? Open in Web Editor NEWNeovim plugin to detect and view battery information
License: MIT License
Neovim plugin to detect and view battery information
License: MIT License
It's possible to get the estimated time remaining. For example with pmset the output is...
> pmset -g ps
Now drawing from 'Battery Power'
-InternalBattery-0 (id=6094947) 94%; discharging; 7:08 remaining present: true
Although the code doesn't currently do it, you could parse the 7:08 remaining part and store it in the battery_status structure. This opens up the user to be able to display it on the statusline (although it may be a bit long).
"At some point" it may be possible to mouse hover the battery icon and display the time remaining in a tip.
Currently there are no tests.
Create a test suite, preferably using plenary test in idiomatic style. It should test things like config options create the correct status line given various inputs.
For a stretch goal create a mock process to interact with and simulate errors and timeouts.
Should there be two percent(%) signs when showing percentage?
I have tried installing acpid
on WSL, but it doesn't seem to work. I know there are files in /sys/class/power_supply/
which supply all the data that the plugin needs. Is there a reason why the plugin depends on acpi
instead of using these files? (Someone mentioned in #1 that these files are supplied by the Linux kernel, so they should work for all distributions). I think this is a more sensible default than requiring acpi
as a dependency.
(lua/battery/health/health.lua
line 8)
Possible implementation:
In the select_job
function, set M.method
to a string representing the method used to collect information (nil
if none of them work), so that in the health module, you could do something like
local method = require("battery.battery").method
if method then
ok("Battery info retrieval method: " .. method)
else
error("No battery info retrieval method")
end
In battery.lua you will find
local charging_battery_icons
For this task add user configuration option to toggle the use of icons that have the charging symbol on them when the AC power is connected.
The structure is a list of icons and the max power required to show that icon. You can check the vertical icon handling code to see how to implement for other icons.
local function discharging_battery_icon_for_percent(p)
My config is:
lua << EOF local nvimbattery = { function() return require("battery").get_status_line() end } EOF lua << EOF require('lualine').setup { options = { theme = "catppuccin", icons_enabled = true }, sections = { lualine_a = {'mode'}, lualine_b = {'branch', 'diff', 'diagnostics'}, lualine_c = {'filename'}, lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'location'}, lualine_z = {nvimbattery, 'ctime'} } } EOF
And I have acpi installed in Linux, but I get this weird error everytime:
`
Error executing vim.schedule lua callback: ...k/.local/share/nvim/plugged/lualine.
nvim/lua/lualine.lua:432: Error executing lua: .../nvim/plugged/lualine.nvim/lua/l
ualine/utils/section.lua:38: attempt to get length of a nil value
stack traceback:
.../nvim/plugged/lualine.nvim/lua/lualine/utils/section.lua:38: in functio
n 'draw_section'
...k/.local/share/nvim/plugged/lualine.nvim/lua/lualine.lua:173: in functi
on 'statusline'
...k/.local/share/nvim/plugged/lualine.nvim/lua/lualine.lua:301: in functi
on <...k/.local/share/nvim/plugged/lualine.nvim/lua/lualine.lua:282>
[C]: in function 'nvim_win_call'
...k/.local/share/nvim/plugged/lualine.nvim/lua/lualine.lua:432: in functi
on 'refresh'
...k/.local/share/nvim/plugged/lualine.nvim/lua/lualine.lua:356: in functi
on <...k/.local/share/nvim/plugged/lualine.nvim/lua/lualine.lua:355>
stack traceback:
[C]: in function 'nvim_win_call'
...k/.local/share/nvim/plugged/lualine.nvim/lua/lualine.lua:432: in functi
on 'refresh'
`
Any ideas about what's happening?
Battery info on windows is retrieved using Powershell as follows
local get_battery_info_powershell_command = {
"Get-CimInstance -ClassName Win32_Battery | Select-Object -Property EstimatedChargeRemaining,BatteryStatus",
}
Implement multiple battery support as already exists for linux/acpi.
from :help health-dev
:
For example if your plugin is named "foo", define your healthcheck module at
one of these locations (on 'runtimepath'):
- lua/foo/health/init.lua
- lua/foo/health.lua
Currently, it is defined in lua/battery/health/health.lua
This means that in :checkhealth
there is .health
twice
battery.health: require("battery.health.health").check()
^^^^^^^
When using Termux, there is a plugin called Termux:API which provides the termux-battery-status
command. The output is in JSON format, and contains information on the battery percentage, status, and whether it is plugged in.
Example output:
{
"health": "GOOD",
"percentage": 96,
"plugged": "PLUGGED_AC",
"status": "CHARGING",
"temperature": 24.600000381469727,
"current": -252
}
One problem with termux-battery-status
is that it is very slow, so it should probably be tried last
In battery.lua you will find
local sideways_battery_icons
For this task add user configuration option to toggle horizontal and vertical icons, and show the horizontal ones when selected.
The structure is a list of icons and the max power required to show that icon. You can check the vertical icon handling code to see how to implement for other icons.
local function discharging_battery_icon_for_percent(p)
I think it's very necessary, as I have several devices that shows in acpi
and, in the current situation, ends up breaking the percentage.
as the image shows, it should be 56%, but shows 28%.
In this case, the first one is my notebook battery, and the last one is my mouse.
The solution I found is quite simple, but I can't possible say it solves all cases.
Currently the update is periodic. This is a big stretch goal to instead of polling the battery status by running a system process, instead communicate over RPC with a custom written executable (that is of course, cross platform), that can react to battery events such as percent changes and ac power connection (even battery insert and remove).
Roughly it looks like this...
There is multiple battery support for linux (acpi) but not for Mac and Windows. This issue is to add support for Mac which uses pmset to get the battery information.
> pmset -g ps
Now drawing from 'Battery Power'
-InternalBattery-0 (id=7274595) 80%; discharging; 3:24 remaining present: true
The goal is to first determine what multiple battery output looks like in the pmset output above.
Then implement the multiple battery selection code that is used on linux.
replace 'kyazdani42/nvim-web-devicons' not exist more
Currently only Windows (via Powershell) and macOS (via pmset) are supported. Add support for Linux.
Acceptance Criteria
Should be as portable as possible. Should work without installing software IF possible.
For guidance start with the files powershell.lua and pmset.lua and modify for the Linux tool that works best.
The code that renders the status to a string is a simple sequence of nested if statements. It gets the job done but it doesn't scale well as more and more options are added, nor is it very configurable.
This task adds a config option "format_string". When set this overrides the other display related options and allows the user to configure the battery status exactly as they like.
For example "%Bh %C %P%%"
%Bh means battery icon and horizontal specifier
%C is show charging icon if power connected otherwise show disconnected, %c could be show when connected only
%P is text percentage
%% is the normal format specified for %%
What's nice about this approach is it is easier to customize and it can be used to express the options to make it backwards compatible.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.