-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Timer Session Support with
:TimerSession
Command (#29)
* Initial commit * Added :TimerSession command for managing Pomodoro like sessions * clean up readme * Add autocomplete to command --------- Co-authored-by: epwalsh <[email protected]>
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
local log = require "pomo.log" | ||
local pomo = require "pomo" | ||
|
||
return function(data) | ||
local config = pomo.get_config() | ||
|
||
---@type string | ||
local session_name | ||
if data.args and string.len(data.args) > 0 then | ||
session_name = data.args | ||
elseif config.sessions and #vim.tbl_keys(config.sessions) == 1 then | ||
session_name = vim.tbl_keys(config.sessions)[1] | ||
else | ||
return log.error "Please provide a session name.\nUsage: TimerSession <session_name>" | ||
end | ||
|
||
local session = config.sessions[session_name] | ||
if not session then | ||
return log.error("Session '%s' not found", session_name) | ||
end | ||
|
||
local function start_session(current_session, index) | ||
if index > #current_session then | ||
log.info("Session '%s' completed", session_name) | ||
return | ||
end | ||
|
||
local timer_config = current_session[index] | ||
local time_limit = require("pomo.util").parse_time(timer_config.duration) | ||
if not time_limit then | ||
log.error("Invalid time duration '%s' in session '%s'", timer_config.duration, session_name) | ||
return | ||
end | ||
|
||
local timer = pomo.start_timer(time_limit, timer_config.name) | ||
timer:start(function() | ||
start_session(current_session, index + 1) | ||
end) | ||
end | ||
|
||
start_session(session, 1) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters