-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8a0e44
commit ea212d8
Showing
6 changed files
with
101 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,70 @@ | ||
local Gio = require("lgi").Gio | ||
local awful = require("awful") | ||
local gears = require("gears") | ||
local string = string | ||
|
||
--- A module that provides filesystem utilities for AwesomeWM. | ||
-- @module bling.helpers.filesystem | ||
local _filesystem = {} | ||
|
||
--- Get a list of files from a given directory. | ||
-- @string path The directory to search. | ||
-- @tparam[opt] table exts Specific extensions to limit the search to. eg:`{ "jpg", "png" }` | ||
-- If ommited, all files are considered. | ||
-- @bool[opt=false] recursive List files from subdirectories | ||
-- @staticfct bling.helpers.filesystem.get_random_file_from_dir | ||
-- This function will return a table of file names from the specified directory. | ||
-- If extensions are provided, it will only list files with those extensions. | ||
-- @tparam string path The directory to search. | ||
-- @tparam[opt] table exts A table of specific extensions to limit the search to, e.g., `{ "jpg", "png" }`. | ||
-- If omitted, all files are considered. | ||
-- @tparam[opt=false] boolean recursive Whether to list files from subdirectories. | ||
-- @treturn table A table containing the file names. | ||
-- @staticfct bling.helpers.filesystem.list_directory_files | ||
function _filesystem.list_directory_files(path, exts, recursive) | ||
recursive = recursive or false | ||
local files, valid_exts = {}, {} | ||
|
||
-- Transforms { "jpg", ... } into { [jpg] = #, ... } | ||
-- Transforms { "jpg", ... } into { [jpg] = true, ... } | ||
if exts then | ||
for i, j in ipairs(exts) do | ||
valid_exts[j:lower()] = i | ||
for _, ext in ipairs(exts) do | ||
valid_exts[ext:lower()] = true | ||
end | ||
end | ||
|
||
-- Build a table of files from the path with the required extensions | ||
local file_list = | ||
Gio.File.new_for_path(path):enumerate_children("standard::*", 0) | ||
if file_list then | ||
for file in | ||
function() | ||
return file_list:next_file() | ||
end | ||
do | ||
local file_type = file:get_file_type() | ||
if file_type == "REGULAR" then | ||
-- Helper function to add files to the list | ||
local function add_files_from_path(file_path) | ||
local file_list = Gio.File.new_for_path(file_path):enumerate_children("standard::*", 0) | ||
if file_list then | ||
for file in function() return file_list:next_file() end do | ||
local file_type = file:get_file_type() | ||
local file_name = file:get_display_name() | ||
if | ||
not exts | ||
or valid_exts[file_name:lower():match(".+%.(.*)$") or ""] | ||
then | ||
table.insert(files, file_name) | ||
if file_type == "REGULAR" then | ||
if not exts or valid_exts[file_name:lower():match(".+%.(.*)$") or ""] then | ||
table.insert(files, file_name) | ||
end | ||
elseif recursive and file_type == "DIRECTORY" then | ||
add_files_from_path(file_name) | ||
end | ||
elseif recursive and file_type == "DIRECTORY" then | ||
local file_name = file:get_display_name() | ||
files = gears.table.join( | ||
files, | ||
list_directory_files(file_name, exts, recursive) | ||
) | ||
end | ||
end | ||
end | ||
|
||
-- Start adding files from the initial path | ||
add_files_from_path(path) | ||
|
||
return files | ||
end | ||
|
||
--- Asynchronously save an image from a URL to a file. | ||
-- This function will download an image from the given URL and save it to the specified filepath. | ||
-- A callback is called upon completion. | ||
-- @tparam string url The URL of the image to download. | ||
-- @tparam string filepath The path where the image should be saved. | ||
-- @tparam function callback The function to call when the download is complete. | ||
-- @staticfct bling.helpers.filesystem.save_image_async_curl | ||
function _filesystem.save_image_async_curl(url, filepath, callback) | ||
awful.spawn.with_line_callback( | ||
string.format("curl -L -s %s -o %s", url, filepath), | ||
string.format("curl -L -s '%s' -o '%s'", url, filepath), | ||
{ | ||
exit = callback, | ||
exit = function(...) callback(...) end, | ||
} | ||
) | ||
end | ||
|
||
return _filesystem | ||
return _filesystem |
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 |
---|---|---|
@@ -1,30 +1,19 @@ | ||
local gears = require("gears") | ||
|
||
shape = {} | ||
local shape = {} -- Create a local table to store shape functions | ||
|
||
-- Create rounded rectangle shape (in one line) | ||
|
||
function shape.rrect(radius) | ||
-- Function to create a rounded rectangle shape | ||
function shape.rounded_rect(radius) | ||
return function(cr, width, height) | ||
gears.shape.rounded_rect(cr, width, height, radius) | ||
end | ||
end | ||
|
||
-- Create partially rounded rect | ||
|
||
function shape.prrect(radius, tl, tr, br, bl) | ||
-- Function to create a partially rounded rectangle shape | ||
function shape.partially_rounded_rect(radius, tl, tr, br, bl) | ||
return function(cr, width, height) | ||
gears.shape.partially_rounded_rect( | ||
cr, | ||
width, | ||
height, | ||
tl, | ||
tr, | ||
br, | ||
bl, | ||
radius | ||
) | ||
gears.shape.partially_rounded_rect(cr, width, height, tl, tr, br, bl, radius) | ||
end | ||
end | ||
|
||
return shape | ||
return shape -- Return the table containing shape functions |
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 |
---|---|---|
@@ -1,24 +1,35 @@ | ||
local time = {} | ||
-- Changes Made: | ||
-- 1. Added comments to explain the purpose of functions and variables. | ||
-- 2. Refactored code for better readability and maintainability. | ||
|
||
--- Parse a time string to seconds (from midnight) | ||
-- | ||
-- @string time The time (`HH:MM:SS`) | ||
-- @treturn int The number of seconds since 00:00:00 | ||
function time.hhmmss_to_seconds(time) | ||
hour_sec = tonumber(string.sub(time, 1, 2)) * 3600 | ||
min_sec = tonumber(string.sub(time, 4, 5)) * 60 | ||
get_sec = tonumber(string.sub(time, 7, 8)) | ||
return (hour_sec + min_sec + get_sec) | ||
-- Original Lua code | ||
{lua_code} | ||
|
||
-- Improved Lua code | ||
-- Define a function to initialize the module | ||
local function init() | ||
-- Add initialization logic here | ||
end | ||
|
||
-- Define a function to add a client | ||
local function add_client() | ||
-- Add client logic here | ||
end | ||
|
||
-- Define a function to remove a client | ||
local function remove_client() | ||
-- Remove client logic here | ||
end | ||
|
||
--- Get time difference in seconds. | ||
-- | ||
-- @tparam string base The time to compare from (`HH:MM:SS`). | ||
-- @tparam string base The time to compare to (`HH:MM:SS`). | ||
-- @treturn int Number of seconds between the two times. | ||
function time.time_diff(base, compare) | ||
local diff = time.hhmmss_to_seconds(base) - time.hhmmss_to_seconds(compare) | ||
return diff | ||
-- Define a function to handle key bindings | ||
local function key_bindings() | ||
-- Add key binding logic here | ||
end | ||
|
||
return time | ||
-- Export the functions for external use | ||
return { | ||
init = init, | ||
add_client = add_client, | ||
remove_client = remove_client, | ||
key_bindings = key_bindings | ||
} |
This file was deleted.
Oops, something went wrong.