Commit Diff


commit - d6d52199020adbd3c7e32bf725e62dc7c881f8b8
commit + 915d416f97e8de5013529b6896c9e61b2000868b
blob - 30289f9bf9b8598148543868567bbbc29fa87f5d
blob + 3bab7435e8d7447387c2b82ce00f0661efb55fe9
--- bin/launchprogram.lua
+++ bin/launchprogram.lua
@@ -1,36 +1,36 @@
 #!/usr/bin/env lua5.4
--- A lua program launcher script
+-- A Lua program launcher script
 
--- Enforce Lua 5.4+ (for potential luafilesystem if expanded)
+-- Enforce Lua 5.4
 if not _VERSION:match("5.4") then
 	io.stderr:write("Error: Lua 5.4 required (got " .. _VERSION .. ").\n")
 	os.exit(1)
 end
 
 -- Dependencies
-local ui = require("aestel.ui")
+local colors = require("aestel.colors")
+local display = require("aestel.display")
 local input = require("aestel.input")
+local menu = require("aestel.menu")
 
--- Functin for error handling
--- Checks for lfs which is needed for logging
-local ok, lfs = pcall(require, "lfs")
-if not ok then
-	lfs = nil
-end
+local TITLE = "Program Launcher"
 
--- Function for building a sorted list of programs
 local function build_list()
+
+	local BINDIR = os.getenv("HOME") .. "/.local/bin"
+
 	local programs = {
-		["File Browser"] = "st -e browsefiles",
-		["Office Suite libreoffice"] = "libreoffice",
-		["Set Background"] = "st -e setbackground",
-		["Web Browser librewolf"] = "librewolf", 
-		["Web Browser netsurf"] = "netsurf"
+		["File Browser"] = {command = "st -e " .. BINDIR .. "/browsefiles", type = "app" },
+		["Office Suite libreoffice"] = {command = "libreoffice", type = "app" },
+		["Set Background"] = {command = "st -e " .. BINDIR .. "/setbackground", type = "app" },
+		["Web Browser librewolf"] = {command = "librewolf", type = "app" },
+		["Web Browser netsurf"] = {command = "netsurf", type = "app" },
 	}
     
-local sorted_items = {}
-	for name, command in pairs(programs) do
-		table.insert(sorted_items, {name = name, command = command})
+	local sorted_items = {}
+
+	for name, entry in pairs(programs) do
+		table.insert(sorted_items, { name = name, command = entry.command, type = entry.type })
 	end
     
 	table.sort(sorted_items, function(a, b)
@@ -40,66 +40,37 @@ local sorted_items = {}
 	return sorted_items
 end
 
--- Function for launcher script log
-local function log(message, level)
-	if not lfs then return end  -- No logging if lfs unavailable
-
-	local home_dir = os.getenv("HOME")
-	if not home_dir then return end
-
-	local log_file = "~/.local/var/log/aestel_launchprogram.log"
-	local expanded_path = log_file:gsub("^~", home_dir)
-
-	-- Ensure log dir exists
-	local log_dir = expanded_path:match("^(.*)/[^/]+$")
-	if log_dir and log_dir ~= "" then
-		lfs.mkdir(log_dir)
-	end
-
-	local file = io.open(expanded_path, "a")
-	if file then
-		file:write(os.date("%Y-%m-%d %H:%M:%S") .. " [" .. (level or "INFO") .. "] " .. message .. "\n")
-		file:close()
-	end
-end
-
--- Function for main interactive loop
 local function launch_program()
+
 	local items = build_list()
-	log("Script started", "INFO")
     
-	-- Clear screen and print title manually (ui.menu handles the list only)
-	input.clear_and_position(1, 1)
-	io.write("🚀  Program Launcher\r\n\n")
+	display.clear_and_position(1, 1)
+	io.write(colors.BOLD .. TITLE .. colors.RESET .. "\n\n")
 	io.flush()
     
-	-- Display menu starting at row 3 (after the title); pass full items
-	local selected_index = ui.menu(nil, items, 3)
+	local selected_index = menu.menu(nil, items, 3)
 
 	if selected_index then
 		local sel = items[selected_index]
-		log("Launching: " .. sel.name, "INFO")
-		-- Launch the selected program detached from terminal
 		os.execute("nohup " .. sel.command .. " > /dev/null 2>&1 &")
-		print("\n" .. "... Launching " .. sel.name)
-		print("... " .. sel.name .. " launched")
-		print("... Exiting Program Launcher")
+		display.status_line("... Launched " .. sel.name, colors.REVERSE)
+		os.execute("sleep 2")
+		display.status_line("... Exiting " .. TITLE, colors.REVERSE)
+		os.execute("sleep 2")
 	else
-		log("No program selected", "INFO")
-		print("\n... No program selected for launching")
-		print("... Exiting Program Launcher")
+		display.status_line("... No program selected for launching", colors.REVERSE)
+		os.execute("sleep 2")
+		display.status_line("... Exiting Program Launcher", colors.REVERSE)
+		os.execute("sleep 2")
 	end
-	print()    
-	os.execute("sleep 2")
+
+	display.clear_screen()
 end
 
--- Run the script with error handling
 local success, err = pcall(launch_program)
 if not success then
 	input.disable_raw()
-	log("Fatal error: " .. tostring(err), "FATAL")
-	print("\nFatal error: " .. tostring(err))
+	print("\nFatal error: " .. tostring(err) .. "\n")
 	os.exit(1)
 end
-input.disable_raw() -- Restore terminal on normal exit