Closed tbrsvn closed 1 month ago
Im loading battery.nvim in lualine like this:
lua << EOF
local batterycolor = "#ec9ca4"
local battery = require("battery")
battery.setup({
update_rate_seconds = 30, -- Number of seconds between checking battery status
show_status_when_no_battery = true, -- Don't show any icon or text when no battery found (desktop for example)
show_plugged_icon = true, -- If true show a cable icon alongside the battery icon when plugged in
show_unplugged_icon = true, -- When true show a diconnected cable icon when not plugged in
show_percent = true, -- Whether or not to show the percent charge remaining in digits
vertical_icons = true, -- When true icons are vertical, otherwise shows horizontal battery icon
multiple_battery_selection = 1, -- Which battery to choose when multiple found. "max" or "maximum", "min" or "minimum" or a number to pick the nth battery found (currently linux acpi only)
})
EOF
lua << EOF
require('lualine').setup {
options = {
theme = 'catppuccin',
icons_enabled = true
},
nvimbattery = {
function()
return require("battery").get_status_line()
end,
color = { fg = batterycolor, bg = bg },
},
extensions = {
'nerdtree'
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_w = {'encoding', 'fileformat', 'filetype'},
lualine_x = {'location'},
lualine_y = {'ctime'},
lualine_z = {'nvimbattery'}
},
}
EOF
I also tried running :lua vim.print(require("battery").get_status_line())
manually and the output was a battery with a question mark
I just cleaned my syntax, but same issue
lua << EOF
local batterycolor = '#ec9ca4'
local battery = require('battery')
battery.setup({
update_rate_seconds = 30,
show_status_when_no_battery = true,
show_plugged_icon = true,
show_unplugged_icon = true,
show_percent = true,
vertical_icons = true,
multiple_battery_selection = 1
})
EOF
lua << EOF
local nvimbattery = {
function()
return require('battery').get_status_line()
end,
color = { fg = batterycolor, bg = bg }
}
EOF
lua << EOF
require('lualine').setup {
options = {
theme = 'catppuccin',
icons_enabled = true
},
extensions = {
'nerdtree'
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_w = {'encoding', 'fileformat', 'filetype'},
lualine_x = {'location'},
lualine_y = {'ctime'},
lualine_z = {'nvimbattery'}
},
}
EOF
I updated to the latest version on my laptop and nothing is showing, no errors, but no battery
Thank you for the report Norok I will investigate when I get time 👍🏽
Sounds good
@Norok-The-Diablo I think I found the issue. I have a fork with the branch 50-fix-error-on-windows-no-battery
with a fix
You can see the diff here https://github.com/justinhj/battery.nvim/pull/51/files
I am not sure how you manage your packages, but I will assume vim-plug since it looks like you are using .vimrc
:
Plug 'agent-e11/battery.nvim', { 'branch': '50-fix-error-on-windows-no-battery' }
Thanks so much!
On Thu, Jul 18, 2024, 12:36 PM Eamon Burns @.***> wrote:
I am not sure how you manage your packages, but I will assume vim-plug since it looks like you are using .vimrc:
Plug 'agent-e11/battery.nvim', { 'branch': '50-fix-error-on-windows-no-battery' }
— Reply to this email directly, view it on GitHub https://github.com/justinhj/battery.nvim/issues/50#issuecomment-2237385192, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY22GBWNKOY7VGCM5GUMYCTZNAKMDAVCNFSM6AAAAABLA6P2AWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZXGM4DKMJZGI . You are receiving this because you were mentioned.Message ID: @.***>
@Norok-The-Diablo Did it fix it?
Just got home, I will test right now
No more error, it just shows nothing on desktop
I will try this version on my laptop too
@Norok-The-Diablo Oh, I forgot to mention. I think the reason that it shows nothing is because in your config you wrote:
lualine_z = { 'nvimbattery' }
instead of
lualine_z = { nvimbattery }
on my init I have it without quotes so that's not it
I realized I did it wrong later
What is the output of require("battery").get_battery_status()
?
nothing
"Nothing" meaning:
{}
or
?
nothing nothing
nothing on my laptop either
just tried it
It's loaded like this:
lua << EOF
local batterycolor = '#ec9ca4'
local battery = require('battery')
battery.setup({
update_rate_seconds = 30,
show_status_when_no_battery = true,
show_plugged_icon = true,
show_unplugged_icon = true,
show_percent = true,
vertical_icons = true,
multiple_battery_selection = 1
})
EOF
lua << EOF
local nvimbattery = {
function()
return require('battery').get_status_line()
end,
color = { fg = batterycolor, bg = bg }
}
EOF
lua << EOF
require('lualine').setup {
options = {
theme = 'catppuccin',
icons_enabled = true
},
extensions = {
'nerdtree'
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_w = {'encoding', 'fileformat', 'filetype'},
lualine_x = {'location'},
lualine_y = {'ctime'},
lualine_z = {nvimbattery}
},
}
EOF
can you verify that you have the proper branch checked out?
Go to the directory the plugin is installed to and run:
git remote --verbose
git branch
yeah everything's right
Ok, run this directly:
:lua =require"battery".get_battery_status()
Remember the =
{
ac_power = true, battery_count = 0, method = "powershell", percent_charge_remaining = 100 }
thats the output
Yeah, that is what it's supposed to be. 🤔
Try this:
:lua =require"battery".get_status_line()
there's a desktop icon
so weird
Now, replace this:
lualine_z = {nvimbattery}
with this:
lualine_z = { { require("battery").get_status_line } }
It works now
What the heck
so how I'm loading nvimbattery in the function must be wrong
maybe just replace this:
local nvimbattery = {
function()
return require('battery').get_status_line()
end,
color = { fg = batterycolor, bg = bg }
}
with this:
local nvimbattery = {
require("battery").get_status_line,
color = { fg = batterycolor, bg = bg }
}
doesn't work
If I remove the color variable it doesn't work either
Does it have to be nested in the lualine setup?
That is really strange
Actually, remove the
EOF
lua<<EOF
between the declaration of nvimbattery
and require('lualine').setup
sounds good
works just fine!
thanks so much
Thanks to you both. I just sat down and updated my Windows desktop since it was still on Neovim 0.7 lol By the time I had replicated the issue and create a branch to fix it I saw @Agent-E11 had fixed already! Thanks again
I work on a laptop and a desktop, and I liked this plugin because it could make my config go in between the two with an extra QOL feature on my laptop. It works fine on my laptop, but on my desktop with no battery every time the plugin checks if I have a battery it gives this error:
Error executing luv callback: .../plugged/battery.nvim/lua/battery/parsers/powershell.lua:57: attempt to index a nil value stack traceback: .../plugged/battery.nvim/lua/battery/parsers/powershell.lua:57: in function 'parse_powershell_battery_info' .../plugged/battery.nvim/lua/battery/parsers/powershell.lua:79: in function '_user_on_exit' ...Local/nvim-data/plugged/plenary.nvim/lua/plenary/job.lua:241: in function '_shutdown' ...Local/nvim-data/plugged/plenary.nvim/lua/plenary/job.lua:48: in function <...Local/nvim-data/plugged/plenary.nvim/lua/plenary/job.lua:39>
which makes sense because there's no battery, but I read on the ReadMe that it can detect if there isn't a battery and not cause harm. If that's only a feature in Linux, then I guess this is an enhancement issue.