Commit Diff


commit - 095f1cbe955bbb38c49fc5c9e195a1fe1783773d
commit + d6c130a407914179d262025c3f6cd269291ed9b2
blob - 19e7bb342806b143f3703a356c106db4ae0cd171
blob + f89d7b550fa44a21b0c5b51b9402826b6ab5a280
--- aestel/menu.lua
+++ aestel/menu.lua
@@ -34,8 +34,10 @@ function M.menu(title, options, start_row, header_line
 			input.enable_raw()
 
 			-- Write the empty message on the last terminal line
+			local terminal_width = input.get_terminal_width()
+			local padding = string.rep(" ", math.max(0, terminal_width - #empty_message))
 			io.write(string.format("\27[%d;1H\27[K", terminal_height))
-			io.write(colors.REVERSE .. empty_message .. colors.RESET)
+			io.write(colors.REVERSE .. empty_message .. padding .. colors.RESET)
 			io.flush()
 
 			local key = read_key_full()
blob - 894793b05cbb9fca0d8a49e212031dbecb680f58
blob + ab05520f4aae196d3a1baa76d752be5bd1d596a4
--- aestel/navigate.lua
+++ aestel/navigate.lua
@@ -26,7 +26,6 @@ local function join_path(base, name)
 	return normalize_path(base .. "/" .. name)
 end
 
--- REVERTED change_dir: Original regex for ".." (reliable for all cases, including /home → /)
 local function change_dir(cur, target, base_dir)
 	local new_path
 	if target == ".." then
@@ -35,14 +34,12 @@ local function change_dir(cur, target, base_dir)
 			return nil, "Cannot go above root directory (/)"
 		end
 		new_path = cur_no_trail:match("(.+)/[^/]+$") or "/"
-		-- NEW: Debug (uncomment: io.stderr:write("DEBUG .. from '" .. cur_no_trail .. "': match = '" .. (new_path or "nil") .. "'\n"); io.stderr:flush())
 	else
 		new_path = join_path(cur, target)
 	end
 
 	new_path = normalize_path(new_path)
 
-	-- Base_dir boundary (unchanged)
 	if base_dir then
 		local normalized_base = normalize_path(base_dir) .. "/"
 		local normalized_new = new_path .. "/"
@@ -64,39 +61,6 @@ local function change_dir(cur, target, base_dir)
 	return new_path
 end
 
--- handle_empty_dir (unchanged)
-local function handle_empty_dir(title, cwd, base_dir)
-	display.write_header(title, cwd)
-	local height = input.get_terminal_height()
-	io.write(string.format("\27[%d;1H\27[K", height))
-	io.write("Empty directory. Press 'q' to quit or 'h' to go up.\n")
-	io.flush()
-
-	input.enable_raw()
-	local key = input.read_key()
-	input.disable_raw()
-
-	if key == "q" or key == "\27" or key == nil then
-		return false
-	elseif key == "h" then
-		local new_cwd, err = change_dir(cwd, "..", base_dir)
-		if new_cwd then
-			return new_cwd
-		else
-			io.write(string.format("\27[%d;1H\27[K", height))
-			io.write("Error: " .. (err or "unknown") .. ". Press 'q' or 'h'.\n")
-			io.flush()
-			os.execute("sleep 1")
-			io.write(string.format("\27[%d;1H\27[K", height))
-			io.flush()
-			return handle_empty_dir(title, cwd, base_dir)
-		end
-	end
-	os.execute("sleep 0.5")
-	return handle_empty_dir(title, cwd, base_dir)
-end
-
--- build_list (unchanged)
 local function build_list(path)
 	local dirs, files = {}, {}
 	for item in lfs.dir(path) do
@@ -125,7 +89,6 @@ local function build_list(path)
 	return combined
 end
 
--- M.browse (unchanged)
 function M.browse(start_dir, base_dir, start_row, title)
 	title = title or ""
 	local cwd = normalize_path(start_dir or lfs.currentdir() or home_dir)
@@ -139,10 +102,16 @@ function M.browse(start_dir, base_dir, start_row, titl
 	while running do
 		local items = build_list(cwd)
 		if #items == 0 then
-			local empty_result = handle_empty_dir(title, cwd, base_dir)
-			if type(empty_result) == "string" then
-				cwd = empty_result
-				display.write_header(title, cwd)
+			local selected_index = menu.menu(title, items, start_row or 4, header_lines, "Empty directory. Press 'h' to go up, 'q' to quit.")
+			if selected_index == 0 then
+				local new_cwd, err = change_dir(cwd, "..", base_dir)
+				if new_cwd then
+					cwd = new_cwd
+					display.write_header(title, cwd)
+				else
+					display.status_line("Error: " .. (err or "unknown"), colors.REVERSE)
+					os.execute("sleep 1")
+				end
 			else
 				running = false
 			end