Skip to content

Commit

Permalink
Merge pull request #9 from QuentinGruber/lualine_support
Browse files Browse the repository at this point in the history
lualine_support
  • Loading branch information
QuentinGruber authored Sep 27, 2024
2 parents 21c3b6c + 1eef9d0 commit 9ba72af
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Use the Pomodoro Technique in Neovim with built-in session tracking and break re

![image](https://github.com/user-attachments/assets/71b3b980-4d4a-433f-b847-689794c35709)


- install using [lazy.nvim](https://github.com/folke/lazy.nvim)

```lua
Expand All @@ -23,6 +22,24 @@ Use the Pomodoro Technique in Neovim with built-in session tracking and break re

```

## Setup pomodoro display in lualine

```lua
{
"nvim-lualine/lualine.nvim",
optional = true,
event = "VeryLazy",
opts = function(_, opts)
table.insert(opts.sections.lualine_x, 3, {
function()
return require("pomodoro").get_pomodoro_status()
end,
})
end,
},

```

## Usage

| Command | Description |
Expand Down
21 changes: 21 additions & 0 deletions lua/pomodoro/pomodoro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ function pomodoro.startTimer(time, fn)
pomodoro.timer:start(time, 0, fn)
end

function pomodoro.get_pomodoro_status()
local time_left = pomodoro.timer_duration
- (uv.now() - pomodoro.started_timer_time)

local phase_str = ""
if pomodoro.phase == Phases.NOT_RUNNING then
phase_str = "🍅❌"
time_left = 0
elseif pomodoro.phase == Phases.RUNNING then
phase_str = "🍅"
elseif pomodoro.phase == Phases.BREAK then
phase_str = ""
end

local minutes = math.floor(time_left / 60000)
local seconds = math.floor((time_left % 60000) / 1000)
local time_left_str = string.format("%02d:%02d", minutes, seconds)

return phase_str .. " " .. time_left_str
end

function pomodoro.displayPomodoroUI()
if pomodoro.phase == Phases.NOT_RUNNING or pomodoro.phase == nil then
pomodoro.start()
Expand Down

0 comments on commit 9ba72af

Please sign in to comment.