epwalsh / pomo.nvim

:new: :stopwatch: A simple, customizable pomodoro timer for Neovim, written in Lua, with nvim-notify, lualine, and telescope integrations
Apache License 2.0
187 stars 10 forks source link

How to access a created notifier? #24

Closed Deton8t closed 5 months ago

Deton8t commented 5 months ago

📚 The doc issue

How do I access user created notifiers?

Suggest a potential alternative/fix

No response

Deton8t commented 5 months ago

I'm fairly new to this but for example if I wanted to use the example of the PrintNotifier. How would I set a timer to use this Notifier after adding the init entry in the notifiers field? Thanks!

InvisOn commented 5 months ago

I figured it out.

Use it like normal: :TimerStart TIMELIMIT [NAME].

I hope this helps!

-- ~/.config/nvim/lua/plugins/pomo.lua
return {
  "epwalsh/pomo.nvim",
  version = "*",
  lazy = true,
  cmd = { "TimerStart", "TimerRepeat" },
  dependencies = {
    "rcarriga/nvim-notify",
  },
  opts = {
    notifiers = {
      {
        init = function(timer, opts)
          local PrintNotifier = {}

          PrintNotifier.new = function(timer, opts)
            local self = setmetatable({}, { __index = PrintNotifier })
            self.timer = timer
            self.hidden = false
            self.opts = opts -- not used
            return self
          end

          PrintNotifier.start = function(self)
            print(
              string.format(
                "Starting timer #%d, %s, for %ds",
                self.timer.id,
                self.timer.name,
                self.timer.time_limit
              )
            )
          end

          PrintNotifier.tick = function(self, time_left)
            if not self.hidden then
              print(
                string.format(
                  "Timer #%d, %s, %ds remaining...",
                  self.timer.id,
                  self.timer.name,
                  time_left
                )
              )
            end
          end

          PrintNotifier.done = function(self)
            print(string.format("Timer #%d, %s, complete", self.timer.id, self.timer.name))
          end

          PrintNotifier.stop = function(self) end

          PrintNotifier.show = function(self)
            self.hidden = false
          end

          PrintNotifier.hide = function(self)
            self.hidden = true
          end

          return PrintNotifier.new(timer, opts)
        end,
        opts = {},
      },
    },
  },
}
Deton8t commented 5 months ago

Ah I was a little confused about where I would set the name of the timer. Thanks for the help.