Flowerfetch has been styleguided according to luarocks styleguide.

At least to the best of my ability, I just gave it a quick scan and
pass. I may have missed things. Who knows!
See: github.com/luarocks/lua-style-guide
This commit is contained in:
Josh 2024-04-16 10:28:21 -04:00
parent c6179458de
commit 70537a8138

View file

@ -2,37 +2,37 @@
local lfs = require("lfs")
local luadir = arg[0]:match("@?(.*/)");
local lua_dir = arg[0]:match("@?(.*/)")
-- Clear
print("\27[H\27[2J\27[3J")
-- Print out flower from text file
local flower = io.open(luadir .. "flower.txt", "r");
local flower = io.open(lua_dir .. "flower.txt", "r")
if (flower ~= nil) then
print(flower:read("*a"));
flower:close();
print(flower:read("*a"))
flower:close()
else
print("Error: Missing ASCII flower");
os.exit(-1);
print("Error: Missing ASCII flower")
os.exit(-1)
end
function Getfile(loc, perm, splitstr)
local table = {};
local gotfile = io.open(loc, perm);
if (gotfile ~= nil) then
for line in gotfile:lines() do
for lineid, lineval in line:gmatch(splitstr) do
table[lineid] = lineval;
local get_file = function(location, permissions, split_str)
local table = {}
local got_file = io.open(location, permissions)
if (got_file ~= nil) then
for line in got_file:lines() do
for line_id, line_val in line:gmatch(split_str) do
table[line_id] = line_val
end
end
gotfile:close();
got_file:close()
end
return table;
return table
end
function Getline(loc)
local item = io.open(loc, 'r')
local get_line = function(location)
local item = io.open(location, 'r')
if (item ~= nil) then
local str = item:read('*l')
item:close()
@ -47,38 +47,38 @@ local battery = ""
local batteries = ""
for filename in lfs.dir("/sys/class/power_supply") do
if filename ~= "." and filename ~= ".." and filename ~= "AC" then
battery = Getline("/sys/class/power_supply/" .. filename .. "/capacity")
battery = get_line("/sys/class/power_supply/" .. filename .. "/capacity")
batteries = string.format("[ %s %s%% ] ", filename, battery) .. batteries
end
end
-- Get wifi link quality
local winit = {}
local wifistring = ""
local wifi_string = ""
local wifi = io.open('/proc/net/wireless', 'r')
if (wifi ~= nil) then
for line in wifi:lines() do
table.insert(winit, line);
table.insert(winit, line)
end
-- what the fuck is lua regex.
local wifiregex = "%s(.*):.*%s(%d+)%."
local wifi_regex = "%s(.*):.*%s(%d+)%."
-- Assemble wifi into printable set of strings.
for item = 1, #winit - 2 do
for wif, wqual in winit[item + 2]:gmatch(wifiregex) do
wifistring = wifistring .. string.format("[ %s %s%% ] ", wif, wqual)
for wif, wqual in winit[item + 2]:gmatch(wifi_regex) do
wifi_string = wifi_string .. string.format("[ %s %s%% ] ", wif, wqual)
end
end
wifi:close()
end
-- Get individual elements
local model = Getline('/sys/devices/virtual/dmi/id/product_name');
local kernel = Getline('/proc/sys/kernel/osrelease');
local shell = os.getenv("SHELL"):gsub(".*/", "");
local osrel = Getfile("/etc/os-release", "r", "(.*)=\"(.*)\"");
local uptime = Getline("/proc/uptime"):gsub("%..*", "");
local model = get_line('/sys/devices/virtual/dmi/id/product_name')
local kernel = get_line('/proc/sys/kernel/osrelease')
local shell = os.getenv("SHELL"):gsub(".*/", "")
local os_rel = get_file("/etc/os-release", "r", "(.*)=\"(.*)\"")
local uptime = get_line("/proc/uptime"):gsub("%..*", "")
local up_d = math.floor(uptime / (3600 * 24))
local up_h = math.floor((uptime % (3600 * 24)) / 3600)
local up_m = math.floor(((uptime % (3600 * 24)) % 3600) / 60)
@ -94,20 +94,20 @@ end
local output = {
{ "model", model },
{ "distro", osrel['PRETTY_NAME'] },
{ "distro", os_rel['PRETTY_NAME'] },
{ "kernel", kernel },
{ "shell", shell },
{ "uptime", upstring },
{ "bat", batteries },
{ "wifi", wifistring },
};
{ "wifi", wifi_string },
}
for i, value in pairs(output) do
local color = "";
local color = ""
if i%2 == 1 then
color = "\27[34m";
color = "\27[34m"
else
color = "\27[36m";
color = "\27[36m"
end
print(string.format("%s%6s \27[37m-\27[37m %s", color, value[1], value[2]))