GithubHelp home page GithubHelp logo

justinhj / battery.nvim Goto Github PK

View Code? Open in Web Editor NEW
49.0 49.0 7.0 86 KB

Neovim plugin to detect and view battery information

License: MIT License

Lua 93.96% Makefile 4.59% Vim Script 1.45%
lua neovim vim

battery.nvim's People

Contributors

david-0609 avatar justinhj avatar softinio avatar yoginalex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

battery.nvim's Issues

Support charging battery icons

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)

ACPI shows average battery power when mouse with battery added

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.
battery info

The solution I found is quite simple, but I can't possible say it solves all cases.

No support for Linux

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.

Test suite

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.

Optional customization option for advanced users - format string

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.

Realtime battery handling

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...

  1. Plugin requires a binary built for the platform (similar to how an lsp server may work)
  2. The client launches the binary and listens to messages from it
  3. On battery change message it updates the battery_status

Handle multiple batteries - Windows/Powershell

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.

Show charge remaining time

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.

Handle multiple batteries - pmset (Mac OS)

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.

Support horizontal battery icons

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)

Weird error in Linux.

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.