Runnable Examples
todo
A persistent task list CLI built in Tea.
What it demonstrates
- Persists state to disk with
std.fsandstd.path. - Uses
std.envfor configurable file location andstd.argsfor subcommands.
Run it
tea examples/todo/main.tea
tea build examples/todo/main.tea
./bin/mainREADME summary
A persistent todo list application that stores tasks in a text file. It supports adding, listing, completing, and removing tasks, with a configurable location through TODO_FILE.
todo/main.tea
use args = "std.args"
use env = "std.env"
use fs = "std.fs"
use path = "std.path"
def char_to_digit(c: String) -> Int
if c == "0"
return 0
else if c == "1"
return 1
else if c == "2"
return 2
else if c == "3"
return 3
else if c == "4"
return 4
else if c == "5"
return 5
else if c == "6"
return 6
else if c == "7"
return 7
else if c == "8"
return 8
else if c == "9"
return 9
else
return - 1
end
end
def parse_int(s: String) -> Int
var result = 0
var i = 0
while i < @len(s)
const c = s[i]
const digit = char_to_digit(c)
if digit >= 0
result = result * 10 + digit
else
@eprintln(`todo: invalid number '${s}'`)
@exit(1)
end
i = i + 1
end
return result
end
def get_todo_file() -> String
const custom_path = env.get("TODO_FILE")
if @len(custom_path) > 0
return custom_path
end
const home = env.get("HOME")
return path.join([home, ".todo.txt"])
end
def init_todo_file() -> Void
const filepath = get_todo_file()
fs.write_file(filepath, "")
@println(`Initialized ${filepath}`)
end