Files
orchid/examples/file-browser/main.orc
Lawrence Bethlenfalvy 7396078304 Added directfs
Added a very rudimentary file I/O system suitable for experimenting
with the language further. A better one will be designed when we have
sensible error management.
2023-09-17 16:37:39 +01:00

32 lines
858 B
Plaintext

import system::(io, directfs, async)
import std::proc::*
import std::(to_string, to_uint)
const folder_view := \path.\next. do{
cps println $ "Contents of " ++ path;
cps entries = async::block_on $ directfs::readdir path;
cps list::enumerate entries
|> list::map (pass \id. pass \name.\is_dir. (
println $ to_string id ++ ": " ++ name ++ if is_dir then "/" else ""
))
|> list::chain;
cps print "select an entry, or .. to move up: ";
cps choice = readln;
let output = if choice == "..\n"
then directfs::pop_path path
|> option::unwrap
|> tuple::pick 0 2
else (
to_uint choice
|> (list::get entries)
|> option::unwrap
|> (directfs::join_paths path)
);
next output
}
const main := loop_over (path = "/home/lbfalvy/Code/orchid/examples") {
cps path = folder_view path;
}