Improved timer example
Also pushed other half of system::fs rename
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
import system::(io, directfs, async)
|
import system::(io, fs, async)
|
||||||
import std::(to_string, to_uint, inspect)
|
import std::(to_string, to_uint, inspect)
|
||||||
|
|
||||||
const folder_view := \path. \next. do{
|
const folder_view := \path. \next. do{
|
||||||
cps println $ "Contents of " ++ directfs::os_print path;
|
cps println $ "Contents of " ++ fs::os_print path;
|
||||||
cps entries = async::block_on $ directfs::read_dir path;
|
cps entries = async::block_on $ fs::read_dir path;
|
||||||
cps list::enumerate entries
|
cps list::enumerate entries
|
||||||
|> list::map (pass \id. pass \name. \is_dir.
|
|> list::map (pass \id. pass \name. \is_dir.
|
||||||
println $ to_string id ++ ": " ++ directfs::os_print name ++ if is_dir then "/" else ""
|
println $ to_string id ++ ": " ++ fs::os_print name ++ if is_dir then "/" else ""
|
||||||
)
|
)
|
||||||
|> list::chain;
|
|> list::chain;
|
||||||
cps print "select an entry, or .. to move up: ";
|
cps print "select an entry, or .. to move up: ";
|
||||||
cps choice = readln;
|
cps choice = readln;
|
||||||
if (choice == "..") then do {
|
if (choice == "..") then do {
|
||||||
let parent_path = directfs::pop_path path
|
let parent_path = fs::pop_path path
|
||||||
|> option::unwrap
|
|> option::unwrap
|
||||||
|> tuple::pick 0 2;
|
|> tuple::pick 0 2;
|
||||||
next parent_path
|
next parent_path
|
||||||
@@ -20,10 +20,10 @@ const folder_view := \path. \next. do{
|
|||||||
cps subname, is_dir = to_uint choice
|
cps subname, is_dir = to_uint choice
|
||||||
|> (list::get entries)
|
|> (list::get entries)
|
||||||
|> option::unwrap;
|
|> option::unwrap;
|
||||||
let subpath = directfs::join_paths path subname;
|
let subpath = fs::join_paths path subname;
|
||||||
if is_dir then next subpath
|
if is_dir then next subpath
|
||||||
else do {
|
else do {
|
||||||
cps file = async::block_on $ directfs::read_file subpath;
|
cps file = async::block_on $ fs::read_file subpath;
|
||||||
cps contents = async::block_on $ io::read_string file;
|
cps contents = async::block_on $ io::read_string file;
|
||||||
cps println contents;
|
cps println contents;
|
||||||
next path
|
next path
|
||||||
@@ -31,7 +31,7 @@ const folder_view := \path. \next. do{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const main := loop_over (path = directfs::cwd) {
|
const main := loop_over (path = fs::cwd) {
|
||||||
cps path = folder_view path;
|
cps path = folder_view path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import system::async::(set_timer, yield)
|
|||||||
import system::io::(readln, println)
|
import system::io::(readln, println)
|
||||||
import std::exit_status
|
import std::exit_status
|
||||||
|
|
||||||
const main := (
|
const main := do{
|
||||||
set_timer true 1 (println "y" yield) \cancel.
|
cps cancel = set_timer true 1 (println "y" yield);
|
||||||
readln \a.
|
cps _ = readln;
|
||||||
cancel exit_status::success
|
cps cancel;
|
||||||
)
|
exit_status::success
|
||||||
|
}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ impl IntoSystem<'static> for DirectFS {
|
|||||||
lexer_plugin: None,
|
lexer_plugin: None,
|
||||||
line_parser: None,
|
line_parser: None,
|
||||||
constants: ConstTree::namespace(
|
constants: ConstTree::namespace(
|
||||||
[i.i("system"), i.i("directfs")],
|
[i.i("system"), i.i("fs")],
|
||||||
ConstTree::tree([
|
ConstTree::tree([
|
||||||
(i.i("read_file"), ConstTree::xfn(xfn_1ary(open_file_read_cmd))),
|
(i.i("read_file"), ConstTree::xfn(xfn_1ary(open_file_read_cmd))),
|
||||||
(i.i("read_dir"), ConstTree::xfn(xfn_1ary(read_dir_cmd))),
|
(i.i("read_dir"), ConstTree::xfn(xfn_1ary(read_dir_cmd))),
|
||||||
|
|||||||
Reference in New Issue
Block a user