commit 095f1cbe955bbb38c49fc5c9e195a1fe1783773d from: Brett Fisher date: Sat Jul 4 04:04:11 2026 UTC aestel/display.lua, aestel/menu.lua, aestel/navigate.lua: Move header rendering to display module. - Add display.write_header(title, cwd) returning lines written. - Add empty_message parameter to menu.menu. - Remove refresh_headers from navigate.lua and use display.write_header. commit - 9192f9e6bc31960f2056c2d174b5f447246617bf commit + 095f1cbe955bbb38c49fc5c9e195a1fe1783773d blob - 94d6649fac47a28aff2989f0eb08a42bfc495535 blob + 1299751ba0bb185628edcb3c9f6ed5ba77854e49 --- aestel/display.lua +++ aestel/display.lua @@ -40,5 +40,28 @@ function M.color_for_type(item_type) return TYPE_COLORS[item_type] or colors.WHITE end +-- Write a header block at the top of the terminal: +-- line 1: bold title (or omitted if title is empty) +-- line 2: "Current Path: " +-- line 3: blank separator (only when title is present) +-- Returns the number of lines written, for callers to position +-- a menu immediately below the header. +function M.write_header(title, cwd) + M.clear_and_position(1, 1) + local lines = 0 + if title and title ~= "" then + io.write(colors.BOLD .. title .. colors.RESET .. "\n") + lines = lines + 1 + end + io.write("Current Path: " .. (cwd or "") .. "\n") + lines = lines + 1 + if title and title ~= "" then + io.write("\n") + lines = lines + 1 + end + io.flush() + return lines +end + return M blob - d19e4d35a47d917ab3ddcfaca8f32c88beab67c2 blob + 19e7bb342806b143f3703a356c106db4ae0cd171 --- aestel/menu.lua +++ aestel/menu.lua @@ -26,8 +26,26 @@ end -- Display a key-navigated menu and return the selected index -- (1-based, 0 for "up", or nil (quit)) -function M.menu(title, options, start_row, header_lines) +function M.menu(title, options, start_row, header_lines, empty_message) if not options or #options == 0 then + if empty_message then + start_row = start_row or 1 + local terminal_height = input.get_terminal_height() + input.enable_raw() + + -- Write the empty message on the last terminal line + io.write(string.format("\27[%d;1H\27[K", terminal_height)) + io.write(colors.REVERSE .. empty_message .. colors.RESET) + io.flush() + + local key = read_key_full() + input.disable_raw() + + if key == "h" or key == "left" then + return 0 -- Signal "go up" + end + return nil -- Quit + end return nil end blob - 1411ce481537f6985960169eaa58eb33fd347748 blob + 894793b05cbb9fca0d8a49e212031dbecb680f58 --- aestel/navigate.lua +++ aestel/navigate.lua @@ -64,27 +64,9 @@ local function change_dir(cur, target, base_dir) return new_path end --- UPDATED refresh_headers: Debug print for title/cwd; simplified title, extra flushes -local function refresh_headers(title, cwd, start_row) - display.clear_and_position(1, 1) - title = title or "" -- Ensure string --- io.stderr:write("DEBUG refresh: title='" .. title .. "', cwd='" .. cwd .. "'\n") - io.stderr:flush() - if title ~= "" then - io.write(colors.BOLD .. title .. colors.RESET .. "\n") - io.flush() - end - io.write("Current Path: " .. cwd .. "\n") - io.flush() - if title ~= "" then - io.write("\n") -- Empty line for title case - io.flush() - end -end - -- handle_empty_dir (unchanged) local function handle_empty_dir(title, cwd, base_dir) - refresh_headers(title, cwd, nil) + 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") @@ -149,7 +131,7 @@ function M.browse(start_dir, base_dir, start_row, titl local cwd = normalize_path(start_dir or lfs.currentdir() or home_dir) local header_lines = title ~= "" and 3 or 1 - refresh_headers(title, cwd, nil) + display.write_header(title, cwd) local running = true local selected_file = nil @@ -160,7 +142,7 @@ function M.browse(start_dir, base_dir, start_row, titl local empty_result = handle_empty_dir(title, cwd, base_dir) if type(empty_result) == "string" then cwd = empty_result - refresh_headers(title, cwd, nil) + display.write_header(title, cwd) else running = false end @@ -173,9 +155,9 @@ function M.browse(start_dir, base_dir, start_row, titl local new_cwd, err = change_dir(cwd, "..", base_dir) if new_cwd then cwd = new_cwd - refresh_headers(title, cwd, nil) + display.write_header(title, cwd) else - refresh_headers(title, cwd, nil) + display.write_header(title, cwd) local height = input.get_terminal_height() io.write(string.format("\27[%d;1H\27[K", height)) io.write("Error: " .. (err or "unknown") .. "\n") @@ -190,9 +172,9 @@ function M.browse(start_dir, base_dir, start_row, titl local new_cwd, err = change_dir(cwd, sel.name, base_dir) if new_cwd then cwd = new_cwd - refresh_headers(title, cwd, nil) + display.write_header(title, cwd) else - refresh_headers(title, cwd, nil) + display.write_header(title, cwd) local height = input.get_terminal_height() io.write(string.format("\27[%d;1H\27[K", height)) io.write("Error: " .. (err or "unknown") .. "\n")