diff --git a/README.md b/README.md index 4bcc0bf..fe94784 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/lua/pomo/timer.lua b/lua/pomo/timer.lua index a72212f..6708919 100644 --- a/lua/pomo/timer.lua +++ b/lua/pomo/timer.lua @@ -1,4 +1,5 @@ local notifier = require "pomo.notifier" +local util = require "pomo.util" ---@class pomo.Timer ---@field id integer @@ -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