♻️ refactor(full-scope)!: major revision refactoring
Code layout has been changed and improoved. Annotations are added for documentation. Automated through utility functions and data tables BREAKING CHANGE: Tested from clean. Now properly uses LuaRocks to install dependencies.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
---@module "utils.blinky"
|
||||
--- This module provides a function to set up and disable the blinky cursor.
|
||||
|
||||
local M = {}
|
||||
|
||||
--- Function to set up blinky cursor
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
---@module "utils.cache_stats"
|
||||
--- This module provides a function to update the cached statistics.
|
||||
-- ╭─────────────────────────────────────────────────────────╮
|
||||
-- │ Cache Stats │
|
||||
-- ╰─────────────────────────────────────────────────────────╯
|
||||
|
||||
local M = {}
|
||||
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
-- Options can be set with:
|
||||
-- vim.g.stats_wakatime = true|false (default: true)
|
||||
@@ -14,6 +17,10 @@ local M = {}
|
||||
local config_dir = vim.fn.stdpath("config") --[[@as string]]
|
||||
local cache_script = vim.fs.joinpath(config_dir, "scripts", "update_cache.sh")
|
||||
|
||||
-- Path to the Neovim cache directory
|
||||
_G.cache_stats_dir = -- Cache directory
|
||||
vim.fn.stdpath("cache") --[[@as string]]
|
||||
|
||||
-- Flag to check if the script has already been run
|
||||
local script_run_once = false
|
||||
|
||||
@@ -32,13 +39,9 @@ for _, player in ipairs(vim.g.stats_ignored_players or {}) do
|
||||
table.insert(ignored_players, player)
|
||||
end
|
||||
|
||||
if vim.g.stats_music == nil then
|
||||
vim.g.stats_music = true
|
||||
end
|
||||
|
||||
if vim.g.stats_wakatime == nil then
|
||||
vim.g.stats_wakatime = true
|
||||
end
|
||||
-- Set the default values for the options
|
||||
vim.g.stats_music = vim.g.stats_music or true
|
||||
vim.g.stats_wakatime = vim.g.stats_wakatime or true
|
||||
|
||||
--- Function to run the cache script
|
||||
---@return boolean|number pid The pid of the script
|
||||
@@ -47,6 +50,10 @@ function M.setup_script()
|
||||
-- Build the arguments for the cache script
|
||||
local args = { cache_script }
|
||||
|
||||
-- Add the --cache-dir option
|
||||
table.insert(args, "--cache-dir")
|
||||
table.insert(args, _G.cache_stats_dir)
|
||||
|
||||
-- Add the --ignore option with the ignored players
|
||||
if #ignored_players > 0 then
|
||||
table.insert(args, "--ignore")
|
||||
@@ -77,7 +84,7 @@ function M.setup_script()
|
||||
return false
|
||||
end
|
||||
|
||||
-- Run the setup script only once
|
||||
-- Run the setup script
|
||||
M.setup_script()
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
---@module "utils.cmd_window"
|
||||
--- This module provides a function to open a floating window with a completion menu.
|
||||
-- ╭─────────────────────────────────────────────────────────╮
|
||||
-- │ Rootiest Command Window │
|
||||
-- ╰─────────────────────────────────────────────────────────╯
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---@module "utils.highlight"
|
||||
--- This module provides functions to apply highlights to the statusline and other components.
|
||||
-- ╭─────────────────────────────────────────────────────────╮
|
||||
-- │ Highlight │
|
||||
-- ╰─────────────────────────────────────────────────────────╯
|
||||
---@module "utils.highlight"
|
||||
--- This module provides functions to apply highlights to the statusline and other components.
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
+35
-18
@@ -1,25 +1,42 @@
|
||||
---@module "utils"
|
||||
--- This module aggregates various utility functions used across the configuration.
|
||||
--- It provides access to caching mechanisms, Git utilities, WakaTime statistics, music status, highlighting utilities, and a blinking effect utility.
|
||||
--- It provides access to caching mechanisms, Git utilities, WakaTime statistics, music status, highlight utilities, and a blinking effect utility.
|
||||
|
||||
local cache = require("utils.cache_stats")
|
||||
local git = require("utils.git")
|
||||
local wakatime = require("utils.wakatime_stats")
|
||||
local music = require("utils.music_stats")
|
||||
local highlight = require("utils.highlight")
|
||||
local blinky = require("utils.blinky")
|
||||
local utils = {}
|
||||
|
||||
---@alias UtilsModule
|
||||
---| { cache_stats: table, git: table, wakatime_stats: table, music_stats: table, highlight: table, blinky: table }
|
||||
-- Explicitly specify modules for LSP support
|
||||
utils.cache_stats = require("utils.cache_stats")
|
||||
utils.git = require("utils.git")
|
||||
utils.wakatime_stats = require("utils.wakatime_stats")
|
||||
utils.music_stats = require("utils.music_stats")
|
||||
utils.highlight = require("utils.highlight")
|
||||
utils.blinky = require("utils.blinky")
|
||||
|
||||
-- Function to iterate over files in the directory and load them dynamically
|
||||
local function read_utils_dir()
|
||||
-- Getting the root path for the current module directory
|
||||
local dir_path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h")
|
||||
|
||||
-- Open the directory
|
||||
local files = vim.fn.readdir(dir_path)
|
||||
|
||||
for _, file in ipairs(files) do
|
||||
-- Skip init.lua
|
||||
if file ~= "init.lua" and file:match(".*%.lua$") then
|
||||
-- Get the module name without the .lua extension
|
||||
local module_name = file:sub(1, -5)
|
||||
-- Load the module if not already explicitly set
|
||||
if not utils[module_name] then
|
||||
utils[module_name] = require("utils." .. module_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Read the directory to load any additional modules
|
||||
read_utils_dir()
|
||||
|
||||
---@alias UtilsModule table<string, any>
|
||||
|
||||
---@type UtilsModule
|
||||
local utils = {
|
||||
cache_stats = cache,
|
||||
git = git,
|
||||
wakatime_stats = wakatime,
|
||||
music_stats = music,
|
||||
highlight = highlight,
|
||||
blinky = blinky,
|
||||
}
|
||||
|
||||
return utils
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
local M = {}
|
||||
|
||||
require("utils.cache_stats")
|
||||
local cache_file = os.getenv("HOME") .. "/.cache/music_cache.txt"
|
||||
local cache_file = vim.fs.joinpath(_G.cache_stats_dir, "music_cache.txt")
|
||||
|
||||
local separator = "␟"
|
||||
local last_known_value = ""
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
---@module "utils.wakatime_stats"
|
||||
--- This module provides functions to retrieve wakatime statistics from the cache file.
|
||||
-- ╭─────────────────────────────────────────────────────────╮
|
||||
-- │ WakaTime Stats │
|
||||
-- ╰─────────────────────────────────────────────────────────╯
|
||||
local M = {}
|
||||
|
||||
require("utils.cache_stats")
|
||||
local cache_file = os.getenv("HOME") .. "/.cache/wakatime_cache.txt"
|
||||
local cache_file = vim.fs.joinpath(_G.cache_stats_dir, "wakatime_cache.txt")
|
||||
|
||||
-- Local variable to store the last known value
|
||||
local last_known_value = ""
|
||||
@@ -41,7 +43,10 @@ end
|
||||
--- Function to get the wakatime today status
|
||||
---@return string status The wakatime today status
|
||||
function M.get_today()
|
||||
return get_wakatime_today()
|
||||
local text = get_wakatime_today()
|
||||
-- Check if it starts with "0 hrs " and remove it
|
||||
text = text:gsub("^0 hrs%s*", "")
|
||||
return text
|
||||
end
|
||||
|
||||
--- Function to get the wakatime today icon
|
||||
|
||||
Reference in New Issue
Block a user