More lua style cleanup.

This commit is contained in:
Josh 2024-04-17 23:16:12 -04:00
parent 37b616165d
commit fc775120fd
1 changed files with 9 additions and 11 deletions

View File

@ -9,7 +9,7 @@ print("\27[H\27[2J\27[3J")
-- Print out flower from text file
local flower = io.open(lua_dir .. "flower.txt", "r")
if (flower ~= nil) then
if flower then
print(flower:read("*a"))
flower:close()
else
@ -20,7 +20,7 @@ end
local get_file = function(location, permissions, split_str)
local table = {}
local got_file = io.open(location, permissions)
if (got_file ~= nil) then
if got_file then
for line in got_file:lines() do
for line_id, line_val in line:gmatch(split_str) do
table[line_id] = line_val
@ -33,12 +33,10 @@ end
local get_line = function(location)
local item = io.open(location, 'r')
if (item ~= nil) then
if item then
local str = item:read('*l')
item:close()
return str
else
return ""
end
end
@ -53,21 +51,21 @@ for filename in lfs.dir("/sys/class/power_supply") do
end
-- Get wifi link quality
local winit = {}
local w_initial = {}
local wifi_string = ""
local wifi = io.open('/proc/net/wireless', 'r')
if (wifi ~= nil) then
if wifi then
for line in wifi:lines() do
table.insert(winit, line)
table.insert(w_initial, line)
end
-- what the fuck is lua regex.
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(wifi_regex) do
wifi_string = wifi_string .. string.format("[ %s %s%% ] ", wif, wqual)
for item = 1, #w_initial - 2 do
for w_if, w_qual in w_initial[item + 2]:gmatch(wifi_regex) do
wifi_string = wifi_string .. string.format("[ %s %s%% ] ", w_if, w_qual)
end
end
wifi:close()