Ok, I wrote my own, it's on alpha stage and you are only able to browse directories, not to take a file, but it'll be done in next release. Here are current problems:
- when users moves to a parent directory (for example from A/CHDK/SCRIPTS to A/CHDK the path the browser gives is A/CHDK/SCRIPTS/.. which refers to the same place, but in dirty way. I have no idea, how to get parent directory by lua, possibly there is some simple command?
-root directory is not accesible now... I need to solve the first problem before this
I also implemented a few nice functions such as is_file(string) and is_dir(string) which returns true if string referst to file or directory respectively and false if not (based on os.stat), global variable pwd (which meanc working directory), cd(string) which changes pwd if string refers to a directory and ls(string) which returns table containing list of files in directory string. These functions are simpler to use than low-level lua functions;)
the code:
--[[
@title chdkacs
--]]
-- SET ALL THE THINGS WE WILL NEED
console_height=12
set_console_layout(1,1,40,console_height)
visible_files=console_height-2
-- INPUTS --
function get_input()
wait_click(5000)
input=nil
if is_key("up") then
input="up"
end
if is_key("down") then
input="down"
end
if is_key("left") then
input="left"
end
if is_key("right") then
input="right"
end
if is_key("set") then
input="set"
end
return input
end
-- FILESYSTEM CMDS --
function init_env()
pwd="A/CHDK"
end
function is_file(file)
stat=os.stat(file)
out=stat["is_file"]
return out
end
function is_dir(dir)
stat=os.stat(dir)
if stat~=nil then
out=stat["is_dir"]
end
if stat==nil then
out=false
end
return out
end
function cd(dir)
if is_dir(dir) then
pwd=dir
end
if not is_dir(dir) then
return false
end
end
function ls(dir)
if is_dir(dir) then
out=os.listdir(dir, true)
end
return out
end
function browser_draw(first,selected)
set_console_autoredraw(0)
last=first+visible_files
print("--- SELECT FILE ---")
print("["..pwd.."]")
for i=first, first+visible_files-2 do
if i~=selected and i<=ls_numof then
print(" "..ls_dir[i])
end
if i==selected and i<=ls_numof then
print(">>"..ls_dir[i])
end
if i>ls_numof then
print("")
end
end
console_redraw()
set_console_autoredraw(1)
end
function browser()
exit_browser=false
ls_dir=ls(pwd)
ls_numof=table.getn(ls_dir)
selected=2
first=2
repeat
-- print("-- "..pwd.." --")
browser_draw(first,selected)
input=get_input()
if input=="up" then
selected=selected-1
first=first-1
end
if input=="down" then
selected=selected+1
end
if selected<2 then
selected=2
end
if first<2 then
first=2
end
if selected>ls_numof then
selected=ls_numof
end
if selected>visible_files then
first=selected-visible_files+2
end
if input=="set" then
if is_dir(pwd.."/"..ls_dir[selected]) then
cd(pwd.."/"..ls_dir[selected])
ls_dir=ls(pwd)
ls_numof=table.getn(ls_dir)
selected=2
first=2
sleep(1000)
end
end
until browser_exit==true
end
init_env()
browser()
And the attached file: