Skip to content

Commit

Permalink
Add lualine example
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Nov 30, 2023
1 parent 69722a8 commit 80c45c1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ A simple, customizable [pomodoro](https://en.wikipedia.org/wiki/Pomodoro_Techniq
- 🪶 Lightweight and asynchronous
- 💻 Written in Lua
- ⚙️ Easily customizable and extendable
- ⏱️ Supports multiple concurrent timers
- ⏱️ Run multiple concurrent timers
- ➕ Integrate with [lualine](#lualinenvim)

### Commands

Expand Down Expand Up @@ -137,6 +138,37 @@ And then in the `notifiers` field of your pomo.nvim config, you'd add the follow
{ init = PrintNotifier.new, opts = {} }
```

## Integrations

### [lualine.nvim](https://github.com/nvim-lualine/lualine.nvim)

pomo.nvim can easily be added to a section in lualine. For example, this would extend the defaults for section X to include the next timer to finish (min time remaining):

```lua
require("lualine").setup {
sections = {
lualine_x = {
function()
local ok, pomo = pcall(require, "pomo")
if not ok then
return ""
end

local timer = pomo.get_first_to_finish()
if timer == nil then
return ""
end

return "󰄉 " .. tostring(timer)
end,
"encoding",
"fileformat",
"filetype",
},
},
}
```

## Contributing

Please see the [CONTRIBUTING](https://github.com/epwalsh/obsidian.nvim/blob/main/.github/CONTRIBUTING.md) guide from [obsidian.nvim](https://github.com/epwalsh/obsidian.nvim) before submitting a pull request, as this repository is set up and managed in the same way.
Expand Down
23 changes: 22 additions & 1 deletion lua/pomo/timer.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local notifier = require "pomo.notifier"
local util = require "pomo.util"

---@class pomo.Timer
---@field id integer
Expand All @@ -17,7 +18,27 @@ local Timer = {}
---@param config pomo.Config
---@return pomo.Timer
Timer.new = function(id, time_limit, name, config)
local self = setmetatable({}, { __index = Timer })
local self = setmetatable({}, {
__index = Timer,
---@param self pomo.Timer
---@return string
__tostring = function(self)
---@type string
local time_str
local time_left = self:time_remaining()
if time_left ~= nil then
time_str = util.format_time(time_left)
else
time_str = util.format_time(self.time_limit)
end

if self.name ~= nil then
return string.format("#%d, %s: %s", self.id, self.name, time_str)
else
return string.format("#%d: %s", self.id, time_str)
end
end,
})
self.id = id
self.time_limit = time_limit
self.name = name
Expand Down

0 comments on commit 80c45c1

Please sign in to comment.