<ContentPage
  eyebrow="Runnable Examples"
  title="todo"
  description="A persistent task list CLI built in Tea."
>
  <div className="grid gap-4 md:grid-cols-2">
    <KeyConceptCard title="What it demonstrates">
      <ul className="space-y-2">
        <li>Persists state to disk with `std.fs` and `std.path`.</li>
        <li>Uses `std.env` for configurable file location and `std.args` for subcommands.</li>
      </ul>
    </KeyConceptCard>
  </div>

**Run it**

```bash
tea examples/todo/main.tea
tea build examples/todo/main.tea
./bin/main
```

## README 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`.

<div className="divider-section" />

**`todo/main.tea`**

```tea
use args from "std.args"
use env from "std.env"
use fs from "std.fs"
use path from "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
```

<div className="divider-section" />

  <NextSteps title="Related pages">
    <NextLink href="/reference/env" title="std.env" description="This example reads `TODO_FILE` from the environment." />
    <NextLink href="/reference/path" title="std.path" description="See the path helpers used for the todo file location." />
  </NextSteps>
</ContentPage>
