Skip to content

Instantly share code, notes, and snippets.

@sebdelsol
Last active May 26, 2025 15:26
Show Gist options
  • Save sebdelsol/0722dc3518f7e1c95c7e4851b460849c to your computer and use it in GitHub Desktop.
Save sebdelsol/0722dc3518f7e1c95c7e4851b460849c to your computer and use it in GitHub Desktop.
KOReader userpatch for better compact items status bar
-- **MOVED to https://github.com/sebdelsol/KOReader.patches**
-- enhance compact items:
-- use the better frontlight icons, and add the battery percentage
-- better separator for title/chapter/author in compact mode with no separator
local ReaderFooter = require("apps/reader/modules/readerfooter")
local userpatch = require("userpatch")
local footerTextGeneratorMap = userpatch.getUpValue(ReaderFooter.applyFooterMode, "footerTextGeneratorMap")
local symbol_prefix = userpatch.getUpValue(footerTextGeneratorMap.frontlight, "symbol_prefix")
-- use the better icons for compact items
for _, item in ipairs { "frontlight", "frontlight_warmth" } do
symbol_prefix.compact_items[item] = symbol_prefix.icons[item]
end
-- use the battery percent for compact items
for _, item in ipairs { "battery" } do
local orig = footerTextGeneratorMap[item]
footerTextGeneratorMap[item] = function(footer, ...)
if footer.settings.item_prefix == "compact_items" then footer.settings.item_prefix = "icons" end
local text = orig(footer, ...)
footer.settings.item_prefix = "compact_items" -- restore
return text
end
end
-- add a separator for title/chapter/author
local BEGIN, END = string.char(0x1E), string.char(0x1F)
for _, item in ipairs { "book_author", "book_title", "book_chapter" } do
local orig = footerTextGeneratorMap[item]
footerTextGeneratorMap[item] = function(...) return BEGIN .. orig(...) .. END end
end
local separator_next = symbol_prefix.compact_items.pages_left
local subs = { -- order is important
{ pattern = END .. " " .. BEGIN, replace = " " .. separator_next .. " " }, -- sequence of title/chapter/author
{ pattern = "^" .. BEGIN, replace = "" }, -- @beginning of string
{ pattern = END .. "$", replace = "" }, -- @end of string
{ pattern = BEGIN, replace = separator_next .. " " }, --@beginning of title/chapter/author
{ pattern = END, replace = "" }, --@end of title/chapter/author
}
local orig_ReaderFooter_genAllFooterText = ReaderFooter.genAllFooterText
function ReaderFooter:genAllFooterText(...)
local text, is_filler_inside = orig_ReaderFooter_genAllFooterText(self, ...)
if self.settings.item_prefix == "compact_items" and self.settings.items_separator == "none" then
-- stylua: ignore
for _, sub in ipairs(subs) do text = text:gsub(sub.pattern, sub.replace) end
end
return text, is_filler_inside
end
@HahBikes
Copy link

Thanks a lot for these! Appreciate it!

@sebdelsol
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment